1
0
Fork 0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2026-03-05 12:01:38 +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

@ -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))