Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord Notifications #21

Closed
wants to merge 24 commits into from
Closed

Discord Notifications #21

wants to merge 24 commits into from

Conversation

Pukabyte
Copy link
Contributor

@Pukabyte Pukabyte commented Jul 14, 2024

  • Added RTN to blackhole.py for parsing torrent names
  • Dockerfile.blackhole needs to be changed to at least Python 3.11-slim
  • rank-torrent-name added to requirements.txt
  • Edited discord.py to handle new updates
  • A couple of edits in debrid.py
  • Added better rate limiting in blackhole.py
  • This can now parse whether it's processing a Series or Movie

@@ -83,26 +83,28 @@ def cleanFileName(name):

refreshingTask = None

async def refreshArr(arr: Arr, count=60):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why get rid of this system rather than updating it? This was here so that if you refreshArr on multiple torrents at the same time it doesn't just pile them up but does them all in the same refresh option.

This actually might be broken in that it doesn't take into account which arr we're dealing with, but that can probably be fixed pretty easily.

arr.refreshMonitoredDownloads()
await asyncio.sleep(delay)

def retryRequest(func, retries=3, delay=2, print=print):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a retryRequest system, let's update that and use it here instead?


def copyFiles(file: TorrentFileInfo, folderPathMountTorrent, arr: Arr):
# Consider removing this and always streaming
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably get rid of this whole chunk of code rather than the comment.

if not await torrent.selectFiles():
torrent.delete()
return False
elif status == torrent.STATUS_DOWNLOADING:
await asyncio.sleep(15) # Add a 15-second wait between select file calls
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

@@ -188,14 +218,6 @@ def print(*values: object):
for root, dirs, files in os.walk(folderPathMountTorrent):
relRoot = os.path.relpath(root, folderPathMountTorrent)
for filename in files:
# Check if the file is accessible
# if not await is_accessible(os.path.join(root, filename)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If getting rid of this we should probably get rid of the code it's calling. Alternatively we can try getting the is_accessible code to work.

@@ -254,20 +261,16 @@ async def selectFiles(self):
extraFilesGroup = next((fileGroup for fileGroup in self._instantAvailability if largestMediaFileId in fileGroup.keys()), None)
if self.onlyLargestFile and extraFilesGroup:
self.print('extra files required for cache:', extraFilesGroup)
discordUpdate('Extra files required for cache:', extraFilesGroup)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep this as a separate message because I'm still trying to gauge how often it happens. I don't know of anyone that's actually gotten this message yet.

Comment on lines -260 to -261
if self.onlyLargestFile and len(mediaFiles) > 1:
discordUpdate('largest file:', largestMediaFile['path'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a debugging tool, should we add it as a field in the discord message?

Comment on lines +166 to +169
@property
def instantAvailability(self):
return self._instantAvailability

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a purpose for this and the one in torbox?

@@ -412,7 +423,7 @@ async def getInfo(self, refresh=False):
torrents = infoRequest.json()['data']

for torrent in torrents:
if torrent['id'] == self.id:
if (torrent['id'] == self.id) and ('download_finished' in torrent):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we specifically don't want this.

rate_limit_retry=True,
username='Update Bot'
)
webhook.add_embed(embed)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any need to move this out here instead of inline?

Comment on lines +134 to +135
TAG_ON_SUCCESS=true
TAG_ON_FAILURE=false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start these with DISCORD

Comment on lines +133 to +135
DISCORD_USER_TAG=<your_discord_user_id>
TAG_ON_SUCCESS=true
TAG_ON_FAILURE=false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making these a blackhole property instead of a discord property. Though not really sure where they belong because they currently only apply to blackhole, but should it remain that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it would be cool to have repair added to the discord notifications if we are wanting to do the one big embed?

Comment on lines +133 to +135
DISCORD_USER_TAG=<your_discord_user_id>
TAG_ON_SUCCESS=true
TAG_ON_FAILURE=false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update all the locations that this is applicable, like the readme file. (I usually just ask gpt for a description)

Comment on lines 347 to +352
if realdebrid['enabled']:
torrentConstructors.append(RealDebridTorrent if file.torrentInfo.isDotTorrentFile else RealDebridMagnet)
debrid_provider = "Real-Debrid"
if torbox['enabled']:
torrentConstructors.append(TorboxTorrent if file.torrentInfo.isDotTorrentFile else TorboxMagnet)
debrid_provider = "Torbox"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can both be enabled, so this is probably something we should just pull directly from TorrentBase type

Comment on lines +357 to +360
discord_user = os.getenv('DISCORD_USER_TAG')
discord_user_tag = f"<@{discord_user}>"
tag_on_success = os.getenv('TAG_ON_SUCCESS', 'true').lower() == 'true'
tag_on_failure = os.getenv('TAG_ON_FAILURE', 'true').lower() == 'true'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this in the shared.py file in the same way as all the others.

@@ -2,7 +2,8 @@ environs==9.5.0 #all
discord_webhook==1.3.0 #all
requests==2.28.1 #all
ratelimit #all
rank-torrent-name==0.2.23 #all
rank-torrent-name #all
python-dotenv #all
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already using environs, no need for this.

embed = DiscordEmbed(title=title, description=message, color=color)
embed.set_author(name="Blackhole", icon_url="https://cdn.discordapp.com/attachments/1222893572521594962/1262384669161295934/black-hole-556660.png?ex=669666d7&is=66951557&hm=e792b1162ea86c1ba24ee9f4568c571ff1e3429e5b295555fea3fcb94404b434&")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discordUpdate is also used for other scripts, so we should probably do this more dynamically

@westsurname
Copy link
Owner

@Pukabyte Build is failing for some reason

@Pukabyte Pukabyte closed this Dec 4, 2024
@Pukabyte Pukabyte deleted the discord branch December 4, 2024 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants