コード例 #1
0
ファイル: sub_extract.py プロジェクト: Nyx0uf/python-scripts
                f"{common.COLOR_WHITE}[+] Extracting track {sub_stream.id} from {common.COLOR_YELLOW}{infile} with {common.COLOR_PURPLE}{cmd}{common.COLOR_WHITE}"
            )
            os.system(cmd)
        p_queue.task_done()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input",
                        type=Path,
                        help="Path to directory or single video file")
    parser.add_argument("-v",
                        "--verbose",
                        dest="verbose",
                        action="store_true",
                        help="Verbose mode")
    args = parser.parse_args()
    LOGGER = logger.Logger(args.verbose)

    # Sanity checks
    common.ensure_exist(["ffmpeg"])
    if args.input.exists() is None:
        common.abort(parser.format_help())

    # Get a list of files
    files = common.list_directory(args.input.resolve())
    queue = common.as_queue(files)

    # Extract
    common.parallel(extract_subtitles, (queue, ))
コード例 #2
0
    parser.add_argument("-n",
                        "--audio-name",
                        dest="audio_name",
                        type=str,
                        default="",
                        help="Audio track name")
    parser.add_argument(
        "-d",
        "--delete",
        dest="delete",
        action="store_true",
        help="Delete audio and video file and rename after merge")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvmerge"])
    if args.input.exists() is False or args.input.is_dir() is False:
        common.abort(parser.format_help())

    if len(args.audio_lang) != 3:
        common.abort(parser.format_help())

    # list audios
    audio_files = common.list_directory(
        args.input, lambda x: x.suffix in av.AUDIO_EXTENSIONS, True)
    # list vids
    video_files = common.list_directory(
        args.input, lambda x: x.suffix in av.VIDEO_EXTENSIONS, True)

    if len(audio_files) != len(video_files):
        common.abort(
コード例 #3
0
    parser.add_argument("input",
                        type=Path,
                        help="Path to directory or single MKV file")
    parser.add_argument(
        "-t",
        "--type",
        dest="type",
        type=str,
        default="font,image",
        help=
        "Type of attachments to extract (comma separated list, between font and image)"
    )
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvmerge", "mkvextract"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    # Get a list of files
    files = common.list_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".mkv", True)

    # Extract all attachments
    for f in files:
        mkv = mkvfile.MkvFile(f)
        if mkv.is_valid is False:
            continue

        for attachment in mkv.attachments:
            extract_attachment(f, attachment)
コード例 #4
0
from shlex import quote
from utils import common

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input", type=Path, help="Path to movie file")
    parser.add_argument("-n",
                        "--number-of-screenshots",
                        dest="number_of_screenshots",
                        type=int,
                        default=10,
                        help="Number of screenshots to take")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["ffprobe", "mpv"])
    if args.input.exists() is False or args.input.is_file() is False:
        common.abort(parser.format_help())

    duration = float(
        common.system_call(
            f'ffprobe -i {quote(str(args.input))} -show_entries format=duration -v quiet -of csv="p=0"'
        ).decode("utf-8").split('.')[0])

    step = int(duration / args.number_of_screenshots + 1)
    current = step
    for i in range(args.number_of_screenshots):
        scname = f'{args.input.stem}-{i:0>2}-{current}.png'
        cmd = f'mpv {quote(str(args.input))} --no-config --quiet --no-terminal --aid=no --sid=no --frames=1 --start={current} --o={quote(scname)}'
        os.system(cmd)
        current += step
コード例 #5
0
        cmd = f'mkvpropedit {quote(str(mkv))} --add-attachment {quote(str(attachment))}'
    os.system(cmd)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("attachments_path",
                        type=Path,
                        help="Path to directory of attachments or single file")
    parser.add_argument(
        "videos_path",
        type=Path,
        help="Path to directory or single video file (all files must be .mkv)")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvmerge", "mkvpropedit"])
    if args.videos_path.exists() is False or args.attachments_path.exists(
    ) is False:
        common.abort(parser.format_help())

    # Get a list of files
    video_files = common.list_directory(args.videos_path.resolve(),
                                        lambda x: x.suffix == ".mkv", True)
    attachments = common.list_directory(args.attachments_path.resolve())

    # Add all attachments
    for video in video_files:
        for attachment in attachments:
            add_attachment(video, attachment)
コード例 #6
0
    parser.add_argument(
        "-b",
        "--only-blocks",
        dest="only_blocks",
        action="store_true",
        help="Only remove PADDING, PICTURE and SEEKTABLE blocks")
    parser.add_argument("-l",
                        "--list-tags",
                        dest="list_tags",
                        action="store_true",
                        help="Get a list of all tags across all files")
    args = parser.parse_args()
    LOGGER = logger.Logger(args.verbose)

    # Sanity checks
    common.ensure_exist(["metaflac"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    # Get files list
    files = common.walk_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".flac")
    queue = common.as_queue(files)
    LOGGER.log(
        f"{common.COLOR_WHITE}[+] {len(files)} file{'s' if len(files) != 1 else ''} to consider"
    )

    if args.list_tags is True:
        all_tags = []
        common.parallel(list_tags, (
            queue,
コード例 #7
0
    parser.add_argument("-z",
                        "--video-lang",
                        dest="video_lang",
                        type=str,
                        default="und",
                        help="Lang of the video track")
    parser.add_argument("-r",
                        "--repl",
                        dest="repl",
                        type=str,
                        default="",
                        help="Pattern to replace for the Title")
    args = parser.parse_args()

    # Sanity checks
    common.ensure_exist(["mkvpropedit", "mediainfo"])
    if args.input.exists() is False:
        common.abort(parser.format_help())

    # Get a list of files
    files = common.list_directory(args.input.resolve(),
                                  lambda x: x.suffix == ".mkv", True)

    for f in files:
        mkv = mkvfile.MkvFile(f)
        cmd = f'mkvpropedit {quote(str(f))}'
        # Handle video track
        vtrack: mkvfile.MkvTrack = list(
            filter(lambda x: x.type == "video", mkv.tracks))[0]
        vn = f'{args.video_lang.upper()} — {mkv.video_codec_desc()}{" — " + args.video_name if args.video_name is not None else ""}'
        cmd += f' --edit track:v1 --set language={args.video_lang} --set name={quote(vn)}'