File size: 6,548 Bytes
9a5da81
 
9340a56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75c9267
9340a56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75c9267
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import gradio as gr
import subprocess
import os

# Function to run yt-dlp commands
def run_yt_dlp(command, url, output_path, bitrate=None, start_time=None, end_time=None, playlist_items=None, archive_file=None):
    base_command = ["yt-dlp", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o", output_path]
    
    if command == "list_formats":
        base_command = ["yt-dlp", "-F", url]
    elif command == "download_mp3_max_quality":
        base_command.extend(["--postprocessor-args", "-b:a 320k", url])
    elif command == "basic_high_quality_mp3":
        base_command.append(url)
    elif command == "custom_bitrate":
        base_command.extend(["--postprocessor-args", f"-b:a {bitrate}k", url])
    elif command == "add_metadata_tags":
        base_command.extend(["--embed-metadata", url])
    elif command == "download_playlist":
        base_command.append(url)
    elif command == "download_playlist_range":
        base_command.extend(["--playlist-items", playlist_items, url])
    elif command == "download_hq_soundcloud":
        base_command.extend(["-o", "P:/Local Music/SoundCloud/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "embed_album_art":
        base_command.extend(["--embed-thumbnail", url])
    elif command == "download_opus":
        base_command.extend(["--audio-format", "opus", url])
    elif command == "skip_downloaded_files":
        base_command.extend(["--download-archive", archive_file, url])
    elif command == "download_multiple_files":
        base_command.extend(url.split())
    elif command == "download_split_chapters":
        base_command.extend(["--split-chapters", url])
    elif command == "extract_portion":
        base_command.extend(["-f", "bestvideo+bestaudio", "--external-downloader", "ffmpeg", "--external-downloader-args", f"ffmpeg_i:-ss {start_time} -to {end_time}", url])
    elif command == "update_metadata":
        base_command.extend(["--download-archive", archive_file, "--skip-download", "--embed-metadata", "--embed-thumbnail", url])
    elif command == "auto_rename":
        base_command.extend(["--force-overwrites", url])
    elif command == "download_url_list":
        base_command.extend(["-a", url])
    elif command == "limit_speed":
        base_command.extend(["--rate-limit", "1M", url])
    elif command == "download_vimeo":
        base_command.extend(["-o", "P:/Local Music/Vimeo/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_facebook":
        base_command.extend(["-o", "P:/Local Music/Facebook/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_instagram":
        base_command.extend(["-o", "P:/Local Music/Instagram/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_twitter":
        base_command.extend(["-o", "P:/Local Music/Twitter/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_tiktok":
        base_command.extend(["-o", "P:/Local Music/TikTok/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_reddit":
        base_command.extend(["-o", "P:/Local Music/Reddit/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_dailymotion":
        base_command.extend(["-o", "P:/Local Music/Dailymotion/%(uploader)s - %(title)s.%(ext)s", url])
    elif command == "download_transcript_text":
        base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", url])
    elif command == "download_transcript_markdown":
        base_command.extend(["--write-auto-subs", "--sub-lang", "en", "--skip-download", "--convert-subs", "srt", "-o", "P:/Local Music/%(title)s.md", url])
    elif command == "download_video_info":
        base_command.extend(["--write-info-json", "--skip-download", "-o", "P:/Local Music/%(title)s.json", url])
    elif command == "list_formats_no_download":
        base_command = ["yt-dlp", "-F", url]
    elif command == "download_age_restricted":
        base_command.extend(["--username", "YOUR_YOUTUBE_EMAIL", "--password", "YOUR_PASSWORD", "-f", "bestvideo+bestaudio", url])
    
    try:
        result = subprocess.run(base_command, capture_output=True, text=True)
        return result.stdout
    except Exception as e:
        return str(e)

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# yt-dlp Command Executor")

    with gr.Row():
        command = gr.Dropdown(choices=[
            "list_formats",
            "download_mp3_max_quality",
            "basic_high_quality_mp3",
            "custom_bitrate",
            "add_metadata_tags",
            "download_playlist",
            "download_playlist_range",
            "download_hq_soundcloud",
            "embed_album_art",
            "download_opus",
            "skip_downloaded_files",
            "download_multiple_files",
            "download_split_chapters",
            "extract_portion",
            "update_metadata",
            "auto_rename",
            "download_url_list",
            "limit_speed",
            "download_vimeo",
            "download_facebook",
            "download_instagram",
            "download_twitter",
            "download_tiktok",
            "download_reddit",
            "download_dailymotion",
            "download_transcript_text",
            "download_transcript_markdown",
            "download_video_info",
            "list_formats_no_download",
            "download_age_restricted"
        ], label="Command")

        url = gr.Textbox(label="URL", placeholder="Enter the URL here")

    with gr.Row():
        output_path = gr.Textbox(label="Output Path", placeholder="Enter the output path here")
        bitrate = gr.Textbox(label="Bitrate (for custom bitrate)", placeholder="Enter bitrate in kbps, e.g., 192")
        start_time = gr.Textbox(label="Start Time (HH:MM:SS)", placeholder="Enter start time, e.g., 00:01:00")
        end_time = gr.Textbox(label="End Time (HH:MM:SS)", placeholder="Enter end time, e.g., 00:05:00")
        playlist_items = gr.Textbox(label="Playlist Items (e.g., 1-5)", placeholder="Enter range of items, e.g., 1-5")
        archive_file = gr.Textbox(label="Archive File", placeholder="Enter path to archive file, e.g., P:/Local Music/downloaded.txt")

    execute_button = gr.Button("Execute Command")
    output = gr.Textbox(label="Output", lines=10)

    execute_button.click(
        fn=run_yt_dlp,
        inputs=[command, url, output_path, bitrate, start_time, end_time, playlist_items, archive_file],
        outputs=output
    )

demo.launch()