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

19 lines
555 B
Python
Raw Normal View History

2021-01-25 12:05:40 +00:00
import os
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
2021-03-28 10:58:54 +00:00
id += "_"
2021-04-03 01:57:51 +00:00
# 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("-"):]
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)