shawshankvkt commited on
Commit
8809a69
1 Parent(s): a0e9bba

Upload download_WTours.py

Browse files
Files changed (1) hide show
  1. download_WTours.py +19 -7
download_WTours.py CHANGED
@@ -1,16 +1,24 @@
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(','))
@@ -19,7 +27,10 @@ with open(file_path, 'r') as file:
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}")
@@ -27,7 +38,8 @@ with open(file_path, 'r') as file:
27
  print(f"Error processing line: {line}\nError: {e}")
28
 
29
 
30
- print("All videos downloaded successfully!")
31
-
32
 
33
 
 
 
 
1
  from pytube import YouTube
2
  import os
3
+ import argparse
4
 
 
 
5
 
6
+ input_file = 'WTour.txt'
7
 
 
 
8
 
9
+ def main():
10
+ parser = argparse.ArgumentParser(description='Download WTour videos from WTour.txt')
11
+ parser.add_argument('--output_folder', help='Path to the store videos')
12
+ args = parser.parse_args()
13
 
14
+
15
+ output_base_folder = args.output_folder
16
 
17
+ if not os.path.exists(output_base_folder):
18
+ os.makedirs(output_base_folder)
19
+
20
+ # exit()
21
+ with open(input_file, 'r') as file:
22
  for line in file:
23
  try:
24
  youtube_link, city = map(str.strip, line.split(','))
 
27
  if not os.path.exists(output_folder):
28
  os.makedirs(output_folder)
29
 
30
+
31
  yt = YouTube(youtube_link, use_oauth=True, allow_oauth_cache=True)
32
+
33
+ # downloads the highest res WTour videos.
34
  video = yt.streams.filter(adaptive=True, file_extension='mp4').order_by('resolution').desc().first()
35
  video.download(output_folder)
36
  print(f"Video downloaded for {city}")
 
38
  print(f"Error processing line: {line}\nError: {e}")
39
 
40
 
41
+ print("All videos downloaded successfully!")
 
42
 
43
 
44
+ if __name__ == "__main__":
45
+ main()