DeeeeeeM
commited on
Commit
Β·
1e10fa7
1
Parent(s):
b1818a4
Added playlist tag checking functionality and fixed strict apostrophe checking.
Browse files
app.py
CHANGED
|
@@ -13,6 +13,7 @@ import os
|
|
| 13 |
import subprocess
|
| 14 |
import glob
|
| 15 |
import shutil
|
|
|
|
| 16 |
|
| 17 |
def process_media(
|
| 18 |
model_size, source_lang, upload, model_type,
|
|
@@ -31,7 +32,6 @@ def process_media(
|
|
| 31 |
|
| 32 |
temp_path = upload.name
|
| 33 |
|
| 34 |
-
#-- Check if CUDA is available or not --#
|
| 35 |
if model_type == "faster whisper":
|
| 36 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 37 |
model = stable_whisper.load_faster_whisper(model_size, device=device)
|
|
@@ -185,7 +185,6 @@ def extract_playlist_to_csv(playlist_url):
|
|
| 185 |
with YoutubeDL(ydl_opts) as ydl:
|
| 186 |
result = ydl.extract_info(playlist_url, download=False)
|
| 187 |
entries = result.get('entries', [])
|
| 188 |
-
# Save to a temp file for download
|
| 189 |
fd, csv_path = tempfile.mkstemp(suffix=".csv", text=True)
|
| 190 |
os.close(fd)
|
| 191 |
with open(csv_path, 'w', newline='', encoding='utf-8') as f:
|
|
@@ -229,6 +228,54 @@ def download_srt(video_url):
|
|
| 229 |
print("SRT download error:", e)
|
| 230 |
return None
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
WHISPER_LANGUAGES = [
|
| 233 |
("Afrikaans", "af"),
|
| 234 |
("Albanian", "sq"),
|
|
@@ -522,5 +569,29 @@ with gr.Blocks() as interface:
|
|
| 522 |
outputs=srt_file
|
| 523 |
)
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
interface.launch(share=True)
|
|
|
|
| 13 |
import subprocess
|
| 14 |
import glob
|
| 15 |
import shutil
|
| 16 |
+
import unicodedata
|
| 17 |
|
| 18 |
def process_media(
|
| 19 |
model_size, source_lang, upload, model_type,
|
|
|
|
| 32 |
|
| 33 |
temp_path = upload.name
|
| 34 |
|
|
|
|
| 35 |
if model_type == "faster whisper":
|
| 36 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 37 |
model = stable_whisper.load_faster_whisper(model_size, device=device)
|
|
|
|
| 185 |
with YoutubeDL(ydl_opts) as ydl:
|
| 186 |
result = ydl.extract_info(playlist_url, download=False)
|
| 187 |
entries = result.get('entries', [])
|
|
|
|
| 188 |
fd, csv_path = tempfile.mkstemp(suffix=".csv", text=True)
|
| 189 |
os.close(fd)
|
| 190 |
with open(csv_path, 'w', newline='', encoding='utf-8') as f:
|
|
|
|
| 228 |
print("SRT download error:", e)
|
| 229 |
return None
|
| 230 |
|
| 231 |
+
def check_youtube_tag(video_url, tag_to_check):
|
| 232 |
+
|
| 233 |
+
try:
|
| 234 |
+
with YoutubeDL({'quiet': True}) as ydl:
|
| 235 |
+
info = ydl.extract_info(video_url, download=False)
|
| 236 |
+
tags = info.get('tags', [])
|
| 237 |
+
tag_to_check_norm = tag_to_check.lower()
|
| 238 |
+
tags_norm = [t.lower() for t in tags]
|
| 239 |
+
# Exact match, case-insensitive, apostrophe style must match
|
| 240 |
+
exists = any(tag_to_check_norm == t for t in tags_norm)
|
| 241 |
+
if exists:
|
| 242 |
+
return f"β
Tag '{tag_to_check}' exists in video tags."
|
| 243 |
+
else:
|
| 244 |
+
return f"β Tag '{tag_to_check}' does NOT exist in video tags.\n\nTags found: {tags if tags else 'None'}"
|
| 245 |
+
except Exception as e:
|
| 246 |
+
return f"Error: {str(e)}"
|
| 247 |
+
|
| 248 |
+
def check_playlist_tags(playlist_url, tag_to_check):
|
| 249 |
+
|
| 250 |
+
try:
|
| 251 |
+
ydl_opts = {
|
| 252 |
+
'extract_flat': True,
|
| 253 |
+
'quiet': True,
|
| 254 |
+
'dump_single_json': True
|
| 255 |
+
}
|
| 256 |
+
with YoutubeDL(ydl_opts) as ydl:
|
| 257 |
+
result = ydl.extract_info(playlist_url, download=False)
|
| 258 |
+
entries = result.get('entries', [])
|
| 259 |
+
missing_videos = []
|
| 260 |
+
tag_to_check_norm = tag_to_check.lower()
|
| 261 |
+
for video in entries:
|
| 262 |
+
video_id = video['id']
|
| 263 |
+
video_url = f'https://www.youtube.com/watch?v={video_id}'
|
| 264 |
+
with YoutubeDL({'quiet': True}) as ydl_video:
|
| 265 |
+
info = ydl_video.extract_info(video_url, download=False)
|
| 266 |
+
tags = info.get('tags', [])
|
| 267 |
+
tags_norm = [t.lower() for t in tags]
|
| 268 |
+
exists = any(tag_to_check_norm == t for t in tags_norm)
|
| 269 |
+
if not exists:
|
| 270 |
+
missing_videos.append(f"{video.get('title', 'N/A')} ({video_url})")
|
| 271 |
+
if missing_videos:
|
| 272 |
+
missing_list = "\n".join(missing_videos)
|
| 273 |
+
return f"β Tag '{tag_to_check}' does NOT exist in the following videos:\n\n{missing_list}"
|
| 274 |
+
else:
|
| 275 |
+
return f"β
Tag '{tag_to_check}' exists in all videos in the playlist."
|
| 276 |
+
except Exception as e:
|
| 277 |
+
return f"Error: {str(e)}"
|
| 278 |
+
|
| 279 |
WHISPER_LANGUAGES = [
|
| 280 |
("Afrikaans", "af"),
|
| 281 |
("Albanian", "sq"),
|
|
|
|
| 569 |
outputs=srt_file
|
| 570 |
)
|
| 571 |
|
| 572 |
+
with gr.TabItem("Tag Checker"):
|
| 573 |
+
gr.Markdown("### Check if a specific tag exists in a YouTube video's metadata.")
|
| 574 |
+
tag_url = gr.Textbox(label="YouTube Video URL", placeholder="Paste video URL here")
|
| 575 |
+
tag_input = gr.Textbox(label="Tag to Check", placeholder="Type the tag (e.g. series:my father's wife)")
|
| 576 |
+
tag_btn = gr.Button("Process")
|
| 577 |
+
tag_output = gr.Textbox(label="Tag Check Result", interactive=False)
|
| 578 |
+
tag_btn.click(
|
| 579 |
+
check_youtube_tag,
|
| 580 |
+
inputs=[tag_url, tag_input],
|
| 581 |
+
outputs=tag_output
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
+
with gr.TabItem("Playlist Tag Checker"):
|
| 585 |
+
gr.Markdown("### Check if a specific tag exists in all videos of a YouTube playlist.")
|
| 586 |
+
playlist_url_tags = gr.Textbox(label="YouTube Playlist URL", placeholder="Paste playlist URL here")
|
| 587 |
+
tag_input_playlist = gr.Textbox(label="Tag to Check", placeholder="Type the tag (e.g. series:my father's wife)")
|
| 588 |
+
tag_btn_playlist = gr.Button("Process")
|
| 589 |
+
tag_output_playlist = gr.Textbox(label="Tag Check Result", interactive=False)
|
| 590 |
+
tag_btn_playlist.click(
|
| 591 |
+
check_playlist_tags,
|
| 592 |
+
inputs=[playlist_url_tags, tag_input_playlist],
|
| 593 |
+
outputs=tag_output_playlist
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
|
| 597 |
interface.launch(share=True)
|