Download episodes and provide regular updates
This commit is contained in:
parent
47bb1f761a
commit
34ef348929
@ -9,6 +9,7 @@ state_file_name_suffix = .log
|
||||
mvw_endpoint = http://localhost:8000/api/query
|
||||
title_dedup_winner = first
|
||||
dl_progress_update_interval = 10
|
||||
dl_threads = 2
|
||||
|
||||
[maus]
|
||||
min_duration = 1200
|
||||
|
17
mvw-dl.py
17
mvw-dl.py
@ -89,7 +89,8 @@ class CONST(object):
|
||||
{"key": "state_file_name_suffix", "value": ".log"},
|
||||
{"key": "mvw_endpoint", "value": "http://localhost:8000/api/query"},
|
||||
{"key": "title_dedup_winner", "value": "first"},
|
||||
{"key": "dl_progress_update_interval", "value": "10"}
|
||||
{"key": "dl_progress_update_interval", "value": "10"},
|
||||
{"key": "dl_threads", "value": "2"}
|
||||
]
|
||||
CFG_KNOWN_SECTION = [
|
||||
{"key": "min_duration", "is_mandatory": False},
|
||||
@ -355,11 +356,15 @@ def copy_url(
|
||||
global download_start_time
|
||||
global download_last_update_time
|
||||
global size_downloaded
|
||||
|
||||
update_interval = config_obj.getint(section_name, "dl_progress_update_interval")
|
||||
max_quality_url = video_metadata["url"]
|
||||
filename = max_quality_url.split("/")[-1]
|
||||
dest_path = os.path.join("./", filename)
|
||||
show_name = f"{show.topic} - {show.title}"
|
||||
|
||||
with open(dest_path, "wb") as dest_file:
|
||||
log.info(f"""Downloading "{show_name}" ...""")
|
||||
r = requests.get(max_quality_url, stream=True)
|
||||
for chunk in r.iter_content(32768):
|
||||
size_downloaded += len(chunk)
|
||||
@ -375,8 +380,9 @@ def copy_url(
|
||||
log.debug(f"Downloaded {human_pct}% ({human_size_dl}/{human_total_dl} at an average "
|
||||
f"{human_dl_speed_so_far})")
|
||||
if done_event.is_set():
|
||||
log.debug(f"done_event")
|
||||
log.info(f"""Download of "{show_name}" interrupted""")
|
||||
return
|
||||
log.info(f"""Download of "{show_name}" done""")
|
||||
|
||||
|
||||
def get_max_quality_url(
|
||||
@ -403,9 +409,13 @@ def download_media(
|
||||
section_name: str,
|
||||
config_obj: configparser.ConfigParser(),
|
||||
json_obj: MVWJSONResponse) -> None:
|
||||
|
||||
global download_start_time
|
||||
global download_last_update_time
|
||||
|
||||
dl_threads = config_obj.getint(section_name, "dl_threads")
|
||||
video_metadata = {}
|
||||
|
||||
for result in json_obj.result.results.copy():
|
||||
max_quality_url = get_max_quality_url(result)
|
||||
content_length = get_content_length(max_quality_url)
|
||||
@ -414,7 +424,8 @@ def download_media(
|
||||
for video in video_metadata:
|
||||
total_content_length += video_metadata[video]["content_length"]
|
||||
video_metadata["total_content_length"] = total_content_length
|
||||
with ThreadPoolExecutor(max_workers=2) as pool:
|
||||
log.info(f"Limiting parallel downloads to {dl_threads} ...")
|
||||
with ThreadPoolExecutor(max_workers=dl_threads) as pool:
|
||||
download_last_update_time = time.time()
|
||||
download_start_time = download_last_update_time
|
||||
update_interval = config_obj.getint(section_name, "dl_progress_update_interval")
|
||||
|
Loading…
x
Reference in New Issue
Block a user