mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-25 18:25:35 +02:00
feat: add archive extraction functionality during torrent import process
This commit is contained in:
@@ -1,25 +1,37 @@
|
||||
import logging
|
||||
import mimetypes
|
||||
from pathlib import Path
|
||||
|
||||
import patoolib
|
||||
|
||||
from config import BasicConfig
|
||||
from torrent.schemas import Torrent
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def list_files_recursively(path: Path = Path(".")) -> list[Path]:
|
||||
files = list(path.glob("**/*"))
|
||||
logging.debug(f"Found {len(files)} entries via glob")
|
||||
log.debug(f"Found {len(files)} entries via glob")
|
||||
valid_files = []
|
||||
for x in files:
|
||||
if x.is_dir():
|
||||
logging.debug(f"'{x}' is a directory")
|
||||
log.debug(f"'{x}' is a directory")
|
||||
elif x.is_symlink():
|
||||
logging.debug(f"'{x}' is a symlink")
|
||||
log.debug(f"'{x}' is a symlink")
|
||||
else:
|
||||
valid_files.append(x)
|
||||
logging.debug(f"Returning {len(valid_files)} files after filtering")
|
||||
log.debug(f"Returning {len(valid_files)} files after filtering")
|
||||
return valid_files
|
||||
|
||||
|
||||
def extract_archives(files):
|
||||
for file in files:
|
||||
file_type = mimetypes.guess_type(file)
|
||||
log.debug(f"File: {file}, Size: {file.stat().st_size} bytes, Type: {file_type}")
|
||||
if file_type[0] == 'application/x-compressed':
|
||||
log.debug(f"File {file} is a compressed file, extracting it into directory {file.parent}")
|
||||
patoolib.extract_archive(str(file), outdir=str(file.parent))
|
||||
|
||||
def get_torrent_filepath(torrent: Torrent):
|
||||
return BasicConfig().torrent_directory / torrent.title
|
||||
|
||||
|
||||
Reference in New Issue
Block a user