Movie Renaming w/ alpha sort folder + collection folder + more

All about user-defined episode / movie format expressions
Post Reply
chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 10 Aug 2016, 11:45

I wanted to hurry up and post this before I lose it or something terrible happens to my computer (joking)

This took a long time and is a mashup of several people on the forum's contribution, but I wanted to share my finished product.

Here's my movie renamer.

Code: Select all

E:\movies\{def cn = any{"$collection".replaceFirst(/^(?i)(The|A|An|Der|Die|Das)\s(.+)/, /$2, $1/)+"/"}{n.replaceFirst(/^(?i)(The|A|An|Der|Die|Das)\s(.+)/, /$2, $1/)}; cn =~ /^(?i)[a-z]/ ? cn[0] : '#'}\{collection.replaceFirst(/^(?i)(The|A|An|Der|Die|Das)\s(.+)/, /$2, $1/).replaceFirst(/^(?i)(Collection of the)\s(.+)/, /$2 Collection/).replaceAll(/Saga Collection/, "Saga").replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ")}\{norm = {it.upperInitial().lowerTrail().replaceTrailingBrackets().replaceAll(/[`´‘’ʻ""“”]/, "'").replaceAll(/[:|]/, " - ").replaceAll(/[?]/, "!").replaceAll(/[*\s]+/, " ").replaceAll(/\b[IiVvXx]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:th|nd|rd)\b/, { it.lower() }).replaceFirst(/^(?i)(The|A|An|Der|Die|Das)\s(.+)/, /$2, $1/)}; norm(n)}{if (norm(n) != norm(primaryTitle)) ' ('+norm(primaryTitle)+')'}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""} ({y})/{n.space('.').replaceAll(/[,!'`´‘’ʻ""“”]/, "")}{fn.contains('3D') || fn.contains('3-D') ? ' '+'3D':""}{' (' + fn.matchAll(/extended|uncensored|remastered|unrated|uncut|directors.cut|special.edition/)*.upperInitial()*.lowerTrail().sort().join(', ').replaceAll(/[._]/, ".") + ')'}.{y}{".Part$pi.$vf.$vc.$ac.$af"}
Here's what it does:
- moves to folder
- assigns a single character alpha/numeric folder hierarchy, ignoring articles (The, An, A, etc.)
- assigns the single character based on whether or not a collection exists
- cleans up the name of the Collections a little
- puts a full character movie name as the folder under the Collection folder
- if no Collection folder exists then the movie name is a level higher
- cleans up special characters a little
- renames the file as "." separated with some special Character cleanup
- Capitalizes/lower cases letters appropriately

Here are some examples of the output:

- from Risen_2016_t01.mkv to \R\Risen (2016)\Risen.2016.[original].mkv
- from Maze_Runner_The_Scorch_Trials_2015_t00.mkv to \M\Maze Runner Collection, The\Maze Runner - The Scorch Trials (2015)\Maze.Runner.The.Scorch.Trials.2015.[original].mkv
- from 13_Hours_The_Secret_Soldiers_of_Benghazi_2016_t01.mkv to \#\13 Hours - The Secret Soldiers Of Benghazi (2016)\13.Hours.The.Secret.Soldiers.of.Benghazi.2016.[original].mkv
- from Ocean's_Eleven_2001_t00.mkv to \O\Ocean's Collection\Ocean's Eleven (2001)\Oceans.Eleven.2001.[original].mkv
- from The_Town_2010_t00.mkv to \T\Town, The (2010)\The.Town.2010.[original].mkv
- from Hail_Caesar!_2016.mkv to \H\Hail, Caesar! (2016)\Hail.Caesar.2016.[original].mkv

I have no idea how to write code, all I did was hobble together hours of forum examples, but hopefully this is useful to someone that knows what they're doing.

Now I just have to figure out how to automate the script. :oops:

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

Re: Solved: Movie Renaming w/ alpha sort folder + collection folder + more

Post by rednoah » 10 Aug 2016, 15:01

This should be doing pretty much the same, but shorter and more readable:

Code: Select all

{
   norm = {
      it.colon(' - ')
      .tr('*?|', ' !-')
      .asciiQuotes()
      .replaceAll(/\b(?i)[IVX]+\b/, { it.upper() })
      .replaceAll(/\b[0-9](?i:st|nd|rd|th)\b/, { it.lower() })
      .replaceAll(/(Collection) of the (.+)/, /$2 $1/)
      .replaceAll(/(Saga) Collection/, /$1/)
      .replaceAll(/^(?i)(The|A|An|Der|Die|Das) (.+)/, /$2, $1/)
   };
   path = allOf{ norm(collection) }{ norm(n) }.join('/');
   path[0].replaceAll(/\W|\d/, '#') + '/' + path
}{
   norm(n) != norm(primaryTitle) ? ' (' + primaryTitle + ')' : null
}{
   fn =~ /3D|3-D/ ? ' 3D' : null
} ({y})/{
   allOf
      {n.asciiQuotes().removeAll(/[,!]/)}
      {fn =~ /3D|3-D/ ? '3D' : null}
      {'(' + tags.join(', ') + ')'}
      {y}{'Part'+pi}
      {vf}{vc}{ac}{af}
   .join('.').space('.')
}
EDIT: Fixed (see below)
:idea: Please read the FAQ and How to Request Help.

chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 11 Aug 2016, 09:31

Thanks! your code is sooooo much cleaner :-)

In the way you have this structured I can't figure out how to add back in my text at the end.

As you can see from my export examples, I put "[original]" at the end of all these files so I know which files are my ripped MKVs

Do you mind taking a second and showing me how and where to add it back in to your example. Everything I try doesn't work.

In my version the following seemed to work.

Code: Select all

{"[original-rip]"}

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

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by rednoah » 11 Aug 2016, 10:05

Just add [original-rip] at the very end:

Code: Select all

   .join('.').space('.')
}[original-rip]
Everything not enclosed in {...} is a literal.
:idea: Please read the FAQ and How to Request Help.

chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 12 Aug 2016, 06:06

Well I feel silly. Thanks! That works.

But... :-( Either I'm doing something wrong or your code doesn't work like mine.

Here's a view of what yours returns. It makes these weird year folders all over the place. At the main level and under collections.

Image

It appears to be an issue with movie titles that start with Articles.
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.Bug's.Life.1998.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.Bug's.Life.1998.[original-rip].mkv] to [E:\movies\(1998)\A.Bug's.Life.1998.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.Christmas.Carol.2009.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.Christmas.Carol.2009.[original-rip].mkv] to [E:\movies\(2009)\A.Christmas.Carol.2009.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.Christmas.Story.1983.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.Christmas.Story.1983.[original-rip].mkv] to [E:\movies\(1983)\A.Christmas.Story.1983.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.Few.Good.Men.1992.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.Few.Good.Men.1992.[original-rip].mkv] to [E:\movies\(1992)\A.Few.Good.Men.1992.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.Good.Day.to.Die.Hard.2013.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.Good.Day.to.Die.Hard.2013.[original-rip].mkv] to [E:\movies\(2013)\A.Good.Day.to.Die.Hard.2013.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.History.of.Violence.2005.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.History.of.Violence.2005.[original-rip].mkv] to [E:\movies\(2005)\A.History.of.Violence.2005.[original-rip].mkv]
Processed 1 files
Rename movies using [TheMovieDB]
Auto-detect movie from context: [E:\tmp\MCEBuddy\movies original\A.League.of.Their.Own.1992.[original-rip].mkv]
[MOVE] Rename [E:\tmp\MCEBuddy\movies original\A.League.of.Their.Own.1992.[original-rip].mkv] to [E:\movies\(1992)\A.League.of.Their.Own.1992.[original-rip].mkv]
Processed 1 files
It put's it in a folder name "(year_number)" for some reason. Like (1992) instead of the movie title as the folder name

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

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by rednoah » 12 Aug 2016, 08:06

BAD, because we don't capture the first group:

Code: Select all

.replaceAll(/^(?i:The|A|An|Der|Die|Das) (.+)/, /$2, $1/)
FIX:

Code: Select all

.replaceAll(/^(i:The|A|An|Der|Die|Das) (.+)/, /$2, $1/)

PS: --action test is your friend ;)
:idea: Please read the FAQ and How to Request Help.

chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 13 Aug 2016, 05:18

Thanks! --action test makes this so much easier!

I fixed two additional lines in your code.

1. your code wasn't correctly formatting movies that started with "The" but was working correctly for "A" & "An". I don't know if this is the correct way to fix it but it works.

BAD:

Code: Select all

.replaceAll(/^(i:The|A|An) (.+)/, /$2, $1/)
FIX (edited):

Code: Select all

.replaceAll(/^(i:|The|A|An) (.+)/, /$2, $1/)

2. Your code only put movies that started with a special character in the "#" folder. In the original code, movies that started with both numbers and special characters were in the "#"

BAD:

Code: Select all

.replaceAll(/\W/, '#') 
FIX:

Code: Select all

.replaceAll(/\W|\d/, '#') 
Here's the full updated version:

Code: Select all

{norm = {it.colon(' - ').tr('*?|', ' !-').asciiQuotes().replaceAll(/\b(?i)[IVX]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:|st|nd|rd|th)\b/, { it.lower() }).replaceAll(/(Collection) of the (.+)/, /$2 $1/).replaceAll(/(Saga) Collection/, /$1/).replaceAll(/^(i:|A|An|The) (.+)/, /$2, $1/)};path = allOf{ norm(collection) }{ norm(n) }.join('/');path[0].replaceAll(/\W|\d/, '#') + '/' + path}{norm(n) != norm(primaryTitle) ? ' (' + primaryTitle + ')' : null}{fn =~ /3D|3-D/ ? ' 3D' : null} ({y})/{allOf{n.asciiQuotes().removeAll(/[,!]/)}{fn =~ /3D|3-D/ ? '3D' : null}{'(' + tags.join(', ') + ')'}{y}{'Part'+pi}{vf}{vc}{ac}{af}.join('.').space('.')}.[original-rip]
Last edited by chansearrington on 13 Aug 2016, 18:02, edited 1 time in total.

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

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by rednoah » 13 Aug 2016, 15:20

1.
Your "fix" doesn't make sense. Here's a proper fix:

Code: Select all

{'The Test'.replaceAll(/^(?i)(The|A|An|Der|Die|Das) (.+)/, /$2, $1/)}
:idea: Please read the FAQ and How to Request Help.

chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 13 Aug 2016, 18:42

Sorry, I had a typo in my "fix".

I changed it above as well, but it works with a "|" in front of "The" but does not work for movies starting with "The" with out it.

I'll try it with your fix tonight

chansearrington
Donor
Posts: 7
Joined: 22 Mar 2015, 09:23

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by chansearrington » 19 Mar 2017, 02:34

Hey rednoah,

Any chance you can convert this to a version that works for TV Shows in exchange for another donation? I've been trying to get this to work all day and I'm at my wits end.

Here's what I'm trying to accomplish:
  • moves to folder
  • assigns a single character alpha/numeric folder hierarchy, ignoring articles (The, An, A, etc.) with all numbers and symbols under "#"
  • puts a full character TV Series name plus county like "US" or "UK" only when necessary
  • puts the show year only when necessary -> Battlestar Galactica (2003)
  • Puts Specials in separate "Specials" folder
  • Puts Seasons in padded Seasons -> Season 02
  • cleans up special characters
  • format for the episodes are Series.Title.S00E00.Title.Resolution.[sonar-dl].mkv
  • renames the file as "." separated with some special Character cleanup
  • Capitalizes/lower cases letters appropriately
  • Includes video resolution
  • Includes text "[sonarr-dl]"
Here's some examples
  • \#\12 Monkeys\Season 01\12.Monkeys.S01E01.Splinter.720p.[sonarr-dl].mkv
  • \B\Battlestar Galactica (2003)\Season 04\Battlestar.Galactica.(2003).S04E01.He.That.Believeth.in.Me.720p.[sonarr-dl].mkv
  • \K\The Killing (US)\Season 03\The.Killing.US.S03E01.The.Jungle.720p.[sonarr-dl].mkv
Here's my current mess that I've tried to adapt from movies script.

Code: Select all

filebot -script fn:amc --output "D:/tv/downloaded/" --log-file amc_sonarr_import.log --action move --conflict override -non-strict "D:/tmp/Sonarr/" --def excludeList=amc_sonar_import.txt 
seriesFormat="{norm = {it.colon(' - ').tr('*?|', ' !-').asciiQuotes().replaceAll(/\b(?i)[IVX]+\b/, { it.upper() }).replaceAll(/\b[0-9](?i:|st|nd|rd|th)\b/, { it.lower() }).replaceAll(/(Collection) of the (.+)/, /$2 $1/).replaceAll(/(Saga) Collection/, /$1/).replaceAll(/^(i:|A|An|The) (.+)/, /$2, $1/)};
path = allOf{ norm(collection) }{ norm(n) }.join('/');path[0].replaceAll(/\W|\d/, '#') + '/' + path}{norm(n) != norm(primaryTitle) ? ' (' + primaryTitle + ')' : null}{fn =~ /3D|3-D/ ? ' 3D' : null} ({y})/{allOf{n.asciiQuotes().removeAll(/[,!]/)}{fn =~ /3D|3-D/ ? '3D' : null}{'(' + tags.join(', ') + ')'}{y}{'Part'+pi}{vf}{vc}{ac}{af}.join('.').space('.')}.[sonar-dl]"

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

Re: Movie Renaming w/ alpha sort folder + collection folder + more

Post by rednoah » 19 Mar 2017, 07:29

1.
This will solve the issue mostly:

Code: Select all

/path/to/TV Shows/{az}/{plex.tail.derive{" [$resolution] [sonar-dl]"}}
:idea: (US) (UK) (2003) etc are added by TheTVDB to make the name unique. If it's necessary, then it's already part of the name.

:idea: Using '.' instead of space makes no sense if you only do it for the filename, and not the whole file path.

:idea: "appropriately" means whatever you want it to mean, and I can't read your mind, so we'll just trust TheTVDB for the right characters and spelling here. ;)


2.
Also, overly complex command-line arguments are to be avoided:
viewtopic.php?f=3&t=3244
:idea: Please read the FAQ and How to Request Help.

Post Reply