Localized name from TheTVDB based on audio language?

All about user-defined episode / movie format expressions
Post Reply
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Localized name from TheTVDB based on audio language?

Post by abandonow »

Hi,

I can't for the life of me get this to work. I have a much more complex naming scheme, but let's focus just on the name for now.
I'm currently just testing in the GUI version. Filebot is set to default to English.

i.e running this code:

Code: Select all

{audio.language =~ /no/ ? localize.no.n : n}
on this file:

Code: Select all

Peppa.Gris.S01E01.720p.WEB-DL.x264.mkv
still gives me the english name, instead of the norwegian one.

I have verified that the file only has one audiotrack and is tagged with the language.

Code: Select all

 mediainfo /Volumes/test/filebot/testmedia/series/Peppa.Gris.S01E01.720p.WEB-DL.x264.mkv
General
Unique ID                                : 246321013262533871862882142241173804579 (0xB94FB397F4B138D746156BBCC8A01623)
Complete name                            : /Volumes/test/filebot/testmedia/series/Peppa.Gris.S01E01.720p.WEB-DL.x264.mkv
Format                                   : Matroska
Format version                           : Version 4
File size                                : 66.0 MiB
Duration                                 : 10 min 36 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 870 kb/s
Writing application                      : Lavf57.55.100
Writing library                          : Lavf57.55.100
ErrorDetectionType                       : Per level 1

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 4 frames
Codec ID                                 : V_MPEG4/ISO/AVC
Duration                                 : 10 min 36 s
Bit rate                                 : 741 kb/s
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.032
Stream size                              : 56.2 MiB (85%)
Writing library                          : x264 core 148 r2721 72d53ab
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=23.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
Language                                 : Norwegian
Default                                  : Yes
Forced                                   : No

Audio
ID                                       : 2
Format                                   : Vorbis
Format settings, Floor                   : 1
Codec ID                                 : A_VORBIS
Duration                                 : 10 min 36 s
Bit rate mode                            : Variable
Bit rate                                 : 112 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -83 ms
Stream size                              : 8.49 MiB (13%)
Writing application                      : Lavc57.63.103
Writing library                          : libVorbis (⛄⛄⛄⛄) (20150105 (⛄⛄⛄⛄))
Language                                 : Norwegian
Default                                  : Yes
Forced                                   : No

Text
ID                                       : 3
Format                                   : UTF-8
Codec ID                                 : S_TEXT/UTF8
Codec ID/Info                            : UTF-8 Plain Text
Duration                                 : 10 min 18 s
Language                                 : Norwegian
Default                                  : No
Forced                                   : No

Link to The TVDB show page: https://thetvdb.com/series/peppa-pig
kim
Power User
Posts: 1049
Joined: 15 May 2014, 16:17

Re: Localized name from TheTVDB based on audio language?

Post by kim »

Code: Select all

{localize.no.JSON}

Code: Select all

{"@type":"Episode","seriesName":"Peppa Pig","season":1,"episode":1,"title":"Muddy Puddles","airdate":{"year":2004,"month":5,"day":31},"id":305989,"seriesInfo":{"database":"TheTVDB","order":"Airdate","language":"no","type":"TV Series","id":79222,"name":"Peppa Pig","aliasNames":[],"certification":"TV-G","startDate":{"year":2004,"month":3,"day":16},"genres":["Animation","Children"],"network":"Channel 5 (UK)","rating":8.5,"ratingCount":749,"runtime":5,"status":"Continuing"}}
= looks like problem at thetvdb

maybe because of "Norsk bokmål" (nb) vs "Norsk" (no) ?

EDIT:
https://forums.thetvdb.com/viewtopic.ph ... 3&start=10

using "nb"

Code: Select all

