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.
30 lines
865 B
30 lines
865 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(f"../assets/temp/{id}/"):
|
|
count = 0
|
|
files = [f for f in os.listdir(f"../assets/temp/{id}/") if f.endswith(".mp4")]
|
|
count += len(files)
|
|
for f in files:
|
|
os.remove(f"../assets/temp/{id}/{f}")
|
|
REMOVE_DIRS = [f"../assets/temp/{id}/mp3/", f"../assets/temp/{id}/png/"]
|
|
for d in REMOVE_DIRS:
|
|
if exists(d):
|
|
count += len(_listdir(d))
|
|
for f in _listdir(d):
|
|
os.remove(f)
|
|
os.rmdir(d)
|
|
os.rmdir(f"../assets/temp/{id}/")
|
|
return count
|