CLI filename format with empty values

Any questions? Need some help?
Post Reply
sjthespian
Posts: 7
Joined: 19 Mar 2021, 23:13

CLI filename format with empty values

Post by sjthespian »

I have been using filebot for a couple of years to rename downloaded files successfully, but there's one thing I just can't figure out. How can I build a format template that properly names things with imdb tags even if the item doesn't exist in IMDB? I'm trying to get filebot to name files the same way that Sonarr does.

For example, here are a couple of directory names for shows I download weekly from NHK World's streaming service:
  • Dive In Tokyo (2022) {imdb-}
  • Japan's Top Inventions (2018) {imdb-tt15031708}
Using a command like these to rename a downloaded file works fine with the second one, but not with the first:

Code: Select all

filebot -rename -non-strict --db TheTVDB --format '{ny} {"{imdb-$imdbid}"}/Season {s.pad(2)}/{ny} - {s00e00} - {t} [{vf}]{[hdr]}[{ac} {channels}]{[vc]}{-group}' --output /media/video/TV/ 'Dive in Tokyo - S03E03 Dive in Tokyo - Yotsuya - Echoes of Old Edo.mp4'
filebot -rename -non-strict --db TheTVDB --format '{ny} {"{imdb-$imdbid}"}/Season {s.pad(2)}/{ny} - {s00e00} - {t} [{vf}]{[hdr]}[{ac} {channels}]{[vc]}{-group}' --output /media/video/TV/ 'Japan'\''s Top Inventions - S07E03 Japan'\''s Top Inventions - Cultured Pearls ⧸ Casting Systems.mp4'
The problem I'm running into is that {"{imdb-$imdbid}"} does the right thing if $imdbid is set, but if it isn't it leaves out the whole string. I've tried various assortments of braces and quoting to get it to give me {imdb-} if the value isn't set, and I just can't come up with anything that works.

Can anyone tell me the obvious thing I'm missing that will make this work the way I want it to?

Thanks!
User avatar
rednoah
The Source
Posts: 23000
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: CLI filename format with empty values

Post by rednoah »

:idea: You probably mean to ask: How do I use {...} literally in a file name?


If it wasn't for using { and } in the file path you want, things would be easy:

Format: Select all

(imdb-{imdbid})

But since outermost {...} are interpreted by the format engine, we need to be a little bit creative:

Format: Select all

{ any{ "{imdb-$imdbid}" }{ "{imdb-}" } }
or

Format: Select all

{'\u007B'}imdb-{imdbid}{'\u007D'}
:idea: Please read the FAQ and How to Request Help.
sjthespian
Posts: 7
Joined: 19 Mar 2021, 23:13

Re: CLI filename format with empty values

Post by sjthespian »

Thanks! I think the "any" option is the secret - I didn't realize there was a way to essentially put an "or" statement in the format block.
Post Reply