Spaces:
Sleeping
Sleeping
Commit
·
18fe5e3
1
Parent(s):
3c6f1cc
fix edgecase where the list of video links might contain malformed url
Browse files
Pages/Functions/video_player_functions.py
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
-
import
|
| 2 |
from .db_connection import videos_ref
|
| 3 |
|
| 4 |
|
| 5 |
def youtube_link_to_id(link):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
def get_video_embed_by_id(video_id):
|
| 13 |
return f"""
|
|
|
|
| 1 |
+
import urllib
|
| 2 |
from .db_connection import videos_ref
|
| 3 |
|
| 4 |
|
| 5 |
def youtube_link_to_id(link):
|
| 6 |
+
try:
|
| 7 |
+
from urllib.parse import urlparse, parse_qs
|
| 8 |
+
parsed = urlparse(link)
|
| 9 |
+
return parse_qs(parsed.query)['v'][0]
|
| 10 |
+
except (KeyError, IndexError):
|
| 11 |
+
raise ValueError(f"Invalid YouTube URL: {link}")
|
| 12 |
|
| 13 |
def get_video_embed_by_id(video_id):
|
| 14 |
return f"""
|
Pages/main_page.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from .Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
|
| 3 |
from .Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
|
| 4 |
from .Resources.css import css
|
|
@@ -24,12 +25,17 @@ def get_next_components():
|
|
| 24 |
next_video_link = get_video_link_by_pointer(0)
|
| 25 |
next_video_pointer = 1
|
| 26 |
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
(start_video, start_captions, start_video_id) = get_next_components()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
from .Functions.video_player_functions import youtube_link_to_id, get_video_embed_by_id, get_video_link_by_pointer
|
| 4 |
from .Functions.caption_editor_functions import get_captions_by_video_id, save_dataframe
|
| 5 |
from .Resources.css import css
|
|
|
|
| 25 |
next_video_link = get_video_link_by_pointer(0)
|
| 26 |
next_video_pointer = 1
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
next_video_id = youtube_link_to_id(next_video_link)
|
| 30 |
|
| 31 |
+
next_video = get_video_embed_by_id(next_video_id)
|
| 32 |
+
next_captions = get_captions_by_video_id(next_video_id)
|
| 33 |
+
return next_video, next_captions, next_video_id
|
| 34 |
+
except (ValueError, Exception) as e:
|
| 35 |
+
error_html = f"<div>Error loading video: {str(e)}</div>"
|
| 36 |
+
empty_captions = pd.DataFrame(columns=["Start", "Text", "End"])
|
| 37 |
+
return error_html, empty_captions, "error"
|
| 38 |
+
|
| 39 |
|
| 40 |
|
| 41 |
(start_video, start_captions, start_video_id) = get_next_components()
|