Datasets:
shawshankvkt
commited on
Commit
•
503360e
1
Parent(s):
22cb23f
Upload download_WTours.py
Browse files- download_WTours.py +33 -0
download_WTours.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytube import YouTube
|
2 |
+
import os
|
3 |
+
|
4 |
+
file_path = 'WTour.txt'
|
5 |
+
output_base_folder = 'videos'
|
6 |
+
|
7 |
+
|
8 |
+
if not os.path.exists(output_base_folder):
|
9 |
+
os.makedirs(output_base_folder)
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
with open(file_path, 'r') as file:
|
14 |
+
for line in file:
|
15 |
+
try:
|
16 |
+
youtube_link, city = map(str.strip, line.split(','))
|
17 |
+
output_folder = os.path.join(output_base_folder, city)
|
18 |
+
|
19 |
+
if not os.path.exists(output_folder):
|
20 |
+
os.makedirs(output_folder)
|
21 |
+
|
22 |
+
yt = YouTube(youtube_link, use_oauth=True, allow_oauth_cache=True)
|
23 |
+
video = yt.streams.filter(adaptive=True, file_extension='mp4').order_by('resolution').desc().first()
|
24 |
+
video.download(output_folder)
|
25 |
+
print(f"Video downloaded for {city}")
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Error processing line: {line}\nError: {e}")
|
28 |
+
|
29 |
+
|
30 |
+
print("All videos downloaded successfully!")
|
31 |
+
|
32 |
+
|
33 |
+
|