Spaces:
Running
Running
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() | |