|
@@ -146,19 +146,26 @@ def create_nfo_file(video_data, file_path):
|
|
|
with open(file_path, "w", encoding="utf-8") as nfo_file:
|
|
with open(file_path, "w", encoding="utf-8") as nfo_file:
|
|
|
nfo_file.write(nfo_content)
|
|
nfo_file.write(nfo_content)
|
|
|
|
|
|
|
|
-def delete_old_videos(folder, days=10):
|
|
|
|
|
- """Delete video files and corresponding NFO files older than `days`."""
|
|
|
|
|
|
|
+def delete_old_videos(folder, days=5):
|
|
|
|
|
+ """Delete video files and their folders older than `days`."""
|
|
|
now = time.time()
|
|
now = time.time()
|
|
|
cutoff = now - (days * 86400) # Convert days to seconds
|
|
cutoff = now - (days * 86400) # Convert days to seconds
|
|
|
|
|
|
|
|
- for root, dirs, files in os.walk(folder):
|
|
|
|
|
|
|
+ for root, dirs, files in os.walk(folder, topdown=False):
|
|
|
|
|
+ # Delete files
|
|
|
for file in files:
|
|
for file in files:
|
|
|
file_path = os.path.join(root, file)
|
|
file_path = os.path.join(root, file)
|
|
|
if os.path.isfile(file_path):
|
|
if os.path.isfile(file_path):
|
|
|
- # Check the file's last modification time
|
|
|
|
|
if os.path.getmtime(file_path) < cutoff:
|
|
if os.path.getmtime(file_path) < cutoff:
|
|
|
- print(f"Deleting: {file_path}")
|
|
|
|
|
|
|
+ print(f"Deleting file: {file_path}")
|
|
|
os.remove(file_path)
|
|
os.remove(file_path)
|
|
|
|
|
+
|
|
|
|
|
+ # Remove empty directories
|
|
|
|
|
+ for dir in dirs:
|
|
|
|
|
+ dir_path = os.path.join(root, dir)
|
|
|
|
|
+ if not os.listdir(dir_path): # Check if the directory is empty
|
|
|
|
|
+ print(f"Deleting folder: {dir_path}")
|
|
|
|
|
+ os.rmdir(dir_path)
|
|
|
|
|
|
|
|
def video_exists(output_path, video_id):
|
|
def video_exists(output_path, video_id):
|
|
|
"""Check if a video already exists in the directory."""
|
|
"""Check if a video already exists in the directory."""
|