File size: 1,324 Bytes
503360e
 
8809a69
503360e
 
8809a69
503360e
 
8809a69
 
 
 
503360e
8809a69
 
503360e
8809a69
 
 
 
 
503360e
 
 
 
 
 
 
 
8809a69
503360e
8809a69
 
503360e
 
 
 
 
 
 
8809a69
503360e
 
8809a69
 
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
35
36
37
38
39
40
41
42
43
44
45
46
from pytube import YouTube 
import os
import argparse


input_file = 'WTour.txt'


def main():
    parser = argparse.ArgumentParser(description='Download WTour videos from WTour.txt')
    parser.add_argument('--output_folder', help='Path to the store videos')
    args = parser.parse_args()

    
    output_base_folder = args.output_folder

    if not os.path.exists(output_base_folder):
        os.makedirs(output_base_folder)

    # exit()
    with open(input_file, '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)

                # downloads the highest res WTour videos. 
                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!")


if __name__ == "__main__":
    main()