Prep for logging and safe filenames

This commit is contained in:
hygienic-books 2022-03-17 18:41:17 +01:00
parent 296e2ca7e5
commit 25d0059f14

View File

@ -345,6 +345,19 @@ def handle_sigint(signum, frame):
signal.signal(signal.SIGINT, handle_sigint) signal.signal(signal.SIGINT, handle_sigint)
def get_safe_filename(
dirty_filename: str) -> str:
"""https://stackoverflow.com/a/71199182"""
clean_filename = re.sub(r"[/\\?%*:|\"<>\x7F\x00-\x1F]", "-", dirty_filename)
return clean_filename
def log_successful_download(
show: type_def.mvw_json_response.Show) -> None:
pass
def copy_url( def copy_url(
section_name: str, section_name: str,
config_obj: configparser.ConfigParser(), config_obj: configparser.ConfigParser(),
@ -365,6 +378,7 @@ def copy_url(
dest_path = os.path.expanduser(dest_path) dest_path = os.path.expanduser(dest_path)
dest_path = os.path.expandvars(dest_path) dest_path = os.path.expandvars(dest_path)
show_name = f"{show.topic} - {show.title}" show_name = f"{show.topic} - {show.title}"
publish_date = d.datetime.utcfromtimestamp(show.timestamp).strftime('%Y%m%d')
os.makedirs(os.path.dirname(dest_path), exist_ok=True) os.makedirs(os.path.dirname(dest_path), exist_ok=True)
with open(dest_path, "wb") as dest_file: with open(dest_path, "wb") as dest_file:
@ -388,6 +402,7 @@ def copy_url(
log.info(f"""Download of "{show_name}" interrupted""") log.info(f"""Download of "{show_name}" interrupted""")
return return
log.info(f"""Download of "{show_name}" done""") log.info(f"""Download of "{show_name}" done""")
log_successful_download(show)
def get_max_quality_url( def get_max_quality_url(