Stacked episode renaming

All your suggestions, requests and ideas for future development
Post Reply
Dyolfknip
Posts: 7
Joined: 30 Dec 2019, 17:01

Stacked episode renaming

Post by Dyolfknip »

I was trying to use the stacked episode hack detailed here: viewtopic.php?t=5240

And it worked great on most of the files I was dealing with. But a few others I kept getting this "Expression yields empty value" error. I'm using 4.8.5.

Code: Select all

filebot -rename -non-strict "paw patrol - all star pups - pups save a sports day.mp4" --format "{episodelist.findAll{ fn =~ it.title }.join(' & ')}" --db thetvdb

Code: Select all

Rename episodes using [TheTVDB]
Auto-detected query: [Paw Patrol]
Fetching episode data for [Paw Patrol]
Expression yields empty value
net.filebot.format.SuppressedThrowables: Expression yields empty value
        at net.filebot.format.ExpressionFormat.format(ExpressionFormat.java:163)
        at net.filebot.format.ExpressionFormat.format(ExpressionFormat.java:129)
        at net.filebot.cli.CmdlineOperations.formatMatches(CmdlineOperations.java:571)
        at net.filebot.cli.CmdlineOperations.renameSeries(CmdlineOperations.java:251)
        at net.filebot.cli.CmdlineOperations.rename(CmdlineOperations.java:97)
        at net.filebot.cli.ArgumentProcessor.runCommand(ArgumentProcessor.java:124)
        at net.filebot.cli.ArgumentProcessor.run(ArgumentProcessor.java:33)
        at net.filebot.Main.main(Main.java:132)

Error (o_O)
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Stacked episode renaming

Post by rednoah »

1.
If the file name matches no episode title:

Code: Select all

fn =~ it.title
Then this will return an empty list:

Code: Select all

episodelist.findAll{ fn =~ it.title }
And then this will return empty string:

Code: Select all

episodelist.findAll{ fn =~ it.title }.join(' & ')
And so you get an error because you're trying to rename a file to nothing.

:!: The linked thread assumes that each file name has an exact corresponding match in the episode titles. This is not necessarily the case in your case.


2.
The first step is to find out:
* What is fn when it doesn't work?
* What are all possible title values? Does any of them match?

Then you will need to adjust the condition accordingly, so that you will select the correct episodes for each file. The condition is up to you, and may vary depending on the exact values of file names / episode titles.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: Stacked episode renaming

Post by kim »

the problem is the 'a' in "Pups Save Sports Day" is wrong:
so remove the 'a'

then you can use this:

Code: Select all

{n}{def fileSet = episodelist.findAll{ fn.lower() =~ it.title.lower().replaceAll(/!/) }; ' - S' + s.pad(2) + 'E' + fileSet.episode.min().pad(2) + '-E' + fileSet.episode.max().pad(2) + ' - ' + fileSet.title.join(' & ') }
output:
Paw Patrol - S03E30-E31 - All Star Pups! & Pups Save Sports Day
OR

Code: Select all

{
def epInfo = episodelist.findAll{ fn.lower() =~ it.title.lower().replaceAll(/!/)}.collect{ [ 'name': it.seriesName, 'ep' : 'S' + it.season.pad(2) + 'E' + it.episode.pad(2), title: it.title ] }
epInfo.name[0] + ' - ' + epInfo.ep.join(' & ') + ' - ' + epInfo.title.join(' & ')
}
output:
Paw Patrol - S03E30 & S03E31 - All Star Pups! & Pups Save Sports Day
https://thetvdb.com/series/paw-patrol/episodes/5720764
https://thetvdb.com/series/paw-patrol/episodes/5631547
Dyolfknip
Posts: 7
Joined: 30 Dec 2019, 17:01

Re: Stacked episode renaming

Post by Dyolfknip »

kim wrote: 30 Dec 2019, 19:55 the problem is the 'a' in "Pups Save Sports Day" is wrong:
so remove the 'a'
Yeah, I actually tried that one already. It failed for me both ways when stacked, and worked both ways when run by itself. And in any event, I have 15 others with the same problem. Don't think they're all typos.
Dyolfknip
Posts: 7
Joined: 30 Dec 2019, 17:01

Re: Stacked episode renaming

Post by Dyolfknip »

rednoah wrote: 30 Dec 2019, 19:23 If the file name matches no episode title:
Problem is, it still says the same thing even if I pare the filename down to just one episode, which it then proceeds to match correctly anyway.

"paw patrol - all star pups!" => "[Expression yields empty value] Paw Patrol - 3x30 - All Star Pups!"
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Stacked episode renaming

Post by rednoah »

Note that formatting is completely unrelated to matching. In this case, 3x30 got matched, but fn =~ it.title is still false for each item in episodelist so the format fails. This particular format thoroughly ignores the episode match, and the only thing that has an effect on format is the file part of the match.

:idea: Here's a test for fn =~ it.title and it yields false:

Code: Select all

{(/all star pups!/ =~ /All Star Pups!/) as boolean}
:idea: We'll want to match things regardless of case and punctuation, so we try this, and voilà, it yields true:

Code: Select all

{(/all star pups!/.lower().normalizePunctuation() =~ /All Star Pups!/.lower().normalizePunctuation()) as boolean}


:arrow: Looking at what we have learnt, this condition should work better:

Code: Select all

fn.lower().normalizePunctuation() =~ it.title.lower().normalizePunctuation()
:idea: Please read the FAQ and How to Request Help.
Dyolfknip
Posts: 7
Joined: 30 Dec 2019, 17:01

Re: Stacked episode renaming

Post by Dyolfknip »

rednoah wrote: 30 Dec 2019, 19:23 :!: The linked thread assumes that each file name has an exact corresponding match in the episode titles. This is not necessarily the case in your case.
Ah, I figured it out. "Exact quote" in this case means case-sensitive as well. I had taken the =~ in the original script to mean that it would accept fuzzy matches. Evidently not.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Stacked episode renaming

Post by rednoah »

I see. Yeah, in this case, if the left-hand side is a String, then =~ assumes the right-hand side is a regex pattern, so stripping punctuation is probably a good idea just to get rid of potential regex constructs:
http://docs.groovy-lang.org/latest/html ... d_operator
:idea: Please read the FAQ and How to Request Help.
Dyolfknip
Posts: 7
Joined: 30 Dec 2019, 17:01

Re: Stacked episode renaming

Post by Dyolfknip »

Ah, thanks for the docs. Time to learn another scripting language, I guess.
User avatar
rednoah
The Source
Posts: 22998
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Stacked episode renaming

Post by rednoah »

Dyolfknip wrote: 31 Dec 2019, 02:06 Ah, thanks for the docs. Time to learn another scripting language, I guess.
FileBot will certainly reward you for learning some Groovy fu. :lol:
:idea: Please read the FAQ and How to Request Help.
Post Reply