-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (52 loc) · 3.68 KB
/
main.py
File metadata and controls
60 lines (52 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import argparse
import sys
from src.encoder import encode_file
from src.decoder import decode_video
from src.uploader import upload_video
from src.restore_format import restore_file
def main():
parser = argparse.ArgumentParser(
description="YouTube Data Encoder/Decoder - Encode any file into a video and upload it to YouTube."
)
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Encode command
encode_parser = subparsers.add_parser("encode", help="Encode a file into a video")
encode_parser.add_argument("input_file", help="Path to the file to encode")
encode_parser.add_argument("output_video", help="Path to the output video file (e.g., output.mp4)")
encode_parser.add_argument("--block-size", type=int, default=16, help="Pixel size of each bit block (0 for adaptive, default: 16)")
encode_parser.add_argument("--codec", type=str, default="FFV1", help="Video codec (default: FFV1)")
encode_parser.add_argument("--ecc-size", type=int, default=32, help="Reed-Solomon ECC bytes per frame (default: 32)")
encode_parser.add_argument("--threads", type=int, default=None, help="Number of worker threads (default: CPU count)")
encode_parser.add_argument("--alignment", action="store_true", help="Add QR-style alignment patterns")
encode_parser.add_argument("--grayscale", action="store_true", default=True, help="Grayscale-only mode (default: True)")
# Decode command
decode_parser = subparsers.add_parser("decode", help="Decode a video back into a file")
decode_parser.add_argument("input_video", help="Path to the input video file")
decode_parser.add_argument("output_file", help="Path to save the decoded data")
decode_parser.add_argument("--block-size", type=int, default=16, help="Pixel size of each bit block (0 for auto-detect, default: 16)")
decode_parser.add_argument("--ecc-size", type=int, default=32, help="Reed-Solomon ECC bytes per frame (default: 32)")
decode_parser.add_argument("--threads", type=int, default=None, help="Number of worker threads (default: CPU count)")
decode_parser.add_argument("--alignment", action="store_true", help="Use QR-style alignment patterns")
# Upload command
upload_parser = subparsers.add_parser("upload", help="Upload a video to YouTube")
upload_parser.add_argument("file", help="Path to the video file to upload")
upload_parser.add_argument("--title", default="Encoded Data", help="YouTube video title")
upload_parser.add_argument("--description", default="Data encoded as video frames", help="YouTube video description")
upload_parser.add_argument("--privacy", choices=["public", "private", "unlisted"], default="unlisted", help="Video privacy status (default: unlisted)")
# Restore command
restore_parser = subparsers.add_parser("restore", help="Automatically detect and restore file format")
restore_parser.add_argument("input_file", help="Path to the decoded file to restore")
args = parser.parse_args()
if args.command == "encode":
encode_file(args.input_file, args.output_video, block_size=args.block_size, codec=args.codec, ecc_size=args.ecc_size, threads=args.threads, use_alignment=args.alignment, grayscale_only=args.grayscale)
elif args.command == "decode":
decode_video(args.input_video, args.output_file, block_size=args.block_size, ecc_size=args.ecc_size, threads=args.threads, use_alignment=args.alignment)
elif args.command == "upload":
upload_video(args.file, title=args.title, description=args.description, privacy=args.privacy)
elif args.command == "restore":
restore_file(args.input_file)
else:
parser.print_help()
sys.exit(1)
if __name__ == "__main__":
main()