Skip to content

Commit

Permalink
extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
varthe committed Dec 22, 2024
1 parent fe77f0b commit 3e85885
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions blackhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ 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}")
#filePathProcessing = os.path.join(baseBath, 'processing', f"{filenameWithoutExt}_{uniqueId}{ext}")
folderPathCompleted = os.path.join(baseBath, 'completed', filenameWithoutExt)

self.fileInfo = self.FileInfo(filename, filenameWithoutExt, filePath, filePathProcessing, folderPathCompleted)
Expand All @@ -72,6 +73,17 @@ 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 @@ -277,15 +289,15 @@ async def is_accessible(path, timeout=10):
executor.shutdown(wait=False)

time.sleep(.1) # Wait before processing the file in case it isn't fully written yet.
try:
os.renames(file.fileInfo.filePath, file.fileInfo.filePathProcessing)
except OSError as e:
if e.errno == 36: # File name too long
print(f"Error handling paths for {file.fileInfo.filenameWithoutExt}. Paths may be too long. Blacklisting.")
os.remove(file.fileInfo.filePath)
await fail(arr=arr, filename=file.fileInfo.filenameWithoutExt)
return False
raise
# try:
os.renames(file.fileInfo.filePath, file.fileInfo.filePathProcessing)
# except OSError as e:
# if e.errno == 36: # File name too long
# print(f"Error handling paths for {file.fileInfo.filenameWithoutExt}. Paths may be too long. Blacklisting.")
# os.remove(file.fileInfo.filePath)
# await fail(arr=arr, filename=file.fileInfo.filenameWithoutExt)
# return False
# raise


with open(file.fileInfo.filePathProcessing, 'rb' if file.torrentInfo.isDotTorrentFile else 'r') as f:
Expand Down

0 comments on commit 3e85885

Please sign in to comment.