Rivalcoder commited on
Commit
28868d4
·
1 Parent(s): 5b9992a

[Edit] Add Proxy

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -1,19 +1,40 @@
1
  import gradio as gr
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
 
4
- def fetch_transcript(video_id):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  try:
6
- transcript = YouTubeTranscriptApi.get_transcript(video_id)
7
- return '\n'.join([f"{entry['text']}" for entry in transcript])
8
  except Exception as e:
9
  return f"Error: {str(e)}"
10
 
11
  iface = gr.Interface(
12
- fn=fetch_transcript,
13
  inputs=gr.Textbox(label="YouTube Video ID"),
14
  outputs=gr.Textbox(label="Transcript"),
15
- title="YouTube Transcript Fetcher",
16
- description="Enter a YouTube video ID to fetch its transcript."
17
  )
18
 
19
  iface.launch()
 
1
  import gradio as gr
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
 
4
+ # List of proxies
5
+ proxies_list = [
6
+ 'http://47.90.167.27:100', # United States
7
+ 'http://47.122.56.158:9098', # China
8
+ 'http://47.251.87.74:8008', # United States
9
+ 'http://15.156.24.206:3128', # Canada
10
+ 'http://137.184.100.135:80', # United States
11
+ 'http://51.16.179.113:1080', # United States
12
+ 'http://200.174.198.86:8888', # Brazil
13
+ 'http://3.126.147.182:80', # Germany
14
+ 'http://80.249.112.162:80' # Iran
15
+ ]
16
+
17
+ def fetch_transcript_with_proxy(video_id):
18
+ # Select a proxy from the list (randomly, for example)
19
+ import random
20
+ proxy = random.choice(proxies_list)
21
+ proxies = {
22
+ 'http': proxy,
23
+ 'https': proxy
24
+ }
25
+
26
  try:
27
+ transcript = YouTubeTranscriptApi.get_transcript(video_id, proxies=proxies)
28
+ return '\n'.join([entry['text'] for entry in transcript])
29
  except Exception as e:
30
  return f"Error: {str(e)}"
31
 
32
  iface = gr.Interface(
33
+ fn=fetch_transcript_with_proxy,
34
  inputs=gr.Textbox(label="YouTube Video ID"),
35
  outputs=gr.Textbox(label="Transcript"),
36
+ title="YouTube Transcript Fetcher with Proxy",
37
+ description="Enter a YouTube video ID to fetch its transcript using a proxy."
38
  )
39
 
40
  iface.launch()