2021-01-25 12:05:40 +00:00
import os
2021-11-01 01:21:30 +00:00
import yt_dlp . utils
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
2021-11-11 17:35:05 +00:00
sanitized_id = yt_dlp . utils . sanitize_filename ( id , restricted = True )
2021-08-16 09:56:32 +00:00
# all file names then have an underscore before the converted URL
id + = " _ "
2021-11-01 01:21:30 +00:00
sanitized_id + = " _ "
2021-04-03 01:57:51 +00:00
2021-11-11 17:35:05 +00:00
return ( f for f in os . listdir ( ) if f . startswith ( sanitized_id ) or f . startswith ( 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 )