[Feature Request] Send failed matches to Discord webhook

All your suggestions, requests and ideas for future development
Post Reply
Soitora
Posts: 10
Joined: 17 Nov 2020, 03:13

[Feature Request] Send failed matches to Discord webhook

Post by Soitora »

Hey,

Yesterday I found out that there's a Discord webhook, so I started using it. It's very nice but the main reason I wanted it was because I wanted notifications when it failed to match something. Like yesterday before I looked it up, I saw episode 20 then episode 22 of a series, because I didn't notice (and Plex doesn't tell) that it had missed episode 21.

It would be highly useful to either/or:
  • Include failed matches to Discord webhook messages
  • Optionally only include failed matches to Discord webhook messages so it's even easier to tell
This is how it looks for a successful match:
Image

But it could look like (for failed identification):
Image

Or (idk) for already existing:
Image

Thanks for your time
Maybe I even missed this being an option somewhere
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Feature Request] Send failed matches to Discord webhook

Post by rednoah »

What happens if you add --def unsorted behavior? That'll make sure even unmatched files get processed somewhat, which in turn should make them appear in notifications.
:idea: Please read the FAQ and How to Request Help.
Soitora
Posts: 10
Joined: 17 Nov 2020, 03:13

Re: [Feature Request] Send failed matches to Discord webhook

Post by Soitora »

That works

However I'd still wish if it was possible to just report failed ones, or perhaps in this case, any entry that gets processed as unsorted.
Now I can at least see in the feed which ones fail, but since there's so many every day added that doesn't fail I'd need find a solution to maybe have a Discord bot ping me if it sees any embed with Failed in the title.
Preferably I'd just get the failed entries but it's better than nothing.

Image
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Feature Request] Send failed matches to Discord webhook

Post by rednoah »

You won't be able to get detailed error reporting from the amc script, because it's rename() call internals and there's no interface (other than console output) to report back.


You could do something like this though:
viewtopic.php?t=9801

1. Capture output.
2. Grep information as desired.
3. Curl post to Discord API.
:idea: Please read the FAQ and How to Request Help.
Soitora
Posts: 10
Joined: 17 Nov 2020, 03:13

Re: [Feature Request] Send failed matches to Discord webhook

Post by Soitora »

Alright thanks, I'll maybe look into it in the future.
Detailed isn't important, I just wanna know when/if it fails, or if it becomes Unsorted.

For now, I wrote a very quick discord.py bot that scans the title for "Failed" (which is my Unsorted folder), and it pings me. Not sure about reliability but it's better than nothing for now, would still prefer a native solution.
Another solution (if other ppl read this), I think there's some website you can use as Webhook, then through that you can set When/IF, Filter it, change the style, then send to Discord. But those usually cost
Image

Code: Select all

import os
import discord
from dotenv import load_dotenv

load_dotenv()

UNSORTED_TITLE=os.getenv("UNSORTED_TITLE")
USER_MENTION_ID=os.getenv("USER_MENTION_ID")
BOT_TOKEN=os.getenv("BOT_TOKEN")

client = discord.Client()

@client.event
async def on_ready():
    print("We have logged in as {0.user}".format(client))

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if max([embed.title == UNSORTED_TITLE for embed in message.embeds]):
        await message.channel.send(f"Looks like something failed to match, <@{USER_MENTION_ID}>!")

client.run(BOT_TOKEN)
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: [Feature Request] Send failed matches to Discord webhook

Post by rednoah »

rednoah wrote: 09 Sep 2021, 14:05 1. Capture output.
2. Grep information as desired.
3. Curl post to Discord API.
Here's a bash wrapper for that:
https://github.com/filebot/plugins/blob ... ord-log.sh

e.g.

Code: Select all

send-discord-log.sh filebot -script fn:amc ...


:idea: If you process one file at time, then you can rely on a non-zero exit code if the amc script failed to process that one file, and then send / not send notifications based on that:
https://github.com/filebot/plugins/blob ... log.sh#L34
:idea: Please read the FAQ and How to Request Help.
Soitora
Posts: 10
Joined: 17 Nov 2020, 03:13

Re: [Feature Request] Send failed matches to Discord webhook

Post by Soitora »

rednoah wrote: 10 Sep 2021, 04:39 Here's a bash wrapper for that:

:idea: If you process one file at time, then you can rely on a non-zero exit code if the amc script failed to process that one file, and then send / not send notifications based on that:
https://github.com/filebot/plugins/blob ... log.sh#L34
Thanks 👍
Soitora
Posts: 10
Joined: 17 Nov 2020, 03:13

Re: [Feature Request] Send failed matches to Discord webhook

Post by Soitora »

I made it work kinda hacky on Windows, by using wsl. Kind of amazing that wsl can co-run Linux bash and Windows cmd in the same command.

Had to change line ending on the file so it was LF instead of CRLF though.

This is my qBittorrent execute line on Windows:

Code: Select all

wsl bash /mnt/m/Media/filebot-to-discord.sh filebot @/mnt/m/Media/filebot.conf --def "ut_label=%L" "ut_title=%N" "ut_dir=/mnt/m/Torrents/Plex/%N"
This is an example code run:

Code: Select all

wsl bash /mnt/m/Media/filebot-to-discord.sh filebot @/mnt/m/Media/filebot.conf --def "ut_label=Series" "ut_title=[SubsPlease] Boku no Hero Academia - 111 (1080p) [60B80680].mkv" "ut_dir=/mnt/m/Torrents/Plex/[SubsPlease] Boku no Hero Academia - 111 (1080p) [60B80680].mkv"
I did enable the exit code 0 on line 34, since I only do single file processing through qBittorrent, rest is through the FileBot GUI.

My FileBot AMC configuration you can see me calling in the execution code:

Code: Select all

-script
fn:amc
--log-file
/mnt/m/Media/filebot.log
--output
/mnt/m/Media/
--action
move
--conflict
skip
-non-strict
--apply
date
--filter
(age < 28 || !model.any{ it.age < 28 }) && !lines('''/mnt/m/Media/filebot.exclude''').contains(n)
--def
ignore=Completed
discord=WEBHOOK_URL
plex=127.0.0.1:TOKEN
movieFormat={anime || /Anime/ in genres == true ? 'Anime Films' : 'Movies'}/{ny.replaceAll(/[!?.`"]+/).replace(':','꞉')} [tmdb-{id}]/{fn.matchAll(/\[.+?\]/).first()} {ny.replaceAll(/[!?.`"]+/).replace(':','꞉')} [{vf}, {vc}{audioLanguages.size() > 1 ? ', Dual Audio' : null}]{'.'+lang}
seriesFormat={anime || /Anime/ in genres == true ? 'Anime' : 'Series'}/{n.replaceAll(/[!?.`"]+/).replace(':','꞉')} [tvdb-{id}]{episode.special ? '/Specials' : '/Season ' + s00}/{fn.matchAll(/\[.+?\]/).first()} {n.replaceAll(/[!?.`"]+/).replace(':','꞉')} - {s00}x{e00} [{vf}, {vc}{audioLanguages.size() > 1 ? ', Dual Audio' : null}]{'.'+lang}{' [' + absolute + ']'}
animeFormat=/mnt/m/Torrents/Plex/Failed/{fn.matchAll(/\[.+?\]/).first()} {primaryTitle.replaceAll(/[!?.`"]+/).replace(':','꞉')} - {e00}
Shana Project is set up to RSS download my files to M:/Torrents/Plex/, my Plex files is for example at M:/Media/Anime

I will work on making the embed look nicer personally.

(Image shows two runs, the first is normal one and the second shows it repeated, with the file now already existing.)
Image
Post Reply