Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Adding more formats as compatible. #8

Open
masterofobzene opened this issue May 3, 2022 · 1 comment
Open

[Feature] Adding more formats as compatible. #8

masterofobzene opened this issue May 3, 2022 · 1 comment

Comments

@masterofobzene
Copy link

masterofobzene commented May 3, 2022

Hi there, thanks for this nice script.
I've modified it to work with more formats, the only problem I've found where the 4 digit extensions of "webm", it seems the script used self.output_path = self.video_path[:-4] which removed 4 last characters to add a new extension ("." included). The webm extension has 4 letters + 1 ".", meaning that output thumb files where named "file..jpg" if they where made from a .webm source (this is because self.output_path = self.video_path[:-4] would not remove the "." character)

Here are the small modifications I've made in case you want to modify the script:

worker.py:

        if output_path == '':
            if video_path.endswith('webm'):
                self.output_path = self.video_path[:-5]
                self.output_folder = listToString(re.split(pattern = r"[/\\]", string = self.video_path)[:-1], "sys")
            else:
                self.output_path = self.video_path[:-4]
                self.output_folder = listToString(re.split(pattern = r"[/\\]", string = self.video_path)[:-1], "sys")

        else:
            if video_path.endswith('webm'):
                self.filename = re.split(pattern = r"[/\\]", string = self.video_path)[-1]
                self.output_path = os.path.join(output_path, self.filename[:-5])
                self.output_folder = self.output_path
            else:
                self.filename = re.split(pattern = r"[/\\]", string = self.video_path)[-1]
                self.output_path = os.path.join(output_path, self.filename[:-4])
                self.output_folder = self.output_path

main.py:

def check_files(paths_or_files):
    videos = []
    current_directory = os.getcwd()

    for path_or_file in paths_or_files:
        if not os.path.exists(path_or_file):
            if not os.path.exists(os.path.join(current_directory, path_or_file)):
                sys.exit("{}: no such file or directory".format(path_or_file))
            else:
                real_path = os.path.join(current_directory, path_or_file)
        else:
            if os.path.isfile(path_or_file):
                real_path = path_or_file
            else:
                real_path = os.path.join(current_directory, path_or_file)

        if os.path.isfile(real_path):
            if real_path.endswith(('mp4', 'mkv', 'm4v', 'webm', 'avi', 'wmv')):
                videos.append(real_path)
            else:
                sys.exit("{}: file not supported".format(real_path))
        elif os.path.isdir(real_path):
            for file in os.listdir(real_path):
                if file.endswith(('mp4', 'mkv', 'm4v', 'webm', 'avi', 'wmv')):
                    videos.append(os.path.join(real_path, file))
            if videos == []:
                sys.exit("{}: all of files in the directory are not supported".format(real_path))

    return videos
@Antari-yan
Copy link

With pathlib (included in python 3.4+) you can use stem to remove the extension regardless of length.
So worker.py could be changed like this:

from pathlib import Path
        if output_path == '':
            self.output_path = Path(self.video_path).stem
            self.output_folder = listToString(re.split(pattern = r"[/\\]", string = self.video_path)[:-1], "sys")

        else:
            self.filename = re.split(pattern = r"[/\\]", string = self.video_path)[-1]
            self.output_path = os.path.join(output_path, Path(self.filename).stem)
            self.output_folder = self.output_path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants