AMC: Pushover Custom Message Format?

All about user-defined episode / movie / file name format expressions
Post Reply
Wirly
Posts: 14
Joined: 10 Aug 2020, 01:08

AMC: Pushover Custom Message Format?

Post by Wirly »

Hello,

I've got AMC setup to send a Pushover notification when it completes a job. It works fine, however the default of only sending the original filename isn't too useful to me. I'd like to also see the output filename, so that if it doesn't show up during my next scan, I can see what the bad match was without it getting lost in the logs.

Is there a way to change the format of the Pushover message?

Something like...

Code: Select all

{f.name} --> {f.outname}
The.Lorax.1972.1080p.BluRay.mkv  -->  The Lorax (1972).mkv
I know PushBullet notifications will send a file with a table of the name changes, however I'm not using it since the app doesn't let me sign in without adding another email to my phone, which I rather not do.
User avatar
rednoah
The Source
Posts: 24281
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC: Pushover Custom Message Format?

Post by rednoah »

:arrow: You can make a Custom Post-Processing Script for your needs. The Notify via Pushover example will get you started.
:idea: Please read the FAQ and How to Request Help.
Wirly
Posts: 14
Joined: 10 Aug 2020, 01:08

Re: AMC: Pushover Custom Message Format?

Post by Wirly »

Thanks for the link, I was having issues but then noticed I was still using 5.1.7.

I upgraded to 5.2.0 and it's working great!

Is there any documentation for the available properties of model, $source, $target, $metadata?
User avatar
rednoah
The Source
Posts: 24281
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC: Pushover Custom Message Format?

Post by rednoah »

:idea: model allows you to access all bindings for all matches.

:idea: The File source, File target, Object metadata trio are the parameters you get when using a closure the iterates over the model. In the context of such a closure, all bindings are also available.

:arrow: The Hello World can serve as an example. The general idea is that it's just custom format bindings and works much the same.
:idea: Please read the FAQ and How to Request Help.
Wirly
Posts: 14
Joined: 10 Aug 2020, 01:08

Re: AMC: Pushover Custom Message Format?

Post by Wirly »

Awesome, I kept trying to do things like "$target.resolution" and wasn't having any luck.

I learned a bit of Groove syntax and managed to put together a Pushover notification that has more of the info I'm looking for. Thanks a bunch! :D

Screenshot

Groovy: Select all

submit 'https://api.pushover.net/1/messages.json', [
    token: 'appToken123',
    user: 'userKey123',
    html: 1,
    title: "FileBot: ${model.size()} file(s) processed",
    message: model.each{ source, target, metadata -> 

        if( $type == 'Movie') {
            "🎬 <b><a href='https://www.themoviedb.org/movie/$metadata.id'>${target.name.replaceFirst(/\.\w{3,4}$/, "")}</a></b>\n  <i>β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours\n$source.name</i>"
        } else if( $type == 'Episode') {
            "πŸ“Ί <b><a href='https://www.themoviedb.org/tv/$metadata.id'>${target.name.replaceFirst(/\.\w{3,4}$/, "")}</a></b>\n  <i>β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours\n$source.name</i>"
        } else {
            "πŸ”Ž $source.name βž” $target.name"
        }

    }.join('\n\n')
]
User avatar
rednoah
The Source
Posts: 24281
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC: Pushover Custom Message Format?

Post by rednoah »

Very nice! I'm happy to see users expand upon the examples and make new things. I've updated the Notify via Pushover example with my take on your ideas.
:idea: Please read the FAQ and How to Request Help.
Wirly
Posts: 14
Joined: 10 Aug 2020, 01:08

Re: AMC: Pushover Custom Message Format?

Post by Wirly »

Whoo, glad to have contributed! :D

I didn't realize that Pushover has a 1024 character limit for messages :cry: I added a bit more logic to get more out of that limitation.

Unfortunately, it's still not likely to fit a whole series at once, but it's a lot better than only fitting ~4 items into a single message as with the previous script.

1 Movie Renamed...
Screenshot

>5 Episodes Renamed...
Screenshot

Posting it here for anyone who might find it useful...

Groovy: Select all

// Send a PushOver notification, formatted to get more out of the 1024 character limit for messages...

if (model.size() == 1 && model[0].type == 'Movie') {
    // A single movie...

    pushMessage = model.each{ source, target, metadata -> 
        def genreType = 'Anime' in genres ? 'Anime' : 'Animation' in genres ? 'Animated' : 'Live-Action'

        "🎬 <b><a href='https://www.themoviedb.org/movie/$id'>$target.nameWithoutExtension</a>\nβ˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>\n\n<b><i>${metadata.info.tagline}</i></b>\n\n${metadata.info.overview}"
    }.join('')

} else if (model.size() > 5 && model[0].type == 'Episode') {
    // Probably a batch of episodes...
    def firstItem = model[0]
    def genreType = 'Anime' in firstItem.genres ? 'Anime' : 'Animation' in firstItem.genres ? 'Animated' : 'Live-Action'

    pushMessage = "πŸ“Ί <b><a href='https://www.themoviedb.org/tv/${firstItem.id}'>${firstItem.ny}</a>\nβ˜† ${firstItem.rating} β€’ ${firstItem.vf} β€’ ${firstItem.acf} β€’ ${genreType}</b>\n\n<i>"
    pushMessage = pushMessage + model.each{ source, target, metadata ->
        "$source.name βž” $target.nameWithoutExtension"
    }.join('\n\n') + '</i>'

} else {
    // Probably a mix of movie(s) and/or episode(s)...

    system 'curl', '--output', '.\\pushoverImage.jpg', "${model[0].info.Poster}"

    pushMessage = model.each{ source, target, metadata -> 

            def genreType = 'Anime' in genres ? 'Anime' : 'Animation' in genres ? 'Animated' : 'Live-Action'

            if( $type == 'Movie') {
                "🎬 <b><a href='https://www.themoviedb.org/movie/$id'>$target.nameWithoutExtension</a>\nβ˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>"
            } else if( $type == 'Episode') {
                "πŸ“Ί <b><a href='https://www.themoviedb.org/tv/$id'>$target.nameWithoutExtension</a>\n$ny\nβ˜† $metadata.info.rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>"
            } else {
                "πŸ”Ž $source.name βž” $target.name\n$target.path"
            }
        }.join('\n\n')

}

// Pushover Notification
submit 'https://api.pushover.net/1/messages.json', [
    token: 'appToken123',
    user: 'userToken123',
    html: 1,
    attachment: ".\\pushoverImage.jpg",
    title: "FileBot: ${model.size()} file(s) processed",
    message: pushMessage
]
----------------------------------------------

Pushover allows attaching an image file when sending a message, which I thought would be great when only a single movie/series was renamed.

I spent some time trying to figure out how to do this through Groovy with the provided info.Poster url.

Using curl to download the file worked fine, but I couldn't figure out how to send it through the submit function. Any tips? :?:

Code: Select all

system 'curl', '--output', ".\\pushoverImage.jpg", "${model[0].info.Poster}"
P.S
It'd be great if the forums allowed for in-line code formatting, like in Discord when surrounding text with single backticks (`). So things like [c]$info.Poster[/c] would show up formatted and apparent as a snippet, without having to use a whole code block.

I've seen this function in other forums and it's great for distinguishing code in conversation.
User avatar
rednoah
The Source
Posts: 24281
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC: Pushover Custom Message Format?

Post by rednoah »

You could try something like this:

Groovy: Select all

def APPLICATION_TOKEN = '<YOUR APPLICATION TOKEN>';
def USER_KEY = '<YOUR USER KEY>';

