Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions blackhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, filename, isRadarr) -> None:
isTorrentOrMagnet = isDotTorrentFile or filename.casefold().endswith('.magnet')
filenameWithoutExt, ext = os.path.splitext(filename)
filePath = os.path.join(baseBath, filename)
filePathProcessing = os.path.join(baseBath, 'processing', f"{filenameWithoutExt}_{uniqueId}{ext}")
filePathProcessing = trimProcessingFilepath(os.path.join(baseBath, 'processing'), filenameWithoutExt, f"_{uniqueId}{ext}")
folderPathCompleted = os.path.join(baseBath, 'completed', filenameWithoutExt)

self.fileInfo = self.FileInfo(filename, filenameWithoutExt, filePath, filePathProcessing, folderPathCompleted)
Expand All @@ -72,6 +72,15 @@ def getPath(isRadarr, create=False):

return finalPath

def trimProcessingFilepath(basepath, filename, ext):
MAX_PATH_LENGTH = 255
path = os.path.join(basepath, filename + ext)
if len(path) <= MAX_PATH_LENGTH:
return path

remainingLength = MAX_PATH_LENGTH - len(basepath) - len(ext) - 1
return os.path.join(basepath, filename[:remainingLength] + ext)

# From Radarr Radarr/src/NzbDrone.Core/Organizer/FileNameBuilder.cs
def cleanFileName(name):
result = name
Expand Down Expand Up @@ -322,7 +331,7 @@ def print(*values: object):
_print(f"[{torrent.__class__.__name__}] [{torrent.file.fileInfo.filenameWithoutExt}]", *values)

print(f"Failing")

torrentHash = torrent.getHash()
history = await asyncio.to_thread(arr.getHistory, blackhole['historyPageSize'])
items = [item for item in history if (item.torrentInfoHash and item.torrentInfoHash.casefold() == torrentHash.casefold()) or cleanFileName(item.sourceTitle.casefold()) == torrent.file.fileInfo.filenameWithoutExt.casefold()]
Expand All @@ -335,7 +344,7 @@ def print(*values: object):
failTasks = [asyncio.to_thread(arr.failHistoryItem, item.id) for item in items]
await asyncio.gather(*failTasks)
print(f"Failed")

def getFiles(isRadarr):
print('getFiles')
files = (TorrentFileInfo(filename, isRadarr) for filename in os.listdir(getPath(isRadarr)) if filename not in ['processing', 'completed'])
Expand All @@ -353,7 +362,7 @@ async def on_created(isRadarr):

futures: list[asyncio.Future] = []
firstGo = True

# Consider switching to a queue
while firstGo or not all(future.done() for future in futures):
files = getFiles(isRadarr)
Expand Down