1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-09-21 11:07:30 +00:00
NewLeaf/tools/files.py

25 lines
715 B
Python
Raw Normal View History

2021-01-25 12:05:40 +00:00
import os
2021-08-16 09:56:32 +00:00
import re
2021-01-25 12:05:40 +00:00
def get_created_files(id):
2021-08-16 09:56:32 +00:00
# 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)
2021-04-03 01:57:51 +00:00
2021-08-16 09:56:32 +00:00
# all file names then have an underscore before the converted URL
id += "_"
trim_id += "_"
2021-04-03 01:57:51 +00:00
2021-03-28 10:58:54 +00:00
return (f for f in os.listdir() if f.startswith(id) or f.startswith(trim_id))
2021-01-25 12:05:40 +00:00
def clean_up_temp_files(id):
created_files = get_created_files(id)
for file in created_files:
os.unlink(file)