0x22almostEvil commited on
Commit
7beabae
1 Parent(s): 9d051db

Upload 5 files

Browse files
Files changed (5) hide show
  1. channel_urls.txt +1 -0
  2. generate_dataset.py +76 -0
  3. generate_urls.py +10 -0
  4. polish_dataset.py +33 -0
  5. urls.txt +0 -0
channel_urls.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://www.youtube.com/channel/UCX6OQ3DkcsbYNE6H8uQQuVA
generate_dataset.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import os
3
+ import glob
4
+ import shutil
5
+ from concurrent.futures import ThreadPoolExecutor
6
+
7
+ def move_to_unmatched(base_path, lang, audio_exists, subtitle_exists):
8
+ unmatched_path = os.path.join(base_path, "unmatched", lang)
9
+ os.makedirs(unmatched_path, exist_ok=True)
10
+
11
+ if audio_exists:
12
+ audio_file = glob.glob(f"{base_path}/{lang}.wav")[0]
13
+ shutil.move(audio_file, unmatched_path)
14
+
15
+ if subtitle_exists:
16
+ subtitle_file = glob.glob(f"{base_path}/{lang}.vtt")[0]
17
+ shutil.move(subtitle_file, unmatched_path)
18
+
19
+ def download_and_convert_audio(video_url, languages):
20
+ video_id = video_url.split('=')[-1]
21
+ base_path = f"dataset/{video_id}"
22
+ os.makedirs(base_path, exist_ok=True)
23
+
24
+ for lang in languages:
25
+ command_download = [
26
+ 'yt-dlp',
27
+ '--extract-audio',
28
+ '--audio-format', 'm4a',
29
+ '--write-sub',
30
+ '--sub-langs', lang,
31
+ '--sub-format', 'vtt',
32
+ '--output', f"{base_path}/%(title)s.{lang}.%(ext)s",
33
+ '--format', f'bestaudio[ext=m4a][acodec=mp4a.40.2][language={lang}]',
34
+ video_url
35
+ ]
36
+ subprocess.run(command_download)
37
+
38
+ m4a_files = glob.glob(f"{base_path}/*.{lang}.m4a")
39
+ if m4a_files:
40
+ m4a_file = m4a_files[0]
41
+ wav_file = f"{base_path}/{lang}.wav"
42
+ command_convert = ['ffmpeg', '-i', m4a_file, '-acodec', 'pcm_s16le', '-ar', '44100', wav_file]
43
+ subprocess.run(command_convert)
44
+ os.remove(m4a_file)
45
+
46
+ vtt_files = glob.glob(f"{base_path}/*.{lang}.vtt")
47
+ if vtt_files:
48
+ vtt_file = vtt_files[0]
49
+ new_vtt_file = f"{base_path}/{lang}.vtt"
50
+ os.rename(vtt_file, new_vtt_file)
51
+
52
+ audio_exists = bool(glob.glob(f"{base_path}/{lang}.wav"))
53
+ subtitle_exists = bool(glob.glob(f"{base_path}/{lang}.vtt"))
54
+
55
+ if not (audio_exists and subtitle_exists):
56
+ move_to_unmatched(base_path, lang, audio_exists, subtitle_exists)
57
+
58
+ def process_video(url, languages):
59
+ try:
60
+ download_and_convert_audio(url, languages)
61
+ except Exception as e:
62
+ print(f"Error processing {url}: {e}")
63
+
64
+ if __name__ == "__main__":
65
+
66
+ video_urls = []
67
+
68
+ with open('urls.txt', 'r') as file:
69
+ video_urls = [line.strip() for line in file if line.strip()]
70
+
71
+ languages = ["ar", "es", "fr", "hi", "id", "ja", "ko", "pt", "ru", "th", "tr", "vi", "en"]
72
+
73
+ with ThreadPoolExecutor(max_workers=5) as executor:
74
+ futures = [executor.submit(process_video, url, languages) for url in video_urls]
75
+ for future in futures:
76
+ future.result()
generate_urls.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+
3
+ video_urls = []
4
+
5
+ with open("channel_urls.txt", "r") as f:
6
+ channel_urls = f.readlines()
7
+
8
+ for channel_url in channel_urls:
9
+ command = ["yt-dlp", "--flat-playlist", "--print-to-file", "webpage_url", "urls.txt", channel_url]
10
+ subprocess.run(command)
polish_dataset.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+
4
+ main_directory = "dataset"
5
+
6
+ deleted_folders = 0
7
+ remaining_folders = 0
8
+
9
+ for folder_name in os.listdir(main_directory):
10
+ folder_path = os.path.join(main_directory, folder_name)
11
+
12
+ if os.path.isdir(folder_path):
13
+ subfolders = os.listdir(folder_path)
14
+ if len(subfolders) == 1 and subfolders[0] == "unmatched" and os.path.isdir(os.path.join(folder_path, "unmatched")):
15
+
16
+ print(f"Content of folder {folder_name}:")
17
+ for item in os.listdir(folder_path):
18
+ print(f"- {item}")
19
+
20
+ print(f"It's bad sample. Deleting folder: {folder_name}")
21
+ shutil.rmtree(folder_path)
22
+ deleted_folders += 1
23
+
24
+ else:
25
+ print(f"Content of folder {folder_name}:")
26
+ for item in os.listdir(folder_path):
27
+ print(f"- {item}")
28
+ print(f"It's good sample #{folder_name}. Keeping.")
29
+ remaining_folders += 1
30
+
31
+ # Display the results
32
+ print(f"Deleted {deleted_folders} empty folders.")
33
+ print(f"Remaining folders: {remaining_folders}")
urls.txt ADDED
File without changes