File size: 951 Bytes
503360e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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!")