forked from lekoOwO/auto-ytarchive-raw
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlive_download.py
49 lines (44 loc) · 2.08 KB
/
live_download.py
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
47
48
49
import subprocess
import const
import utils
def download(video_id, live_status):
setDownloaded = True
# If download location is not set then don't download
if not const.DOWNLOAD and utils.PlayabilityStatus.ON_LIVE:
return setDownloaded
if not const.MEMBER_DOWNLOAD and utils.PlayabilityStatus.MEMBERS_ONLY:
return setDownloaded
if not const.PREMIUM_DOWNLOAD and utils.PlayabilityStatus.PREMIUM:
return setDownloaded
if not const.PREMIERE_DOWNLOAD and utils.PlayabilityStatus.PREMIERE:
return setDownloaded
command_list = ['start', f'ytarchive {video_id}', '/min', 'cmd', '/c']
command_list += ['ytarchive.exe', '-v']
if live_status == utils.PlayabilityStatus.LOGIN_REQUIRED and const.COOKIE is not None:
command_list += ['-c', const.COOKIE]
if live_status == utils.PlayabilityStatus.MEMBERS_ONLY and const.MEMBER_DOWNLOAD is not None:
command_list += ['-c', const.COOKIE]
command_list += ['-o', const.MEMBER_DOWNLOAD]
elif live_status == utils.PlayabilityStatus.PREMIUM:
command_list += ['-c', const.COOKIE]
command_list += ['-o', const.PREMIUM_DOWNLOAD]
elif live_status == utils.PlayabilityStatus.PREMIERE:
command_list += ['-o', const.PREMIERE_DOWNLOAD]
else:
command_list += ['-o', const.DOWNLOAD]
command_list += ['--add-metadata', '-t', '--vp9', '--mkv', '--write-description', '--write-thumbnail', '--threads', '2',
'-w']
command_list += [f'https://www.youtube.com/watch?v={video_id}', 'best']
try:
print(f"[INFO] Downloading Live Stream {video_id}")
output = subprocess.run(command_list, check=True, shell=True)
# If theres an error then this ensures a redownload, but only works if the program crashes by itself immediately
# print("[Debug]Output: ", output)
# print("[Debug]Return Code:", output.returncode)
if output.returncode != 0:
setDownloaded = False
setDownloaded = True
except Exception as e:
print(e)
setDownloaded = False
return setDownloaded