mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-26 18:55:44 +02:00
refactor torrent module to use dependency injection and decouple tv and torrent module for better separation of concerns
This commit is contained in:
@@ -44,3 +44,36 @@ def import_file(target_file: Path, source_file: Path):
|
||||
if target_file.exists():
|
||||
target_file.unlink()
|
||||
target_file.hardlink_to(source_file)
|
||||
|
||||
|
||||
def import_torrent(torrent: Torrent) -> (list[Path], list[Path], list[Path]):
|
||||
"""
|
||||
Extracts all files from the torrent download directory, including extracting archives.
|
||||
Returns a tuple containing: seperated video files, subtitle files, and all files found in the torrent directory.
|
||||
"""
|
||||
log.info(f"Importing torrent {torrent}")
|
||||
all_files = list_files_recursively(path=get_torrent_filepath(torrent=torrent))
|
||||
log.debug(f"Found {len(all_files)} files downloaded by the torrent")
|
||||
extract_archives(all_files)
|
||||
all_files = list_files_recursively(path=get_torrent_filepath(torrent=torrent))
|
||||
|
||||
video_files = []
|
||||
subtitle_files = []
|
||||
for file in all_files:
|
||||
file_type, _ = mimetypes.guess_type(str(file))
|
||||
if file_type is not None:
|
||||
if file_type.startswith("video"):
|
||||
video_files.append(file)
|
||||
log.debug(f"File is a video, it will be imported: {file}")
|
||||
elif file_type.startswith("text") and Path(file).suffix == ".srt":
|
||||
subtitle_files.append(file)
|
||||
log.debug(f"File is a subtitle, it will be imported: {file}")
|
||||
else:
|
||||
log.debug(
|
||||
f"File is neither a video nor a subtitle, will not be imported: {file}"
|
||||
)
|
||||
|
||||
log.info(
|
||||
f"Found {len(all_files)} files ({len(video_files)} video files, {len(subtitle_files)} subtitle files) for further processing."
|
||||
)
|
||||
return video_files, subtitle_files, all_files
|
||||
Reference in New Issue
Block a user