Skip to content

Commit

Permalink
Fixes for filedata
Browse files Browse the repository at this point in the history
  • Loading branch information
westsurname authored May 24, 2024
1 parent 9a4e8d8 commit cebdd99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
8 changes: 5 additions & 3 deletions blackhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ async def is_accessible(path, timeout=10):
executor.shutdown(wait=False)

with open(file.fileInfo.filePathProcessing, 'rb' if file.torrentInfo.isDotTorrentFile else 'r') as f:
fileData = f.read()
f.seek(0)

torrentConstructors = []
if realdebrid['enabled']:
torrentConstructors.append(RealDebridTorrent if file.torrentInfo.isDotTorrentFile else RealDebridMagnet)
Expand All @@ -280,7 +283,7 @@ async def is_accessible(path, timeout=10):

onlyLargestFile = isRadarr or bool(re.search(r'S[\d]{2}E[\d]{2}', file.fileInfo.filename))
if not blackhole['failIfNotCached']:
torrents = [constructor(f, file, blackhole['failIfNotCached'], onlyLargestFile) for constructor in torrentConstructors]
torrents = [constructor(f, fileData, file, blackhole['failIfNotCached'], onlyLargestFile) for constructor in torrentConstructors]
results = await asyncio.gather(*(processTorrent(torrent, file, arr) for torrent in torrents))

if not any(results):
Expand All @@ -289,7 +292,7 @@ async def is_accessible(path, timeout=10):
else:
for i, constructor in enumerate(torrentConstructors):
isLast = (i == len(torrentConstructors) - 1)
torrent = constructor(f, file, blackhole['failIfNotCached'], onlyLargestFile)
torrent = constructor(f, fileData, file, blackhole['failIfNotCached'], onlyLargestFile)

if await processTorrent(torrent, file, arr):
break
Expand All @@ -311,7 +314,6 @@ def fail(torrent: TorrentBase, arr: Arr):
def print(*values: object):
_print(f"[{torrent.__class__.__name__}] [{torrent.file.fileInfo.filenameWithoutExt}]", *values)


print(f"Failing")

history = arr.getHistory(blackhole['historyPageSize'])['records']
Expand Down
17 changes: 6 additions & 11 deletions shared/debrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ class TorrentBase(ABC):
STATUS_COMPLETED = 'completed'
STATUS_ERROR = 'error'

def __init__(self, f, file, failIfNotCached, onlyLargestFile) -> None:
def __init__(self, f, fileData, file, failIfNotCached, onlyLargestFile) -> None:
super().__init__()
self.f = f
self.fileData = fileData
self.file = file
self.failIfNotCached = failIfNotCached
self.onlyLargestFile = onlyLargestFile
Expand All @@ -117,12 +118,6 @@ def __init__(self, f, file, failIfNotCached, onlyLargestFile) -> None:
def print(self, *values: object):
print(f"[{datetime.now()}] [{self.__class__.__name__}] [{self.file.fileInfo.filenameWithoutExt}]", *values)

@cached_property
def fileData(self):
fileData = self.f.read()
self.f.seek(0)
return fileData

@abstractmethod
def submitTorrent(self):
pass
Expand Down Expand Up @@ -164,8 +159,8 @@ def _enforceId(self):
raise Exception("Id is required. Must be acquired via successfully running submitTorrent() first.")

class RealDebrid(TorrentBase):
def __init__(self, f, file, failIfNotCached, onlyLargestFile) -> None:
super().__init__(f, file, failIfNotCached, onlyLargestFile)
def __init__(self, f, fileData, file, failIfNotCached, onlyLargestFile) -> None:
super().__init__(f, fileData, file, failIfNotCached, onlyLargestFile)
self.headers = {'Authorization': f'Bearer {realdebrid["apiKey"]}'}
self.mountTorrentsPath = realdebrid["mountTorrentsPath"]

Expand Down Expand Up @@ -304,8 +299,8 @@ def _normalize_status(self, status):
return status

class Torbox(TorrentBase):
def __init__(self, f, file, failIfNotCached, onlyLargestFile) -> None:
super().__init__(f, file, failIfNotCached, onlyLargestFile)
def __init__(self, f, fileData, file, failIfNotCached, onlyLargestFile) -> None:
super().__init__(f, fileData, file, failIfNotCached, onlyLargestFile)
self.headers = {'Authorization': f'Bearer {torbox["apiKey"]}'}
self.mountTorrentsPath = torbox["mountTorrentsPath"]
self.submittedTime = None
Expand Down

0 comments on commit cebdd99

Please sign in to comment.