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:
parent
e496ccb45a
commit
d2df18ff75
@ -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]
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user