File size: 1,747 Bytes
89df459
234649d
7c4cd6e
150836e
89df459
7c30181
150836e
7c30181
 
150836e
7c30181
 
150836e
 
7c30181
 
 
 
 
150836e
 
234649d
150836e
 
 
 
 
234649d
150836e
 
7c4cd6e
234649d
89df459
7c30181
150836e
 
4e9af05
89df459
7c30181
 
 
 
 
150836e
 
4e9af05
7c30181
 
 
4e9af05
7c30181
 
 
150836e
 
7c30181
4e9af05
4d47eb6
7c30181
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 subprocess
import uuid
import gradio as gr
from youtube_dl import YoutubeDL

title_and_description = """
# Twitch Clip Downloader
Created by [@artificialguybr](https://artificialguy.com)

Enter the Twitch Clip URL and (optionally) an authentication token to download Twitch clips in MP4 format.

## Features
- **Easy to Use**: Simple interface for inputting Twitch clip URLs and optional authentication tokens.
- **High-Quality Video**: Downloads in the best available quality in MP4 format.
- **Unique File Naming**: Utilizes UUIDs to generate unique file names, avoiding any file overwrite issues.

Feel free to use and generate your own video clips!
"""

# Function to download Twitch clip using youtube-dl
def download_twitch_clip(url):
    unique_id = uuid.uuid4()
    output_filename = f"{unique_id}.mp4"
    ydl_opts = {
        'format': 'best[ext=mp4]',
        'outtmpl': output_filename
    }

    with YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])

    return output_filename

# Gradio interface
def gradio_interface(url):
    mp4_file = download_twitch_clip(url)
    return mp4_file, mp4_file  # Return the file path twice, for both the video and file components

with gr.Blocks() as app:
    gr.Markdown(title_and_description)
    
    with gr.Row():
        with gr.Column():
            result_video = gr.Video(label="Video Output")
            download_link = gr.File(label="Download MP4")
    
    with gr.Row():
        with gr.Column():
            url_input = gr.Textbox(label="Twitch Clip URL")
            run_btn = gr.Button("Download Clip")
            
    run_btn.click(
        gradio_interface,
        inputs=[url_input],
        outputs=[result_video, download_link]
    )

app.queue()
app.launch()