{
  "data": [
    {
      "aliases": [
        "小猪佩奇"
      ],
      "banner": "/banners/graphical/79222-g6.jpg",
      "firstAired": "2004-3-16",
      "id": 79222,
      "image": "/banners/posters/79222-2.jpg",
      "network": "Channel 5 (UK)",
      "overview": "Peppa er en søt liten gris som bor sammen med sin lillebror Georg, mamma Gris og pappa Gris. Peppa elsker å leke, kle seg ut, besøke spennende steder og å få nye venner, men den absolutte yndlingsbeskjeftigelsen er å hoppe rundt i søle!",
      "poster": "/banners/posters/79222-2.jpg",
      "seriesName": "Peppa Gris",
      "slug": "peppa-pig",
      "status": "Continuing"
    },
    {
      "aliases": [],
      "banner": "/banners/graphical/235441-g.jpg",
      "firstAired": "2010-3-31",
      "id": 235441,
      "image": "/banners/posters/235441-1.jpg",
      "network": "Nick Jr.",
      "poster": "/banners/posters/235441-1.jpg",
      "seriesName": "Pepper Pig",
      "slug": "pepper-pig-duplicate-of-79222",
      "status": "Ended"
    }
  ]
}
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Appreciate the research!

So it's a bug raised in april, and still not fixed.

Is there any way to tell filebot to first check "no", and if no hit, then check "nb"?

This is my current audio/language code where I took into account that the audio actually could be tagged with "nn" (norwegian nynorsk) or "nb" (norwegian bokmål).

Code: Select all

    def a = audio[0].language
    (a = a.replace('nn':'no', 'nb':'no'))
    (a =~ (/no|da|sv/) ? localize[a].plex : plex)
(EDIT: Testing to get data with hardcoded "nb", does not seem to work)
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

Well, FileBot has a lookup table for supported locales, so you can use any no | nor | no-NO | Norwegian to refer to this particular locale. That'll make everything work seamlessly regardless of how you refer to the locale, but also makes it impossible to pass through arbitrary language codes.


:?: We could make nb an alias of no, but that would just result in nb | Norwegian Bokmål defaulting to no (whichever locale that code may refer to on the TheTVDB server-side) and perhaps not be particularly useful for this particular use case.


:?: We could make any Norwegian lookup use language code nb for TheTVDB requests, but that would break all the use cases that currently work with no as language code (assuming of course that no is actually working which we are unable to test ourselves).


:!: However, a complex tree structure of language families and defaults is unfortunately not supported nor planned as far as FileBot is concerned.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1049
Joined: 15 May 2014, 16:17

Re: Localized name from TheTVDB based on audio language?

Post by kim »

use themoviedb, it has no, nb and nn support and if no "no" info but has "nb" then that info is used with "no"
https://www.themoviedb.org/tv/12225-peppa-pig

just add the missing info ;)

or

Code: Select all

{filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale ('nb')).find{it.season == s && it.episode == e}}

Code: Select all

{filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale ('nb')).find{it.season == s && it.episode == e}.seriesInfo.name}

Code: Select all

{filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale ('nb')).find{it.season == s && it.episode == e}.title}
PS: add

Code: Select all

net.
to front ... cant post it gives me
Internal Server Error
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

kim wrote: 07 Oct 2020, 21:43 add

Code: Select all

net.
to front ... cant post it gives me
Internal Server Error
Sorry about that. Hosting provider uses a rather strict WAF rules since a few weeks ago, which tend to block code-like posts. Unfortunately, I can't fine-tune that myself, and turning it off is not a good idea either because phpBB probably has security bugs. Best to use Gist or Pastebin for code sharing in the meanwhile.
:idea: Please read the FAQ and How to Request Help.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks @kim!

I prefer to use thetvdb since it seems to have the most correct date. Your first example works fine when testing, but I'm having a hard time incorporating it into my script.

Code: Select all

    def a = audio[0].language
    (a = a.replace('nn':'no', 'nb':'no'))
    (a =~ (/no|da|sv/) ? localize[a].plex : plex)
I changed it to:

Code: Select all

def a = audio[0].language
    (a = a.replace('nn':'nb', 'no':'nb'))
    (a =~ (/no|da|sv/) ? {n e t.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a).find{it.season == s && it.episode == e}} : plex)
- Changed the a.replace part to force all possibilities to "nb" (since as far as I understand thetvdb only works on norwegian with the "nb".
- Changed the "nb" hardcoded bit with the variable "a"

Unfortunately it does not work. Not sure why. The files that does not contain "no, da, sv" works fine (i.e uses the "plex" part).

Do you see any obvious errors?
kim
Power User
Posts: 1049
Joined: 15 May 2014, 16:17

Re: Localized name from TheTVDB based on audio language?

Post by kim »

Code: Select all

{    def a = 'no'
    a = a.replace('nn':'nb', 'no':'nb')
    a =~ /nb|da|sv/ ? net.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{it.season == s && it.episode == e} : kodi.name
}
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks for your help!

I sort get it to work if I copy your code alone, but it no longer catches "Specials" (ie. "Peppa.Pig.S00E01.special.1080p.Web.x265.10bit.mkv"), and trying to incorporate it in my exisiting setup also breaks it. And I can't seem to figure out why.

This is my current script, that I can't seem to understand why won't work.

Code: Select all

series/{
    def a = audio[0].language
    (a = a.replace('nn':'nb', 'no':'nb'))
    (a =~ /nb|da|sv/ ? net.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{it.season == s && it.episode == e} : plex)
    .derive
    {" " + tags}
    {" " + [fn.match(/(?i)nordic|norwegian|danish|swedish/).upper()]} 
    {" " + [allOf
        {allOf
            {vf}
            {hdr}
            .join(" ")
        }
        {source}
        {allOf
            {ac}
            {channels}
            .join(" ")
        }
        {allOf
            {vc}
            {if (bitdepth == 10)"10bit"}
            .join(" ")
        }
        .join(" - ")]
  }
  .tail
}
All that contains "no" audio, just gets the path "/series/" and I get this error message in the Filebot GUI:
https://pastebin.com/XS6P76x5

(Using pastebin, because "Internal error" when posting.)

(Ideally I think the most logical thing would be to read "Norwegian", "Danish", "Swedish" in the file name, and pull the correct language based on that. I think that possibly could be more precise. And then if nothing is specified – check the audio language and pull the data based on that instead.)
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

The File.derive() method can’t be used on on Episode objects, i.e. only works on the plex object.
:idea: Please read the FAQ and How to Request Help.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Ok, that explains that issue.

Do you have any advice on how to solve the issue using a plex object (ie. "localize[a].plex")? Trying to use "nb" on "localize[a].plex" gives "Binding "nb": undefined"
We could make any Norwegian lookup use language code nb for TheTVDB requests, but that would break all the use cases that currently work with no as language code
Maybe it's possible to implement ^^, at least until TheTVDB fixes their issue. Or make a flag or something that lets you choose.
kim
Power User
Posts: 1049
Joined: 15 May 2014, 16:17

Re: Localized name from TheTVDB based on audio language?

Post by kim »

Code: Select all

{    def a = 'no'
    a = a.replace('nn':'nb', 'no':'nb')
    a =~ /nb|da|sv/ ? net.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{ it =~ sxe || it =~ it.special} : kodi.name
}
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks for fixing the "special" part, but I'm having a hard time incorporating it in my script. I tried to remove the derive part, but get

Code: Select all

Suppressed: No signature of method: net.filebot.web.Episode.call() is applicable for argument types: (Script95$_run_closure2, Script95$_run_closure3, Script95$_run_closure4) values: [[email protected], [email protected], ...]
Possible solutions: wait(), any(), clone(), collect(), grep(), dump()

Code: Select all

series/{
    def a = audio[0].language
    (a = a.replace('nn':'nb', 'no':'nb'))
    (a =~ /nb|da|sv/ ? net.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{ it =~ sxe || it =~ it.special} : kodi.name)
    {" " + tags}
    {" " + [fn.match(/(?i)nordic|norwegian|danish|swedish/).upper()]} 
    {" " + [allOf
        {allOf
            {vf}
            {hdr}
            .join(" ")
        }
        {source}
        {allOf
            {ac}
            {channels}
            .join(" ")
        }
        {allOf
            {vc}
            {if (bitdepth == 10)"10bit"}
            .join(" ")
        }
        .join(" - ")]
  }
  .tail
}
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

plex.derive{1}{2}{3} works because File.derive(Closure...) exists.

i.e.

Code: Select all

plex.derive{1}{2}{3}
is the same as

Code: Select all

plex.derive({1}, {2}, {3})


:arrow: You'll want add your custom information the normal way, instead of injecting it via File.derive(Closure...) like so:

Code: Select all

{plex.name}
{" " + tags}
...
:idea: Note that by not using File.derive(Closure...) to inject information, we just append it at the end, which may cause naming issues with multi-part movies and subtitle files. You may want to avoid relying on {plex} altogether for your particular custom format because simplicity comes with limitations.
:idea: Please read the FAQ and How to Request Help.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks, but isn't that what I've done in the code above? Except I get the error?
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

You have a 1 single expression:

Code: Select all

{episode{" " + tags}}
which is Groovy syntactic sugar equivalent to this, which explains the error message:

Code: Select all

{episode.call({" " + tags})}


The above (i.e. Groovy code that just so happens to use {...} inside a single expression) is not to be confused with having 2 separate expressions:

Code: Select all

{episode}{" " + tags}


:arrow: viewtopic.php?t=1895
:idea: Please read the FAQ and How to Request Help.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks, got it. It's starting to become a bit complex for my understanding, but I'm trying. Appreciate all the help! :)

I still have two more issues with my script:

1. The episode listing is 1x01 (sxe) instead of the plex way of S01E01.
I tried changing the "sxe" to "s00e00", but that did not work.

2. How do I add the standard plex folder scheme to the localized part?
I've tried multiple things, but not anything that works as of yet.

This is my current script (that works except the two issues above):

Code: Select all

series/{
    def a = audio[0].language
    (a = a.replace('nn':'nb', 'no':'nb'))
    (a =~ /nb|da|sv/ ? net.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{ it =~ sxe || it =~ it.special} : plex)}
    {" " + tags}
    {" " + [fn.match(/(?i)nordic|norwegian|danish|swedish/).upper()]} 
    {" " + [allOf
        {allOf
            {vf}
            {hdr}
            .join(" ")
        }
        {source}
        {allOf
            {ac}
            {channels}
            .join(" ")
        }
        {allOf
            {vc}
            {if (bitdepth == 10)"10bit"}
            .join(" ")
        }
        .join(" - ")]
  }
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

1.
Your accessing Episode objects directly, i.e. the type of object {episode} gives you. The default String representation of Episode objects just so happens to use 1x01 formatting. {s00e00} is a binding that the format engine provides based on the matched Episode object. Similarly, {plex} remains unaffected by any Episode objects you may or may not be creating in your own custom code.


2.
You can't. I guess you could separate the file name part {plex.name} and the folder path part {plex.dir}, but that this point it's probably more advisable to build up the entire path with your own custom code with more simple elements step by step.
:idea: Please read the FAQ and How to Request Help.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Thanks for the explanation.

*sigh*. I wish thetvdb would just fix the bug.
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

So where do I add the custom dirs (i.e Series Name/Season XX/) and then change "1x01" to "s00e00" inside of my custom format. Basicly get it to mimic the "plex" output.

Code: Select all

(a =~ /nb|da|sv/ ? n e t.filebot.WebServices.TheTVDB.getEpisodeList(id, null, new Locale (a)).find{ it =~ sxe || it =~ it.special} 
OR would it be easier to just tell filebot use "nb", instead of "no" when querying thetvdb? (like you suggested earlier)
abandonow
Posts: 32
Joined: 22 Jul 2020, 16:42

Re: Localized name from TheTVDB based on audio language?

Post by abandonow »

Just heard back from thetvdb, and they have their new API v4 and wont't prioritize v3 issues.

@rednoah any plans to implement the v4 API?
User avatar
rednoah
The Source
Posts: 19156
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Localized name from TheTVDB based on audio language?

Post by rednoah »

abandonow wrote: 12 Nov 2020, 19:20 any plans to implement the v4 API?
Yes, but as of right now, it doesn't even publicly exist yet.
:idea: Please read the FAQ and How to Request Help.
Post Reply