1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-14 20:17:29 +00:00
NewLeaf/tools/files.py
Lomanic f22decbb74
Fix recommended videos extraction on IDs starting with - and _
Let's just leverage yt_dlp instead of rolling our own algorithms and fix
this kind of issue (not finding yt_dlp dump file for a given video) once
and for all

Example videos:
* https://www.youtube.com/watch?v=-q78QXpSL2M
* https://www.youtube.com/watch?v=_4SKG5uUEqs
2021-11-03 22:52:32 +13:00

17 lines
576 B
Python

import os
import yt_dlp.utils
def get_created_files(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
sanitized_id = yt_dlp.utils.sanitize_filename(id)
# all file names then have an underscore before the converted URL
id += "_"
sanitized_id += "_"
return (f for f in os.listdir() if f.startswith(id) or f.startswith(sanitized_id))
def clean_up_temp_files(id):
created_files = get_created_files(id)
for file in created_files:
os.unlink(file)