Maximofn commited on
Commit
5954bab
1 Parent(s): 398bbd9

Get twitch ID video before download it

Browse files
Files changed (2) hide show
  1. app.py +10 -3
  2. download.py +6 -4
app.py CHANGED
@@ -25,9 +25,9 @@ if DEVICE == "cpu":
25
  # I supose that I am on huggingface server
26
  # Get RAM space
27
  ram = int(os.popen("free -m | grep Mem | awk '{print $2}'").read())
28
- vram = 12288
29
- SECONDS = int(ram*700/vram)
30
- print(f"RAM: {ram}")
31
  else:
32
  # I supose that I am on my computer
33
  # Get VRAM space
@@ -443,6 +443,13 @@ def change_visibility_texboxes():
443
  )
444
 
445
  def get_audio_and_video_from_video(url):
 
 
 
 
 
 
 
446
  python_file = "download.py"
447
  command = f"python {python_file} {url}"
448
  os.system(command)
 
25
  # I supose that I am on huggingface server
26
  # Get RAM space
27
  ram = int(os.popen("free -m | grep Mem | awk '{print $2}'").read())
28
+ factor = 1
29
+ SECONDS = int(ram*factor)
30
+ print(f"RAM: {ram}, SECONDS: {SECONDS}")
31
  else:
32
  # I supose that I am on my computer
33
  # Get VRAM space
 
443
  )
444
 
445
  def get_audio_and_video_from_video(url):
446
+ audios_folder = "audios"
447
+ videos_folder = "videos"
448
+ if not os.path.exists(audios_folder):
449
+ os.makedirs(audios_folder)
450
+ if not os.path.exists(videos_folder):
451
+ os.makedirs(videos_folder)
452
+
453
  python_file = "download.py"
454
  command = f"python {python_file} {url}"
455
  os.system(command)
download.py CHANGED
@@ -5,6 +5,7 @@ import twitchdl.commands as twitch_downloader
5
  import twitchdl.twitch
6
  from twitchdl.commands.download import _parse_playlists
7
  from tqdm import tqdm
 
8
 
9
  VIDEO_FOLDER = 'videos'
10
  AUDIO_FOLDER = 'audios'
@@ -39,17 +40,18 @@ def download_twitch(url, type):
39
  argparser.add_argument('videos', default=[url], help='Videos', nargs='+')
40
  args = argparser.parse_args()
41
 
 
 
 
42
  # Get qualitys
43
- access_token = twitchdl.twitch.get_access_token(1942562640, None)
44
- playlists_m3u8 = twitchdl.twitch.get_playlists(1942562640, access_token)
45
  playlists = list(_parse_playlists(playlists_m3u8))
46
  qualitys = [name for (name, _, _) in playlists]
47
 
48
  # Select quality
49
  if type == DOWNLOAD_VIDEO:
50
  args.quality = qualitys[0]
51
- if args.quality == '1080p' or args.quality == '720p':
52
- args.quality = f'{args.quality}60'
53
  args.format = DOWNLOAD_VIDEO_FORMAT
54
  args.output = f'{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{args.format}'
55
  elif type == DOWNLOAD_AUDIO:
 
5
  import twitchdl.twitch
6
  from twitchdl.commands.download import _parse_playlists
7
  from tqdm import tqdm
8
+ import re
9
 
10
  VIDEO_FOLDER = 'videos'
11
  AUDIO_FOLDER = 'audios'
 
40
  argparser.add_argument('videos', default=[url], help='Videos', nargs='+')
41
  args = argparser.parse_args()
42
 
43
+ # Get video id
44
+ video_id = re.search(r'(?<=videos\/)\d+', url).group(0)
45
+
46
  # Get qualitys
47
+ access_token = twitchdl.twitch.get_access_token(video_id, None)
48
+ playlists_m3u8 = twitchdl.twitch.get_playlists(video_id, access_token)
49
  playlists = list(_parse_playlists(playlists_m3u8))
50
  qualitys = [name for (name, _, _) in playlists]
51
 
52
  # Select quality
53
  if type == DOWNLOAD_VIDEO:
54
  args.quality = qualitys[0]
 
 
55
  args.format = DOWNLOAD_VIDEO_FORMAT
56
  args.output = f'{VIDEO_FOLDER}/{DOWNLOAD_VIDEO_NAME}.{args.format}'
57
  elif type == DOWNLOAD_AUDIO: