getMissingSubtitles() CLI arguments behaviour

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Pat
Posts: 23
Joined: 07 Nov 2014, 15:52

getMissingSubtitles() CLI arguments behaviour

Post by Pat »

This is my simplified groovy script

Code: Select all

// Read format from file
String format = new File('myscript.format').text

// Rename only videos and subtitles
rename(file: args.getFiles{ it.isVideo() || it.isSubtitle() },format: format)

// Get missing subtitles and rename only the new ones
subs=getMissingSubtitles(file: args.getFiles{ it.isVideo() }, lang: 'English')
if (subs) rename(file: subs, format: format)
subs=getMissingSubtitles(file: args.getFiles{ it.isVideo() }, lang: 'Spanish')
if (subs) rename(file: subs, format: format)
1. With filebot -script myscript.groovy -non-strict -unixfs <path>
Missing subtitles are retrieved and renamed correctly.
Renaming videos is missing the DB and trying to guess. I have not intensively tested, so I ignore if it is reliable, probably not.

2. With filebot -script myscript.groovy -non-strict -unixfs --db TheMovieDB<path>
Renaming videos works correctly
Matching subtitles are not found, I do not know why, as if it would have turned to strict mode despite the CLI -no-strict. Adding strict: true to getMissingSubtitles() does not help.

3. Adding --action test to the CLI
Renaming videos does a dry run as expected
Retrieving subtitles ignores it, and does a full run.

Are these bugs or it works as designed?

4. If getMissingSubtitles() would support format, it would spare us some extra renaming
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: getMissingSubtitles() CLI arguments behaviour

Post by rednoah »

-get-subtitles does not use --action thus --action test has no effect

-get-subtitles does use --db so if --db TheMovieDB doesn't match any subtitles DBs (originally you could do --db OpenSubtitles|Sublight|OtherDB when specifying multiple DBs, though now only OpenSubtitles is left)

If you make a script like this it's probably not a good idea to rely on defaults passed in from the cmdlines, instead you should always specify what you want in the call:

Code: Select all

getMissingSubtitles(file: args.getFiles{ it.isVideo() }, lang: 'English', db: 'OpenSubtitles')

Code: Select all

rename(file: subs, format: format, db: 'TheMovieDB')
As long as you don't override the defaults with --db in the cmdline call, you can get away by not specifying it in the script. If you override --db with invalid defaults then you need to override --db again with db: 'name' in the call.
:idea: Please read the FAQ and How to Request Help.
Pat
Posts: 23
Joined: 07 Nov 2014, 15:52

Re: getMissingSubtitles() CLI arguments behaviour

Post by Pat »

Improved it following your suggestions.

Code: Select all

// filebot -script myscript.groovy [--action test] [-non-strict] [-unixfs]  <path>

// Get format from file
String format = new File('myscript.format').text

// Iterate through media folders
args.eachMediaFolder { dir ->

    // Whitelist media types
    def inputV  = dir.listFiles{ it.isVideo() }
    def inputVS = dir.listFiles{ it.isVideo() || it.isSubtitle() }

    // Deduce the right DB
    if (dir.path.find(/\/Movies\//)) db="TheMovieDB"
    else
    if (dir.path.find(/\/Series\//)) db="TheTVDB"
    else
    { println('Nothing found. Exit') ; return }

    // Rename only videos and subtitles
    rename(file: inputVS, format: format, db: db)

    // Retrieve missing subtitles and rename only the new additions
    subLangs=['English', 'Spanish', 'German', 'Russian']
    subLangs.each() {
      subs=getMissingSubtitles(file: inputVS, db: 'OpenSubtitles', lang: it)
      if (subs) rename(file: subs, format: format, db: db)
    }
}                                                                                             2,0-1         Top
1. Now I handle all db's inside the script. I would still like the CLI to override my defaults
How do I detect the --db whaterver?

2. Same for --action test, how may I detect it. I would then simulate a dry run for the getMissingSubtitles

3. Same for --unixfs --lang (I may want less/more languages) and other arguments. Where are they? Which methods do you have available?

4, Now I am iterating through media folders (to detect Movie/Series/etc on single cases from path)
When I retrieve subtitles I get ie:
Get [English] subtitles for 1 files

Before, when I provided geMissingSubtitles with a args.getFiles() with many media folders I would get
Get [English] subtitles for 7 files

Is the later more efficient/less opesubtitles queries or just the same?
Should I rather take the getMissingSubtitles out of the args.eachMediaFolder loop?

And now a BUG?
Running the script on one media folder I get
Get [English] subtitles for 1 files
Looking up subtitles by hash via OpenSubtitles
Looking up subtitles by name via OpenSubtitles
No matching subtitles found: /mnt/Diskstation/video/Movies/Spanish/Esperando La Carroza (1985)/Esperando La Carroza (1985) [480p x264] [2ch AC3] [mp4s.es-en].mp4

However you can find that Movie and many subtitles at their web page search.
(the only difference opensubtitles uses lowercase for the movie name, which is how it works in Spanish. my file is being capitalized by the theMovieDB entry
snapshot4.png
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: getMissingSubtitles() CLI arguments behaviour

Post by rednoah »

1-3.
_args.db and _args.action and _args.lang should give you the values, but _args is read-only. It's all String values so you can interpret it however you want, as long as you pass valid values along to the actual calls.

4.
You can fetch subtitles for each folder, or all files at once. Shouldn't make a difference, but I still recommend fetching subtitles per folder.

5.
The API is not the same as the website. You can debug the request/response with Fiddler and see if it's a bug. On either FileBot doing the wrong search, or OpenSubtitles not returning the right results.
:idea: Please read the FAQ and How to Request Help.
Post Reply