"The" lookup/rename bug

All your suggestions, requests and ideas for future development
Post Reply
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

"The" lookup/rename bug

Post by kim »

Using amc -non-strict, if you change seriesFormat = {n}
to any of this, it will get the naming ok, BUT it will get wrong fanart and nfo file from different show

Code: Select all

tvs:   any{ seriesFormat }{ '''TV/{n.replaceFirst(/^(?i)(The|A|An)\\s(.+)/, /$2, $1/).replace(':', ' - ').trim()}/{n.replaceTrailingBrackets().trim().space('.')}{'.'+s00e00}{'.'+t.space('.').replaceAll(/[!?.]+$/).replacePart('(Part.$1)')}{'-'+group}{'.'+lang}''' },
The Avengers => Avengers, The

{n.sortName()}
{n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}

try it out with e.g. The.Librarians.S02E01


it makes a lookup only for:
http://thetvdb.com/api/GetSeries.php?se ... anguage=en

NOT
http://thetvdb.com/api/GetSeries.php?se ... anguage=en
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

That's why it says:
NOTE: If you mess up the filename like this, FileBot and HTPC software may have trouble making sense of the filename in the future.
You can either make sure that files are named properly, or that xattr metadata is supported and working on the relevant file system.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

but its only part of it that it gets wrong

why does it lookup in 2 dif. ways ?

cant it just do the rename part last ?

or check to see if there is a ", The" ?

plus i only rename the folder NOT the file, so it still has every chance at a correct lookup
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

The artwork.tmdb script expects files to be organized a certain way:
Movies are expected to be organized into folders. The movie is determined using the name of the parent folder of each video file.
It also expects movies to be organized into folder, one movie per folder. FileBot has 2 different ways of doing almost everything, strict and non-strict mode that is, but once you mess with the filename things might get odd either way. I'd try removing the ", The" part at the end and see if that works better.

As I said, FileBot will *try* to store full metadata for each file in the filesystem, and it will *try* to use previously stored metadata to identify the files, so the question you should be asking is why "Why are Extended Attributes not working?".
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

Still using amc and xattr = OFF

In order to use:
The Avengers => Avengers, The
{n.sortName()}
{n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)}

I'm trying to make a PreRename.groovy script
that looks for FOLDERS with "Avengers, The" and rename it to "The Avengers"
so I can use the amc script with e.g. {n.replaceFirst(/^(?i)(The|A|An)\s(.+)/, /$2, $1/)} again

1. Get FOLDERS ONLY (from args.getFolders() ?)
2. If e.g. "Avengers, The" rename to "The Avengers" using something like (?:(.+)(?:[,]\s)([Tt]he|[Aa]|[Aa]n)$)
3. Don't do anything to folders that have ", A" or ", An" or ", The"
4. Do this OFFLINE ONLY

Can you/anyone help pls ???



btw: i made a script that +1 the Season for American Dad! (so it match the TheTVDB season)

Code: Select all

args.getFiles{ it.isVideo() }
.each {
rename(file:it, format:"{n==~'American Dad!' ? n+' S'+(episode.season ? s+1 : 1).pad(2)+'E'+e.pad(2): fn}")
}
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

Rename Avengers, The to The Avengers:

Code: Select all

def e = /^(.+), (The|A|An)$/
def r = /$2 $1/

rename(
	map: args.getFolders().findAll{ it ==~ e }.collectEntries{ [it, it.name.replaceFirst(e, r)] }
)

Rename Alias 1x01 to Alias 2x01:

Code: Select all

def offset = [season: +1, episode: 0]

def p = /(\d{1,2})(\D)(\d{2})/
def r = { m, s, x, e -> ((s as int) + offset.season) + x + ((e as int) + offset.episode).pad(2) }

rename(
	map: args.getFiles().findAll{ parseEpisodeNumber(it) != null }.collectEntries{ [it, it.name.replaceFirst(p, r)] }
)
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

nice THX, that would have taken me weeks to do if ever :)

any chance to help with how to use a show filter (n==~'American Dad!') in the: ???

Code: Select all

def offset = [season: +1, episode: 0]

def p = /(\d{1,2})(\D)(\d{2})/
def r = { m, s, x, e -> ((s as int) + offset.season) + x + ((e as int) + offset.episode).pad(2) }

rename(
   map: args.getFiles().findAll{ parseEpisodeNumber(it) != null }.collectEntries{ [it, it.name.replaceFirst(p, r)] }
)
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

Something like this?

Code: Select all

args.getFiles().findAll{ it =~ /American.Dad/ }
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

thx, but I don't get where to put it in the code ?

can it take a list (if i need) ?
this the right way ?

Code: Select all

args.getFiles().findAll{(it =~ /(?i)American.Dad/||it =~ /(?i)Other.Show/)

EDIT: This looks like it works

Code: Select all

def offset = [season: +1, episode: 0]

def p = /(\d{1,2})(\D)(\d{2})/
def r = { m, s, x, e -> ((s as int) + offset.season) + x + ((e as int) + offset.episode).pad(2) }

rename(
map: args.getFiles().findAll{it =~ /American.Dad/ && parseEpisodeNumber(it) != null }.collectEntries{ [it, it.name.replaceFirst(p, r)] }
)
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

You can use any code that returns true/false as findAll{} so you can use || or but doing that in the regex right away is easier:

Code: Select all

args.getFiles().findAll{ it =~ /(?i:American.Dad|Other.Show)/ }.findAll{ parseEpisodeNumber(it) != null }
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

thx
btw i think i found an "error" in your script when trying to do the reverse "Rename Avengers, The to The Avengers:"

Code: Select all

.findAll{it ==~ e }
should be 
.findAll{it.name ==~ e }

Code: Select all

// Move The|A|An to the FRONT from the BACK
def e = /^(The|A|An)\s(.+)$/
def r = /$2, $1/

rename(
   map: args.getFolders().findAll{it.name ==~ e }.each{println "FOUND: $it.name"}.collectEntries{ [it, it.name.replaceFirst(e, r)] }
)
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

Good point. You'll want to do matches exactly ==~ the file.name, not the whole file path.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

can you explain what makes it offline only ?

I'm trying do make this offline only:
args.getFiles{ it.isVideo() }
.each{println "FOUND: $it.name in $it.parentFile.parentFile --> $it.parentFile.parentFile.name.$it.extension"
rename(file:it, format:"{file.parentFile.parentFile}/{file.parentFile.parentFile.name}")
}

this almost works (move 1 dir up part missing):
def String input = ''
def String output = ''

rename(map: args.getFiles{ it.isVideo() }
.each{input=it.name; println "FOUND: $it.name in $it.parentFile.parentFile --> $it.parentFile.parentFile.name.$it.extension"
output = it.parentFile.parentFile.name+'.'+it.extension
}
.collectEntries{ [it, it.name.replaceFirst(input, output)] }
)
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

You can pass in a File->File map: rename(map: Map<File,File>)

But if you really just want to move/rename files then you can just do it directly File.renameTo(File) without any of the FileBot-specific APIs.
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

1. if this "You can pass in a File->File map: rename(map: Map<File,File>)"
answers "can you explain what makes it offline only"...

then I don't get it... can you dumb it down, pls ?

2. don't think I can use "File.renameTo(File)"
I need the ".isVideo()" part

3. Is there a way I can use the GUI to test script proper without F*ing it up like this:
"{def String input = ''; def String output = ''; file.getFiles{ it.isVideo() }.each{input=it.name; output = it.parentFile.parentFile.name+'.'+it.extension }.collectEntries{ [it, it.name.replaceFirst(input, output)] } }"
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

1.
If you pass in a map of files, then it will just rename files accordingly. There will be no online lookups of any kind.

2.
Does one have anything to do with the other?

3.
Press F5 to open the Groovy pad. Also, why would you not use newlines? It's quite unreadable. I'm not sure what it's supposed to do, but I'm sure there's a more elegant solution. :D


PS: I'm talking about Groovy scripting. I'm not talking about FileBot format expressions. In case there's a confusion here.


EDIT:

If this is a one-off problem, then I'd just do it with the GUI:
viewtopic.php?f=3&t=2072
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: "The" lookup/rename bug

Post by kim »

I have seen "Groovy pad" before, but ever used, because I don't know how to ?

If I try to run e.g.
args.getFiles{ it.isVideo() }
.each{println "FOUND: $it.name in $it.parentFile.parentFile --> $it.parentFile.parentFile.name.$it.extension"
rename(file:it, format:"{file.parentFile.parentFile}/{file.parentFile.parentFile.name}")
}

I get only "Result: []"

how to pass args to it ?
file = No such property: file for class: Script57
and so on... ?
it's like it has nothing to do with filebot, only "vanilla" groovy/java code ?


I need a visual way to show instant results in order to make scripts via the "trial and error" way (my way)
User avatar
rednoah
The Source
Posts: 22976
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: "The" lookup/rename bug

Post by rednoah »

Step 1:

Code: Select all

println args
Result: Oh, it's empty by default because I'm not using the command-line to pass in arguments.


Step 2:

Code: Select all

def args = ['/path/to/folder' as File]
println args
Result: Ok, not empty anymore!


Step 3:

Code: Select all

def args = ['/path/to/folder' as File]
args.getFiles{ it.isVideo() }.each{
	println it
}
Result: Ok, selecting video files works.



I'll leave the rest up to you. ;)
:idea: Please read the FAQ and How to Request Help.
Post Reply