-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.py
More file actions
25 lines (22 loc) · 1010 Bytes
/
scanner.py
File metadata and controls
25 lines (22 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
from datetime import datetime, timedelta
import logging
from config import SUPPORTED_FORMATS, FILE_AGE_THRESHOLD
class MediaScanner:
def __init__(self, root_path):
self.root_path = root_path
def is_file_old_enough(self, file_path):
"""Check if file is older than threshold."""
file_time = datetime.fromtimestamp(os.path.getmtime(file_path))
return datetime.now() - file_time > timedelta(days=FILE_AGE_THRESHOLD)
def scan_directory(self):
"""Recursively scan directory for media files."""
for root, _, files in os.walk(self.root_path):
for file in files:
if file.lower().endswith(SUPPORTED_FORMATS):
file_path = os.path.join(root, file)
try:
if self.is_file_old_enough(file_path):
yield file_path
except Exception as e:
logging.error(f"Error scanning file {file_path}: {e}")