File size: 1,283 Bytes
c6f2536
5b9992a
c6f2536
28868d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c6f2536
28868d4
 
c6f2536
5b9992a
 
 
28868d4
5b9992a
 
28868d4
 
5b9992a
c6f2536
5b9992a
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
import gradio as gr
from youtube_transcript_api import YouTubeTranscriptApi

# List of proxies
proxies_list = [
    'http://47.90.167.27:100',    # United States
    'http://47.122.56.158:9098',  # China
    'http://47.251.87.74:8008',   # United States
    'http://15.156.24.206:3128',  # Canada
    'http://137.184.100.135:80',  # United States
    'http://51.16.179.113:1080', # United States
    'http://200.174.198.86:8888', # Brazil
    'http://3.126.147.182:80',    # Germany
    'http://80.249.112.162:80'    # Iran
]

def fetch_transcript_with_proxy(video_id):
    # Select a proxy from the list (randomly, for example)
    import random
    proxy = random.choice(proxies_list)
    proxies = {
        'http': proxy,
        'https': proxy
    }
    
    try:
        transcript = YouTubeTranscriptApi.get_transcript(video_id, proxies=proxies)
        return '\n'.join([entry['text'] for entry in transcript])
    except Exception as e:
        return f"Error: {str(e)}"

iface = gr.Interface(
    fn=fetch_transcript_with_proxy,
    inputs=gr.Textbox(label="YouTube Video ID"),
    outputs=gr.Textbox(label="Transcript"),
    title="YouTube Transcript Fetcher with Proxy",
    description="Enter a YouTube video ID to fetch its transcript using a proxy."
)

iface.launch()