Team Ai
Apppublic

day84/code-server

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
convert.py62 linesDownload Raw Back to genz
1from encode import create_video2from decode_video import decode3from youtube_decode import youtube_decode4import argparse5import sys6 7def enc_file(source_file, output_video):8    print (f"Encoding {source_file} to {output_video}")9    create_video(source_file, output_video)10 11def dec_video(source_video, destination_folder, docker_mode):12    print (f"Decoding {source_video} to {destination_folder}")13    decode(source_video, destination_folder)14 15def y_decode(video_url, destination_folder, docker_mode):16    print (f"Decoding {video_url} to {destination_folder}")17    youtube_decode(video_url, destination_folder)18 19def main():20 21    # First, check if '--docker' is in the command line arguments22    docker_mode = '--docker' in sys.argv23    if docker_mode:24        sys.argv.remove('--docker')  # Remove it so it doesn't interfere with the main parser25 26    docker_usage = """\27docker run --rm -v $(pwd):/data karaketir16/file2video [-h]  [--encode source_file output_video] 28                                                        [--decode source_video destination_folder] 29                                                        [--youtube-decode youtube_url destination_folder]"""30    31    if docker_mode:32        parser = argparse.ArgumentParser(description="Program to encode files into videos and decode videos back to files.", usage=docker_usage)33    else:34        parser = argparse.ArgumentParser(description="Program to encode files into videos and decode videos back to files.")35 36    # Optional argument for encoding37    parser.add_argument("--encode", nargs=2, metavar=('source_file', 'output_video'), 38                        help="Encode a file into a video: source_file output_video.mp4")39    40    # Optional argument for decoding41    parser.add_argument("--decode", nargs=2, metavar=('source_video', 'destination_folder'), 42                        help="Decode a video to a file: source_video.mp4 destination_folder")43    44    # Optional argument for YouTube video decoding45    parser.add_argument("--youtube-decode", nargs=2, metavar=('youtube_url', 'destination_folder'), 46                        help="Decode a video from a YouTube URL to a file: 'youtube_url' destination_folder")47 48    49    args = parser.parse_args()50 51    # Check which command is used and call the corresponding function52    if args.encode:53        enc_file(*args.encode)54    elif args.decode:55        dec_video(*args.decode, docker_mode)56    elif args.youtube_decode:57        y_decode(*args.youtube_decode, docker_mode)58    else:59        parser.print_help()60 61if __name__ == "__main__":62    main()