Compare commits
2 Commits
171163b3d9
...
c2f5732351
Author | SHA1 | Date |
---|---|---|
MasterofJOKers | c2f5732351 | |
MasterofJOKers | 16de972f7b |
30
mirror-yt.py
30
mirror-yt.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ def download(allow_unknown, base_dir, channel_file):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
dir_name, url = line.split(';')
|
dir_name, url = line.split(';')
|
||||||
channels[dir_name] = url
|
channels[dir_name] = url
|
||||||
|
|
||||||
|
@ -59,7 +60,32 @@ def download(allow_unknown, base_dir, channel_file):
|
||||||
'--write-thumbnail',
|
'--write-thumbnail',
|
||||||
url
|
url
|
||||||
]
|
]
|
||||||
subprocess.run(cmd, check=True, cwd=target_dir)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=target_dir)
|
||||||
|
prev_output = ''
|
||||||
|
while p.poll() is None:
|
||||||
|
try:
|
||||||
|
stdout_data, stderr_data = p.communicate(timeout=0.5)
|
||||||
|
except subprocess.TimeoutExpired as e:
|
||||||
|
if e.output:
|
||||||
|
print(e.output[len(prev_output):].decode('utf-8'), end='')
|
||||||
|
prev_output = e.output or ''
|
||||||
|
else:
|
||||||
|
print(stdout_data[len(prev_output):].decode('utf-8'))
|
||||||
|
|
||||||
|
stdout_lines = stdout_data.decode('utf-8').splitlines()
|
||||||
|
if p.returncode == 0:
|
||||||
|
return
|
||||||
|
if p.returncode == 101:
|
||||||
|
pass
|
||||||
|
elif p.returncode == 1 and stdout_lines[-1] and 'Finished downloading playlist' in stdout_lines[-1]:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
breakpoint()
|
||||||
|
raise subprocess.CalledProcessError(returncode=p.returncode, cmd=cmd)
|
||||||
|
|
||||||
|
sleep_seconds = 5
|
||||||
|
print(f"Sleeping {sleep_seconds}s")
|
||||||
|
time.sleep(sleep_seconds)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue