Skip to content

Commit

Permalink
fix: select biggest file for movie caches
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaisberg authored and Gaisberg committed Sep 10, 2024
1 parent 578ae8f commit c6f9337
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/program/downloaders/realdebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
self.initialized = self.validate()
if self.initialized:
self.existing_hashes = [torrent["hash"] for torrent in get_torrents(1000)]
self.file_finder = FileFinder("filename")
self.file_finder = FileFinder("filename", "filesize")

def validate(self) -> bool:
"""Validate Real-Debrid settings and API key"""
Expand Down
10 changes: 5 additions & 5 deletions src/program/downloaders/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class FileFinder:
filename_attr (str): The name of the file attribute.
"""

def __init__(self, name):
def __init__(self, name, size):
self.filename_attr = name
self.filesize_attr = size

def get_cached_container(self, needed_media: dict[int, list[int]], break_pointer: list[bool] = [False], container: dict = {}) -> dict:
if not needed_media or len(container) >= len([episode for season in needed_media for episode in needed_media[season]]):
Expand Down Expand Up @@ -68,10 +69,9 @@ def cache_matches(self, cached_files: dict, needed_media: dict[int, list[int]],
if not needed_episodes:
return matches_dict
else:
for file in cached_files.values():
matched_movie = self.filename_matches_movie(file[self.filename_attr])
if matched_movie:
return {1: {1: file}}
biggest_file = max(cached_files.values(), key=lambda x: x[self.filesize_attr])
if biggest_file and self.filename_matches_movie(biggest_file[self.filename_attr]):
return {1: {1: biggest_file}}

def get_needed_media(item: MediaItem) -> dict:
acceptable_states = [States.Indexed, States.Scraped, States.Unknown, States.Failed, States.PartiallyCompleted]
Expand Down

0 comments on commit c6f9337

Please sign in to comment.