{ source, target, metadata ->
	if (type =~ /Episode/) {
		submit 'https://api.pushover.net/1/messages.json', [
			token: APPLICATION_TOKEN, user: USER_KEY,
			title: 'πŸ“Ί ' + target.nameWithoutExtension,
			url: "https://www.themoviedb.org/tv/$id/season/$s/episode/$e", url_title: "Open Episode in TheMovieDB",
			attachment_base64: episode.info.image.bytes.encodeBase64(), attachment_type: 'image/jpeg',
			html: 1, message: XML{
				span("β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours")
				code(source.name)
			}
		]
	}
	if (type =~ /Movie/) {
		submit 'https://api.pushover.net/1/messages.json', [
			token: APPLICATION_TOKEN, user: USER_KEY,
			title: '🎬 ' + target.nameWithoutExtension,
			url: "https://www.themoviedb.org/movie/$id", url_title: "Open Movie in TheMovieDB",
			attachment_base64: info.poster.bytes.encodeBase64(), attachment_type: 'image/jpeg',
			html: 1, message: XML{
				p("β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours")
				code(source.name)
			}
		]
	}
}

:arrow: https://pushover.net/api#attachments-base64
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 24281
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: AMC: Pushover Custom Message Format?

Post by rednoah »

FileBot r10850 adds additional extension methods to take care of image caching / scaling / conversion because posting 2000x3000 images to the API is probably a bit much:

Groovy: Select all

def APPLICATION_TOKEN = '<YOUR APPLICATION TOKEN>';
def USER_KEY = '<YOUR USER KEY>';

{ source, target, metadata ->
	if (type =~ /Episode/) {
		submit 'https://api.pushover.net/1/messages.json', [
			token: APPLICATION_TOKEN, user: USER_KEY,
			title: 'πŸ“Ί ' + target.nameWithoutExtension,
			url: "https://www.themoviedb.org/tv/$id/season/$s/episode/$e", url_title: "Open Episode in TheMovieDB",
			attachment_base64: episode.info.image.getImage().scale(480, 270).encode('jpeg').base64(), attachment_type: 'image/jpeg',
			html: 1, message: XML{
				span("β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours")
				code(source.name)
			}
		]
	}
	if (type =~ /Movie/) {
		submit 'https://api.pushover.net/1/messages.json', [
			token: APPLICATION_TOKEN, user: USER_KEY,
			title: '🎬 ' + target.nameWithoutExtension,
			url: "https://www.themoviedb.org/movie/$id", url_title: "Open Movie in TheMovieDB",
			attachment_base64: info.poster.getImage().scale(400, 600).encode('jpeg').base64(), attachment_type: 'image/jpeg',
			html: 1, message: XML{
				p("β˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ $hours")
				code(source.name)
			}
		]
	}
}
:idea: Please read the FAQ and How to Request Help.
Wirly
Posts: 14
Joined: 10 Aug 2020, 01:08

Re: AMC: Pushover Custom Message Format?

Post by Wirly »

Fantastic, your first solution worked great!!

You're right, such large images are excessive, so I'll try to remember to patch in the new methods on the next FileBot update. According to the docs, Pushover deletes messages as soon as they're delivered, so at-least they're not taking up server space πŸ‘

Aside from the posters, I went ahead and added a bit more logic to my script to take into account the renaming of only 1 episode...

ScreenshotScreenshot

With that I think I'm all set, this has been a fun little script to work on, I'm gonna see what else I have that I can use Pushover for :D

Here's my final* script for anyone to reference or make use of. Thanks again for the help Noah! πŸ™

Groovy: Select all

// Send a PushOver notification, formatted to get more out of the 1024 character limit imposed on messages...

