Streamline download selection
This commit is contained in:
parent
d70766bae0
commit
287a755e65
42
mvw-dl.py
42
mvw-dl.py
@ -644,22 +644,28 @@ def get_content_length(
|
||||
return 0
|
||||
|
||||
|
||||
def is_already_downloaded(
|
||||
show: type_def.mvw_json_response.Show,
|
||||
state_file_abs_path: str,
|
||||
show_name: str) -> bool:
|
||||
def get_json_state(
|
||||
state_file_abs_path: str) -> json.loads:
|
||||
|
||||
with open(state_file_abs_path, "r") as state_file:
|
||||
with open(state_file_abs_path, "r", encoding="utf-8") as state_file:
|
||||
try:
|
||||
json_state = json.load(state_file)
|
||||
for log_entry in json_state:
|
||||
for log_data in [key for key in log_entry]:
|
||||
if show.topic == log_entry[log_data]["topic"] and show.title == log_entry[log_data]["title"]:
|
||||
log.debug(f"""Show "{show_name}" already downloaded, won't queue""")
|
||||
return True
|
||||
except json.JSONDecodeError:
|
||||
return False
|
||||
return False
|
||||
return []
|
||||
else:
|
||||
return json_state
|
||||
|
||||
|
||||
def is_already_downloaded(
|
||||
show: type_def.mvw_json_response.Show,
|
||||
json_state: json.loads,
|
||||
show_name: str) -> bool:
|
||||
|
||||
for log_entry in json_state:
|
||||
for log_data in [key for key in log_entry]:
|
||||
if show.topic == log_entry[log_data]["topic"] and show.title == log_entry[log_data]["title"]:
|
||||
log.debug(f"""Show "{show_name}" already downloaded, won't queue""")
|
||||
return True
|
||||
|
||||
|
||||
def download_media(
|
||||
@ -676,14 +682,6 @@ def download_media(
|
||||
state_lock_file = state_file_abs_path + state_lock_file_ext
|
||||
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)
|
||||
video_metadata[result.id] = {"url": max_quality_url, "content_length": content_length}
|
||||
total_content_length = 0
|
||||
for video in video_metadata:
|
||||
total_content_length += video_metadata[video]["content_length"]
|
||||
video_metadata["total_content_length"] = total_content_length
|
||||
tmp_dir = expanded_dest_dir(config_obj.get(section_name, "tmp_base_dir"))
|
||||
dest_dir = expanded_dest_dir(config_obj.get(section_name, "dl_dir"))
|
||||
log.info(f"""Download location is {tmp_dir}""")
|
||||
@ -692,6 +690,10 @@ def download_media(
|
||||
|
||||
lock = get_state_file_lock(state_lock_file)
|
||||
|
||||
with lock:
|
||||
state_file_none_or_valid_json(state_file_abs_path)
|
||||
json_state = get_json_state(state_file_abs_path)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=dl_threads) as pool:
|
||||
download_last_update_time = time.time()
|
||||
download_start_time = download_last_update_time
|
||||
|
Loading…
x
Reference in New Issue
Block a user