1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-21 23:27:29 +00:00

Fix file detection and recommendations

This commit is contained in:
Cadence Ember 2021-08-16 21:56:32 +12:00
parent e496ccb45a
commit d2df18ff75
No known key found for this signature in database
GPG Key ID: BC1C2C61CF521B17
2 changed files with 14 additions and 8 deletions

View File

@ -209,7 +209,7 @@ def get_more_stuff_from_file(id, result):
# Figure out what the name of the saved file was # Figure out what the name of the saved file was
recommendations = [] recommendations = []
created_files = files.get_created_files(id) 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: try:
if len(possible_files) == 1: if len(possible_files) == 1:
filename = possible_files[0] filename = possible_files[0]

View File

@ -1,14 +1,20 @@
import os import os
import re
def get_created_files(id): def get_created_files(id):
if id[0] == "-": # 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
id = "_" + id[1:] # youtube-dl changes - to _ at the start, presumably to not accidentally trigger switches with * in shell patterns = [
id += "_" "__+", "_",
"^_*(-_)?", "",
"^-", "_"
]
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. # all file names then have an underscore before the converted URL
trim_id = id.lstrip("_") id += "_"
if trim_id.startswith("-"): trim_id += "_"
trim_id = "_" + trim_id[len("-"):]
return (f for f in os.listdir() if f.startswith(id) or f.startswith(trim_id)) return (f for f in os.listdir() if f.startswith(id) or f.startswith(trim_id))