Please tell me my superstrict handler script is not necessary

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Please tell me my superstrict handler script is not necessary

Post by cafevincent »

Filebot keeps on giving me the wrong match sometimes, even without using the -non-strict switch. I have built a script years ago that cuts a clip of the video till the first keyframe, and puts it in solitary confinement in "%temp%\generated subdir" to be renamed, so that I can search and find out the new name it wants to give my video beforehand. I then match this new name in a super strict manner against the original filename's "name year" and if that matches exactly it proceeds to really rename the file. If I recall correctly, I was forced to build this script because the undo function wasn't working, but I'm not sure though. I am now rewriting my entire script cluster and this particular script has me a bit baffled, and I must make sure this isn't absolutely crazy before proceeding.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote: 21 Aug 2024, 10:05 Filebot keeps on giving me the wrong match sometimes
:?: Are we talking about movie files or episode files? Please post sample file paths as text so we can have a look and run tests. Please read How to Request Help for details.



cafevincent wrote: 21 Aug 2024, 10:05 I was forced to build this script because the undo function wasn't working, but I'm not sure though.
:?: What exactly is not working? There are no known issues with the filebot -revert feature. It's rather simple, so there's not much that can go awry, as long as you don't delete the history.xml file in the application data folder, forcefully terminate the filebot process before it can store history entries from memory to disk, etc. See Revert files via the internal History for details.
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

you mean sample file paths of mismatched ones? I have not had any of those for years because I've been using this script. it only works for movies, the episode one has not been working since I last asked for your help fixing it, maybe 6 years ago.

I think the issue with revert may had been that the new filename is unknown to the script, so I can't use the feature. Or even check if the renaming was satisfactory.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote: 21 Aug 2024, 10:23 you mean sample file paths of mismatched ones?
Yes, mismatched file paths would be helpful. FileBot works for all use cases known to us, but there surely is an infinite number of rare corner cases were things conceivably go awry. The Name (Year) requirement is for Movie Mode. AFAIK, in Serie Mode the (Year) bit is not strictly required even in Strict Mode because (Year) is extremely uncommon in this category. {tmdb-id} markers are used disambiguate TV Shows with the same name nowadays. That said, if your files already follow a strict naming pattern of some kind, then there may be optimizations that can make FileBot work better for your specific use case.



cafevincent wrote: 21 Aug 2024, 10:23 I think the issue with revert may had been that the new filename is unknown to the script, so I can't use the feature.
FileBot can only revert files that have been moved / renamed with FileBot, i.e. operations recorded in the history.xml file.
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

I think the issue may have been that filebot uses the path in matching, leading to unexpected results. If I recall. Even if I force a --q query it does not force the match. I may have to build a testing script to run though a few hundred files to figure out the current state of this.

Is it possible to get the new filename from filebot without automatically doing the renaming? So that I could force a 100% matching title + year
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote: 21 Aug 2024, 10:44 I think the issue may have been that filebot uses the path in matching, leading to unexpected results. If I recall. Even if I force a --q query it does not force the match. I may have to build a testing script to run though a few hundred files to figure out the current state of this.
--q will force the search query. A query like --q "Doctor Who" will give you multiple search results. A query like --q "Doctor Who (1963)" might work better, but the database may still give you a list of multiple search results. The end result depends largely on the files you have and the context. If the file is identifiable to a human based on the file path alone, then it's generally identifiable to FileBot as well.


:idea: A "query" like --q 00121 would work best of course if you somehow knew the Series ID for each folder / file. See --q manual lookup for details.



cafevincent wrote: 21 Aug 2024, 10:44 Is it possible to get the new filename from filebot without automatically doing the renaming? So that I could force a 100% matching title + year
No, but --filter could certainly be used to limit matching to specific series name / years / ids / etc. See --filter and fine-tuning for details.


:idea: --q and --filter can be used on in combination to express "find Doctor Who; the old one not the new one" like so:

Shell: Select all

--q "Doctor Who" --filter "y < 1970"




EDIT:

:idea: On second thought, a Custom Rename Action could also be used to do / not do / do different things depending on the situation at hand, i.e. have your own shell script perform the "move A to B" operation.
(NOTE: this approach may disable the history / revert feature because filebot does not know what your shell script does)
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote:21 Aug 2024, 19:11 here is one failed rename for movie "The Father (2020)" using

Shell: Select all

--q "The Father" --filter "y < 2020"

Code: Select all

