youtube mobile link
Browse files
app.py
CHANGED
@@ -17,39 +17,11 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
17 |
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
|
18 |
|
19 |
def extract_video_id(url):
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
23 |
video_id = re.search(r"v=([^&]+)", url).group(1)
|
24 |
-
return video_id
|
25 |
-
|
26 |
-
def get_redirected_url_video_id(mobile_url):
|
27 |
-
# Set up Chrome options to run headless (without opening a visible browser window)
|
28 |
-
chrome_options = Options()
|
29 |
-
chrome_options.add_argument("--headless")
|
30 |
-
chrome_options.add_argument("--disable-gpu")
|
31 |
-
|
32 |
-
# Specify the path to the ChromeDriver executable
|
33 |
-
chrome_driver_path = 'chromedriver' # Update this path
|
34 |
-
|
35 |
-
# Create a new Chrome session
|
36 |
-
service = Service(chrome_driver_path)
|
37 |
-
driver = webdriver.Chrome(service=service, options=chrome_options)
|
38 |
-
|
39 |
-
# Open the mobile YouTube link
|
40 |
-
driver.get(mobile_url)
|
41 |
-
|
42 |
-
# Wait for a few seconds to ensure the page has loaded
|
43 |
-
time.sleep(1)
|
44 |
-
|
45 |
-
# Get the current URL (which should be the full YouTube URL)
|
46 |
-
current_url = driver.current_url
|
47 |
-
|
48 |
-
# Close the browser
|
49 |
-
driver.quit()
|
50 |
-
|
51 |
-
# Extract the video ID from the current URL
|
52 |
-
video_id = re.search(r"v=([^&]+)", current_url).group(1)
|
53 |
return video_id
|
54 |
|
55 |
def get_youtube_comments(video_id):
|
|
|
17 |
YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
|
18 |
|
19 |
def extract_video_id(url):
|
20 |
+
# Handle both mobile and desktop URLs
|
21 |
+
if "youtu.be" in url:
|
22 |
+
video_id = re.search(r"youtu\.be/([^&]+)", url).group(1)
|
23 |
+
else:
|
24 |
video_id = re.search(r"v=([^&]+)", url).group(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return video_id
|
26 |
|
27 |
def get_youtube_comments(video_id):
|