Add year when not present

All about user-defined episode / movie / file name format expressions
Post Reply
Pab
Posts: 11
Joined: 18 Oct 2015, 21:45

Add year when not present

Post by Pab »

Is it possible to add the year in brackets only if the year is not present, whilst also preserving other types of trailing brackets, such as (US) or (UK)? For example

Firefly -> Firefly (2002)
The Newsroom (2012) -> The Newsroom (2012)
Wilfred (US) -> Wilfred (US) (2011)

I've tried writing if statements to check if the year is present like this:

Code: Select all

{n.contains(y) ? '' : '(y)'}
But I couldn't quite get it outputting the year. What would be the correct way to go about getting this?

Thank you
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Add year when not present

Post by rednoah »

Everything within {...} is Groovy code, so:

Code: Select all

{n.contains(y) ? '' : ' ('+y+')'}
:idea: Please read the FAQ and How to Request Help.
Pab
Posts: 11
Joined: 18 Oct 2015, 21:45

Re: Add year when not present

Post by Pab »

I think I tried that or something similar but it still isn't working. I tried on both mac and windows as well. Maybe some other part of the naming is interfering. Are there any other problems in this:

Code: Select all

D:/Tv/{genres.contains('Documentary') ? 'Docs - Series' : 'Shows'}/{info.status == 'Ended' ? 'Ended' : 'Ongoing'}/{n.replaceAll(/:/,/-/)} {n.contains(y) ? '' : ' ('+y+')'} ({certification}) [{audio.language}] [{series.id}]/Season {s.pad(2)}/{n.replaceAll(/:/,/-/)} - {s00e00} - {t.replaceAll(/:/,/-/).replaceAll(/[!?.]+$/)} - ({airdate.format('yyyy.MM.dd')}) - [{vc} {vf} {ac} {af}]{' ['+file.name.match(/EngSub|EngDub/)+']'}{'.'+lang}
Thanks again
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Add year when not present

Post by rednoah »

y is an Integer, not a String, so:

Code: Select all

{n.contains(y as String) ? '' : ' ('+y+')'}
Or just:

Code: Select all

{n =~ y ? '' : ' ('+y+')'}
EDIT:

The new {ny} binding will make this even easier.
:idea: Please read the FAQ and How to Request Help.
tyrannicpuppy
Posts: 4
Joined: 17 Dec 2016, 11:19

Re: Add year when not present

Post by tyrannicpuppy »

Thank you so much.

This has helped significantly with my media due to shows like Doctor Who (of which I have classic and new), I like to have the Show folder with the Date, and kept getting double dates on some shows.

My only question is would it be possible to remove the date from the Video filename for shows that are listed with dates on TVDB (e.g. Castle (2009), The Flash (2014), Doctor Who (2005)) but not effect shows that don't (e.g. Arrow, Firefly).

i.e. I would like the files to appear as:
Volumes/Plex/TV/Castle (2009)/Season 01/Castle - S01E08 - Ghosts.mp4

My format is:

Code: Select all

/Volumes/Plex/TV/{ny}/{episode.special ? 'Specials' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.replaceAll(/[`´‘’ʻ]/, /'/).replaceAll(/[!?.]+$/).replacePart(' [$1]')}
I have been trying to achieve it with .replaceAll but I am total noob when it comes to all of this and I cannot get it to work.

I'll be incredibly thankful to anyone who can help me with this.
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Add year when not present

Post by rednoah »

Use {ny} and things will just work, no double years.

If you want to remove the year from {n} then you could try the String.removeTrailingBrackets() helper function.
:idea: Please read the FAQ and How to Request Help.
tyrannicpuppy
Posts: 4
Joined: 17 Dec 2016, 11:19

Re: Add year when not present

Post by tyrannicpuppy »

Perfect. It now works exactly as I wanted. Thank you so much.

Now I just have to incorporate it into my AMC.
User avatar
rednoah
The Source
Posts: 22986
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Add year when not present

Post by rednoah »

Use external text files: viewtopic.php?f=3&t=3244
:idea: Please read the FAQ and How to Request Help.
Post Reply