All about user-defined episode / movie / file name format expressions
kim
Power User
Posts: 1251 Joined: 15 May 2014, 16:17
Post
by kim » 16 Jun 2017, 18:01
is there a way to reuse a pre def variable in another {} ?
e.g. like this
Code: Select all
{def infoDK = net.filebot.WebServices.TheMovieDB.getMovieInfo(Movie, new Locale ('da', 'DK'), true)}
{infoDK.name}
if not, Feature Request
rednoah
The Source
Posts: 23939 Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:
Post
by rednoah » 16 Jun 2017, 18:14
1.
No, but you could write your entire format in a single
{...} block.
2.
You can use the
{localize} binding for what you're trying to do:
@see
viewtopic.php?t=3761
kim
Power User
Posts: 1251 Joined: 15 May 2014, 16:17
Post
by kim » 16 Jun 2017, 18:22
I know, I just changed it because of this
viewtopic.php?f=6&t=5120
localize = TheMovieDB.getMovieInfo(movie, locale,
FALSE ) ?
I want TheMovieDB.getMovieInfo(movie, locale,
TRUE ) to reduce api load
from htpc
Code: Select all
def movieInfo = TheMovieDB.getMovieInfo(movie, locale, true)
rednoah
The Source
Posts: 23939 Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:
Post
by rednoah » 16 Jun 2017, 18:27
{localize.Danish.info.name} does ask for extended information so it should be exactly the same as TheMovieDB.getMovieInfo(movie, Danish, true) as far as I know.
If you set the last parameter to false then that should require much less data, assuming that the data isn't cached already. Kinda depends on what you're doing.
kim
Power User
Posts: 1251 Joined: 15 May 2014, 16:17
Post
by kim » 16 Jun 2017, 23:01
well I tested it and:
it looks like (format):
Code: Select all
def infoDK = localize.DANISH.info;
def infoUS = localize.ENGLISH.info;
= LOG:
Fetch resource: api.themoviedb.org/3/movie/ID?language=en-US
Fetch resource: api.themoviedb.org/3/movie/ID?language=da-DK
Fetch resource: api.themoviedb.org/3/movie/ID?append_to_response=alternative_titles%2Creleases%2Ccasts%2Ctrailers&language=da
Fetch resource: api.themoviedb.org/3/configuration
Fetch resource: api.themoviedb.org/3/movie/ID?append_to_response=alternative_titles%2Creleases%2Ccasts%2Ctrailers&language=en
[MOVE] from *** to ***
Fetch resource: api.themoviedb.org/3/movie/ID?language=en
to me this looks bad
btw: still waiting on the new revision
kim
Power User
Posts: 1251 Joined: 15 May 2014, 16:17
Post
by kim » 16 Jun 2017, 23:07
And
def infoDK = net.filebot.WebServices.TheMovieDB.getMovieInfo(Movie, new Locale ('da', 'DK'), true);
def infoUS = net.filebot.WebServices.TheMovieDB.getMovieInfo(Movie, new Locale ('en', 'US'), true);
= LOG:
Fetch resource: api.themoviedb.org/3/movie/ID?language=en-US
Fetch resource: api.themoviedb.org/3/movie/ID?append_to_response=alternative_titles%2Creleases%2Ccasts%2Ctrailers&language=da-DK
Fetch resource: api.themoviedb.org/3/configuration
Fetch resource: api.themoviedb.org/3/movie/ID?append_to_response=alternative_titles%2Creleases%2Ccasts%2Ctrailers&language=en-US
[MOVE] from *** to ***
Fetch resource: api.themoviedb.org/3/movie/ID?language=en
Only the rename part (from AMC)
And this way it gets reused in the htpc (not downloaded again)
devster
Posts: 417 Joined: 06 Jun 2017, 22:56
Post
by devster » 20 Jun 2017, 22:46
rednoah wrote: ↑ 16 Jun 2017, 18:14
1.
No, but you could write your entire format in a single
{...} block.
What is the difference between:
Code: Select all
{ superu = { it.upper() } }
{ superu(ny)}
(stupid example, but works) and something like:
Code: Select all
{ def a = audioLanguages; a.size() > 1 ? a.ISO3.join(", ").upperInitial() : a.name.first() }
In the first case I seem to be able to reuse "superu(something)" in other parts of the script, but in the second case I seem to be able to reuse it.
I only work in black and sometimes very, very dark grey. (Batman)
rednoah
The Source
Posts: 23939 Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:
Post
by rednoah » 21 Jun 2017, 00:54
If you use def then it's a Groovy variable for the local block. If you don't use def then it's a global variable for the Groovy engine. It's difficult to reason about global variables. If you're advanced enough to use variables and functions, then I'd recommend using def for all your variables writing the entire format in a single {...} block of structured Groovy code
(kinda like you're doing in your shared custom format) .
Here, you're assigning a global variable, and the value of that variable is a Closure: