diff --git a/extractors/video.py b/extractors/video.py index f4da76e..fe23de7 100644 --- a/extractors/video.py +++ b/extractors/video.py @@ -209,7 +209,7 @@ def get_more_stuff_from_file(id, result): # Figure out what the name of the saved file was recommendations = [] created_files = files.get_created_files(id) - possible_files = [f for f in created_files if f[11:].startswith("_https_-_www.youtube.com")] + possible_files = [f for f in created_files if "_https_-_www.youtube.com_watch" in f] try: if len(possible_files) == 1: filename = possible_files[0] diff --git a/tools/files.py b/tools/files.py index 92cc474..027a486 100644 --- a/tools/files.py +++ b/tools/files.py @@ -1,14 +1,20 @@ import os +import re def get_created_files(id): - if id[0] == "-": - id = "_" + id[1:] # youtube-dl changes - to _ at the start, presumably to not accidentally trigger switches with * in shell - id += "_" + # youtube-dl transforms filenames when saving, for example changing - to _ at the start to presumbly not trigger switches in shell, but also in other strange ways too + patterns = [ + "__+", "_", + "^_*(-_)?", "", + "^-", "_" + ] + trim_id = id + for find, replace in zip(patterns[::-2], patterns[1::-2]): # for each 2 items in the list + trim_id = re.sub(find, replace, trim_id) - # youtube-dl thinks it's a really good idea to do this, for some reason. - trim_id = id.lstrip("_") - if trim_id.startswith("-"): - trim_id = "_" + trim_id[len("-"):] + # all file names then have an underscore before the converted URL + id += "_" + trim_id += "_" return (f for f in os.listdir() if f.startswith(id) or f.startswith(trim_id))