if (model.size() == 1 && model[0].type == 'Movie') {
    // A single movie was processed...
    
    pushUrl = "https://passthepopcorn.me/torrents.php?action=advanced&searchstr=${model[0].imdbid}"
    pushUrlTitle = "PassThePopcorn"
    pushAttachment64 = model[0].info.poster.bytes.encodeBase64()
    pushTitle = "FileBot"

    pushMessage = model.each{ source, target, metadata -> 

        def genreType = 'Anime' in genres ? 'Anime' : 'Animation' in genres ? 'Animated' : 'Live-Action'
        "🎬 <b><a href='https://www.themoviedb.org/movie/$id'>$ny</a>\nβ˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>\n\n<b><i>${metadata.info.tagline}</i></b>\n\n${metadata.info.overview}\n"
    }.join('')

} else if (model.size() == 1 && model[0].type == 'Episode') {
    // A single episode was processed...

    pushUrl = "https://broadcasthe.net/torrents.php?action=advanced&imdb=${model[0].imdbid}"
    pushUrlTitle = "BroadcasTheNet"
    pushTitle = "FileBot"

    pushMessage = model.each{ source, target, metadata -> 
        pushAttachment64 = metadata.info.image.bytes.encodeBase64()

        def genreType = 'Anime' in genres ? 'Anime' : 'Animation' in genres ? 'Animated' : 'Live-Action'
        "πŸ“Ί <b>$target.nameWithoutExtension\n<a href='https://www.themoviedb.org/tv/$id'>$ny</a>\nβ˜† $metadata.info.rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>\n\n${metadata.info.overview}\n"
    }.join('')

} else if (model.size() > 4 && model[0].type == 'Episode') {
    // Probably a batch of episodes being processed...

    def firstItem = model[0]
    def genreType = 'Anime' in firstItem.genres ? 'Anime' : 'Animation' in firstItem.genres ? 'Animated' : 'Live-Action'

    pushUrl = "https://broadcasthe.net/torrents.php?action=advanced&imdb=${model[0].imdbid}"
    pushUrlTitle = "BroadcasTheNet"
    pushAttachment64 = model[0].info.poster.bytes.encodeBase64()
    pushTitle = "FileBot: ${model.size()} Episodes Processed"

    pushMessage = "πŸ“Ί <b><a href='https://www.themoviedb.org/tv/${firstItem.id}'>${firstItem.ny}</a>\nβ˜† ${firstItem.rating} β€’ ${firstItem.vf} β€’ ${firstItem.acf} β€’ ${genreType}</b>\n\n<i>"
    pushMessage = pushMessage + model.each{ source, target, metadata ->
        "<b>$target.nameWithoutExtension</b>\n$source.name"
    }.join('\n\n') + '</i>'

} else {
    // Probably a mix of movies and/or episodes...

    pushUrl = ""
    pushUrlTitle = ""
    pushAttachment64 = model[0].info.poster.bytes.encodeBase64()
    pushTitle = "FileBot: ${model.size()} Files Processed"

    pushMessage = model.each{ source, target, metadata -> 

            def genreType = 'Anime' in genres ? 'Anime' : 'Animation' in genres ? 'Animated' : 'Live-Action'

            if( $type == 'Movie') {
                "🎬 <b><a href='https://www.themoviedb.org/movie/$id'>$target.nameWithoutExtension</a>\nβ˜† $rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>"
            } else if( $type == 'Episode') {
                "πŸ“Ί <b>$target.nameWithoutExtension\n<a href='https://www.themoviedb.org/tv/$id'>$ny</a>\nβ˜† $metadata.info.rating β€’ $vf β€’ $acf β€’ $bytes β€’ ${genreType}</b>\n<i>$source.name</i>"
            } else {
                "πŸ”Ž $source.name βž” $target.name\n$target.path"
            }
        }.join('\n\n')

}

// Pushover Notification
submit 'https://api.pushover.net/1/messages.json', [
    token: 'appToken123',
    user: 'userKey123',
    url: pushUrl,
    url_title: pushUrlTitle,
    attachment_base64: pushAttachment64,
    attachment_type: 'image/jpeg',
    html: 1,
    title: pushTitle,
    message: pushMessage
]
Post Reply