Walking_Tours / download_WTours.py
shawshankvkt's picture
Upload download_WTours.py
503360e verified
raw
history blame
951 Bytes
from pytube import YouTube
import os
file_path = 'WTour.txt'
output_base_folder = 'videos'
if not os.path.exists(output_base_folder):
os.makedirs(output_base_folder)
with open(file_path, 'r') as file:
for line in file:
try:
youtube_link, city = map(str.strip, line.split(','))
output_folder = os.path.join(output_base_folder, city)
if not os.path.exists(output_folder):
os.makedirs(output_folder)
yt = YouTube(youtube_link, use_oauth=True, allow_oauth_cache=True)
video = yt.streams.filter(adaptive=True, file_extension='mp4').order_by('resolution').desc().first()
video.download(output_folder)
print(f"Video downloaded for {city}")
except Exception as e:
print(f"Error processing line: {line}\nError: {e}")
print("All videos downloaded successfully!")