You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
826 B
32 lines
826 B
import os
|
|
from os.path import exists
|
|
|
|
|
|
def _listdir(d): # listdir with full path
|
|
return [os.path.join(d, f) for f in os.listdir(d)]
|
|
|
|
|
|
def cleanup(id) -> int:
|
|
"""Deletes all temporary assets in assets/temp
|
|
|
|
Returns:
|
|
int: How many files were deleted
|
|
"""
|
|
if exists("./assets/temp"):
|
|
count = 0
|
|
files = [
|
|
f for f in os.listdir(".") if f.endswith(".mp4") and "temp" in f.lower()
|
|
]
|
|
count += len(files)
|
|
for f in files:
|
|
os.remove(f)
|
|
REMOVE_DIRS = [f"./assets/temp/{id}/mp3/", f"./assets/temp/{id}/png/"]
|
|
files_to_remove = list(map(_listdir, REMOVE_DIRS))
|
|
for directory in files_to_remove:
|
|
for file in directory:
|
|
count += 1
|
|
os.remove(file)
|
|
return count
|
|
|
|
return 0
|