Skip to content

Commit

Permalink
fix: fixed alldebrid instantavail file processing
Browse files Browse the repository at this point in the history
  • Loading branch information
dreulavelle committed Nov 27, 2024
1 parent 73b5179 commit b0d704d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/program/services/downloaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self, item: MediaItem):
download_success = True
break
else:
raise NoMatchingFilesException(f"No valid files found for stream {stream.infohash}")
raise NoMatchingFilesException(f"No valid files found")
except Exception as e:
logger.debug(f"Stream {stream.infohash} failed: {e}")
if 'download_result' in locals() and download_result.id:
Expand Down
23 changes: 21 additions & 2 deletions src/program/services/downloaders/alldebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,27 @@ def get_instant_availability(self, infohash: str, item_type: str) -> Optional[To
info = self.get_torrent_info(torrent_id)
if info.status == "Ready":
files = self.get_files_and_links(torrent_id)
processed_files = [DebridFile.create(filename=file["n"], filesize_bytes=file["s"], filetype=item_type) for file in files]
if processed_files is not None:
processed_files = []

def process_entry(entry):
if isinstance(entry, dict):
# file entries
if 'n' in entry and 's' in entry and 'l' in entry:
if debrid_file := DebridFile.create(
filename=entry['n'],
filesize_bytes=entry['s'],
filetype=item_type
):
processed_files.append(debrid_file)
# directory entries
elif 'e' in entry:
for sub_entry in entry['e']:
process_entry(sub_entry)

for file_entry in files:
process_entry(file_entry)

if processed_files:
return_value = TorrentContainer(infohash=infohash, files=processed_files)
except Exception as e:
logger.error(f"Failed to get instant availability: {e}")
Expand Down

0 comments on commit b0d704d

Please sign in to comment.