Rename movies using [TheMovieDB]
Looking up movie by query [The Father]
Apply filter [y < 2020] on [29] options
Include [Dragon Ball Z: Bardock - The Father of Goku (1990)]
Include [The Father (2011)]
Include [The Father (2009)]
Include [The Father (1969)]
Include [The Father (2000)]
Include [In the Name of the Father (1993)]
Include [Father of the Bride Part II (1995)]
Include [Father of the Bride (1950)]
Include [Father of the Bride (1991)]
Include [My Father the Hero (1994)]
Include [My Father the Hero (1991)]
Include [The Courtship of Eddie's Father (1963)]
Include [The Godfather (1972)]
Include [The Stepfather (2009)]
Include [The Stepfather (1987)]
Include [The Other (1972)]
Include [The Mother (2003)]
Include [Like Father (2018)]
Include [The Face of Another (1966)]
Include [The Black Godfather (2019)]
[20] options remaining
It gets renamed to "Dragon Ball Z Bardock - The Father of Goku (1990) Mitsuo Hashimoto [Animation, Action, Drama] c13 r78 1080p x265M AAC tt0142245.mkv"

I don't understand. there must be a way to force the query to be an exact query, so that only movies with the full title being "The Father" are accepted. And why didn't the year filter work?

https://www.themoviedb.org/movie/600354-the-father
:!: Your filebot call goes haywire because you explicitly exclude the correct match, forcing filebot to choose from the remainder of incorrect matches. y < 2020 excludes movies from 2020 because 2020 is not smaller than 2020. If you know the year, then you can use y == 2020 to exclude movies from other years. If you know the name, then n == /The Father/ can be used to exclude movies where the movie name is not exactly "The Father".







1.
You forgot to include the file path in your PM so I made something up for testing:

Code: Select all

The Father (2020).mkv

Console Output: Select all

$ filebot -rename "The Father (2020).mkv" --db TheMovieDB --format "{plex.id}" --log INFO
[MOVE] from [The Father (2020).mkv] to [Movies/The Father (2020) {tmdb-600354}/The Father (2020).mkv]





2.
If we assume that you have a file path that is completely random and misleading and thus cannot possibly work:

Code: Select all

FileBot.mkv
e.g.

Shell: Select all

--q "The Father (2020)"

Console Output: Select all

$ filebot -rename "FileBot.mkv" --q "The Father (2020)" --db TheMovieDB --format "{plex.id}" --log INFO
[MOVE] from [FileBot.mkv] to [Movies/The Father (2020) {tmdb-600354}/The Father (2020).mkv]

e.g.

Shell: Select all

--q "The Father"

Console Output: Select all

$ filebot -rename "FileBot.mkv" --q "The Father" --db TheMovieDB --format "{plex.id}" --log INFO
[MOVE] from [FileBot.mkv] to [Movies/The Father (2020) {tmdb-600354}/The Father (2020).mkv]





3.
If we further assume that --q alone somehow doesn't work for some reason. I don't have a test case for that since everything I can think of just works. But whatever the case maybe, if --q gives you a set of movies to choose from, then your --filter does the choosing with your own arbitrary custom code.

e.g.

Shell: Select all

--q "The Father" --filter "n == /The Father/ && y == 2020"

Console Output: Select all

$ filebot -rename "FileBot.mkv" --q "The Father" --filter "n == /The Father/ && y == 2020" --db TheMovieDB --format "{plex.id}"
Rename movies using [TheMovieDB]
Looking up movie by query [The Father]
Apply filter [n == /The Father/ && y == 2020] on [29] options
Include [The Father (2020)]
[1] options remaining
...
[MOVE] from [FileBot.mkv] to [Movies/The Father (2020) {tmdb-600354}/The Father (2020).mkv]
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

OMG I can't believe I've made this huge complex script before learning all this precision filtering! Thank you so much!
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

Cheers! Keep us posted on what you end up with. For the next guy.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote:27 Aug 2024, 08:34 is this how I would filter for S01E01?

Shell: Select all

filebot -rename "%videoFile%" --q "%title%" --filter "n == /%title%/ && y == %year% && e == S01E01" @"%utils%\filebot-s.arg"
also, is it case sensitive or no?
:?: What is the actual command being executed?

:idea: You are using BAT code to generate Groovy code, and you're not using the Format Editor to prototype your code first on top of that for the added challenge.



:arrow: I'd start prototyping in the Format Editor like so:

Screenshot
:!: Looks like you forgot the /.../ or "..." to delimit the String literal. Furthermore, you're using the {e} episode number which is always a Number (e.g. 1) value and never a String (e.g. /S01E01/) value.


Screenshot



:idea: Also, is the == String equals operator case-sensitive? Enter s00e00 == /s01e01/. Says false; Enter s00e00 == /S01E01/. Says true; Confirmed case-sensitive.
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

I can't ever match filename to database with this strict method if the title has a ':' if the database. how to work around this?
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote: 03 Sep 2024, 12:34 I can't ever match filename to database with this strict method if the title has a ':' if the database. how to work around this?
:arrow: Please paste sample file paths as text.


:idea: You would naturally have to change your n == /%title%/ code to account for these kinds of variations. "a:b" and "a b" is not the same, but you could normalize n with your own custom code to better match your own custom file names:

Groovy: Select all

n.colon(' ') == /%title%/

Groovy: Select all

"a:b".colon(' ') == "a b" // true
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

Rename movies using [TheMovieDB]
Looking up movie by query [A Quiet Place Day One]
Apply filter [n == /A Quiet Place Day One/ && y == 2024] on [4] options
Exclude [A Quiet Place: Day One (2024)]
Exclude [A Quiet Place (2018)]
Exclude [A Quiet Place Part II (2021)]
Exclude [A Quiet Place to Kill (1970)]
[0] options remaining
* Consider using --filter "true" to disable your filter if your filter has unexpectedly excluded all potential matches
Failed to find a matching movie: [A Quiet Place: Day One (2024), A Quiet Place (2018), A Quiet Place Part II (2021), A Quiet Place to Kill (1970)]
Failure (×_×)⌒☆
This is what I mean. My script can't possibly know where to put a : for a proper match for such cases. Another one:
Rename movies using [TheMovieDB]
Looking up movie by query [Aries Spears Hollywood Look Im Smiling]
Apply filter [n == /Aries Spears Hollywood Look Im Smiling/ && y == 2011] on [1] options
Exclude [Aries Spears: Hollywood, Look I'm Smiling (2011)]
[0] options remaining
* Consider using --filter "true" to disable your filter if your filter has unexpectedly excluded all potential matches
Failed to find a matching movie: [Aries Spears: Hollywood, Look I'm Smiling (2011)]
Failure (×_×)⌒☆
I wish there was a way to do a strict filtering with /.../ but ignoring any missing special characters.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote: 04 Sep 2024, 11:03 This is what I mean. My script can't possibly know where to put a : for a proper match for such cases.
cafevincent wrote: 04 Sep 2024, 11:03 I wish there was a way to do a strict filtering with /.../ but ignoring any missing special characters.

Please read my previous reply again, bearing in mind that it already gives you the solution you are looking for:
rednoah wrote: 03 Sep 2024, 17:05 :idea: You would naturally have to change your n == /%title%/ code to account for these kinds of variations. "a:b" and "a b" is not the same, but you could normalize n with your own custom code to better match your own custom file names:

Groovy: Select all

n.colon(' ') == /%title%/

Groovy: Select all

"a:b".colon(' ') == "a b" // true

Screenshot
:idea: Please read the FAQ and How to Request Help.
cafevincent
Posts: 61
Joined: 22 Jun 2017, 10:08

Re: Please tell me my superstrict handler script is not necessary

Post by cafevincent »

I'm trying but I don't understand literally anything what you just said, or in the previous message. I can't even begin to form a question about it.

After further consideration you seem to be talking about removing characters from filebot suggestions before they are delivered. so n.colon('') would remove the colon? I assume n.colon(' ') would result in a double space since there usually is a space after a colon. Where do I put this? Inside the filter?

Code: Select all

--filter "n.colon('') == /!title!/
This is very exciting! I will be needing help with removing more than just the colon... anything that cannot exist in a filename must be removed, plus other troublesome characters. First thing I need is to replace " - " with " ". can you give me a reference page on this stuff? what language is this? chatgpt may be able to help if I could tell it what this is.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

colon() already takes care of normalizing surrounding white space as well. You'll want to use the Format Editor to run some tests, e.g. paste "a: b".colon(' ') and see the result.


You are using Groovy:
viewtopic.php?t=10824


But this question is more of a "regular expression" question, i.e. replace certain patterns of text.

e.g. replace all non-space non-word characters:

Groovy: Select all

n.replaceAll(/[^\s\w]/, '')
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 23395
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Please tell me my superstrict handler script is not necessary

Post by rednoah »

cafevincent wrote:06 Sep 2024, 08:15 I don't understand the format editor in the GUI. I enter, for example, "a: b".colon(' ') and I get nothing at all. What is supposed to happen? How is this helpful? I know you're always trying to push me to test everything here, but I don't get it.
The Format Editor allows you to see what the code does, so that you can get instant feedback as you are developing your custom filter expression

e.g. if you don't know what { n.colon(' ') } does then you can run the code and see what it does, and play with different values to see what the code does for different values
e.g. if you compare two values with == you'll want to verify that these two values actually are what you think they are.

Screenshot

:idea: We use literal "A: B" instead of variable n here because we are testing the colon() function to see what it does for different values, and using a literal value makes it easy to just make up lots of different values to check for all the corner cases we might worry about, e.g. the test case marked in green in the screenshot above illustrates how colon() takes care of both the : colon character and the surrounding white space.





EDIT:

:arrow: I've added a new section to the manual to better illustrate best practices for prototyping and testing of custom filter expressions:
rednoah wrote: 27 Oct 2014, 20:54 :idea: You can prototype your custom filter expression with the filebot -list command:

Console Output: Select all

$ filebot -list --q "One Piece" --format "{today} | {n} | {sxe} | {airdate} | {age} | {age < 7}" --filter "{age < 7}"
Apply filter [{age < 7}] on [1151] options
Include [One Piece - 22x1118 - The Holy Land in Tumult! Sai and Leo's Full-Power Blow!]
[1] option remaining
2024-09-11 | One Piece | 22x1118 | 2024-09-08 | 3 | true


:idea: You can prototype and test your custom filter expression in the FileBot Desktop application, either in the Format Editor to test with one item at a time, or in the List Editor to test with multiple items at once:

ScreenshotScreenshot
:idea: Please read the FAQ and How to Request Help.
Post Reply