Rivalcoder commited on
Commit
adb03d1
·
1 Parent(s): 28868d4
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -1,40 +1,33 @@
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()
 
1
  import gradio as gr
2
  from youtube_transcript_api import YouTubeTranscriptApi
3
+ from youtube_transcript_api.proxies import WebshareProxyConfig
4
 
5
+ # Initialize the YouTubeTranscriptApi with proxy configuration
6
+ ytt_api = YouTubeTranscriptApi(
7
+ proxy_config=WebshareProxyConfig(
8
+ proxy_username="tlaukrdr", # Replace with your proxy username
9
+ proxy_password="mc1aumn9xbhb" # Replace with your proxy password
10
+ )
11
+ )
 
 
 
 
 
12
 
13
+ # Function to fetch YouTube transcript using the video ID
14
+ def fetch_transcript(video_id: str):
 
 
 
 
 
 
 
15
  try:
16
+ # Fetch transcript
17
+ transcript = ytt_api.fetch(video_id)
18
+ # Format the transcript into a readable text
19
+ transcript_text = "\n".join([entry['text'] for entry in transcript])
20
+ return transcript_text
21
  except Exception as e:
22
+ return f"Error fetching transcript: {str(e)}"
23
 
24
+ # Gradio Interface
25
  iface = gr.Interface(
26
+ fn=fetch_transcript,
27
+ inputs=gr.Textbox(label="Enter YouTube Video ID"),
28
  outputs=gr.Textbox(label="Transcript"),
29
+ live=True
 
30
  )
31
 
32
+ # Launch the Gradio app
33
  iface.launch()