Rename folders only for HAMA by [anidb-###]

Running FileBot from the console, Groovy scripting, shell scripts, etc
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

Hey party peeps, I did look around, but maybe I did a bad job looking, is there a way I can do something similar to the below but for anidb?

Format: Select all

{
	def series = files.metadata.series.find()
	series.name + ' {tmdb-' + series.getExternalId('TheMovieDB') + '}'
}
Taken from here viewtopic.php?t=13723

I am thinking something like this?

Format: Select all

{
	def series = files.metadata.series.find()
	series.name + ' {anidb-' + series.getExternalId('AniDB') + '}'
}
The goal is to only rename the folder so it looks like this.

Code: Select all

Armitage III Poly Matrix [anidb-236]
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

I guess you could try and see what happens? Keep us posted!

If the files at hand already have xattr metadata based on AniDB episode information, then you can easily rewrite the file paths, rename folders, etc based on locally known information. If it's TheMovieDB / TheTVDB episode information, then it'll probably work for most (but not all) Anime depending on ID mappings being known. If files don't have xattr metadata then you'll want to process them with AniDB and just generate the file paths you want (file name, folder name, etc, all at once) at that time.
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

rednoah wrote: 06 Apr 2024, 16:49 I guess you could try and see what happens? Keep us posted!

If the files at hand already have xattr metadata based on AniDB episode information, then you can easily rewrite the file paths, rename folders, etc based on locally known information. If it's TheMovieDB / TheTVDB episode information, then it'll probably work for most (but not all) Anime depending on ID mappings being known. If files don't have xattr metadata then you'll want to process them with AniDB and just generate the file paths you want (file name, folder name, etc, all at once) at that time.
Do I have the vars right/close? I did not see a good list of what is out there to leverage.
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

I have copy & pasted the code you posted, ran it on a sample file / folder, and found that it works.
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

huh, maybe it just hates me then?

This is what I get.

Code: Select all

[Undefined Variable: java.lang.NullPointerException: Cannot get property 'name' on null object at org.codehaus.groovy.runtime.NullObject::getProperty in org.codehaus.groovy.vmplugin.v8.IndyInterface::fromCache in __script_c53674449a35e89de3895960ea27328d::run] Afro Samurai - 01 - Revenge
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

and this one from ctrl + shift

Code: Select all

[Undefined Variable: java.lang.NullPointerException: Cannot get property 'name' on null object at org.codehaus.groovy.runtime.NullObject::getProperty in org.codehaus.groovy.vmplugin.v8.IndyInterface::fromCache in __script_c53674449a35e89de3895960ea27328d::run] Afro Samurai
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

rednoah wrote: 06 Apr 2024, 16:49 If the files at hand already have xattr metadata based on AniDB episode information, then you can easily rewrite the file paths, rename folders, etc based on locally known information. If it's TheMovieDB / TheTVDB episode information, then it'll probably work for most (but not all) Anime depending on ID mappings being known. If files don't have xattr metadata then you'll want to process them with AniDB and just generate the file paths you want (file name, folder name, etc, all at once) at that time.
:?: Do your files have xattr metadata?

:arrow: Cannot get property 'name' on null object suggest not. You need to process the files with FileBot / AniDB first.
rednoah wrote: 02 May 2023, 17:30 :!: The format above will fail if you attempt to process a folder that does not contain any files with xattr metadata:

Error: Select all

java.lang.NullPointerException: Cannot get property 'name' on null object
Screenshot
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

This is what I get, maybe I am smooth brain?

Code: Select all

PS T:\Anime\Afro Samurai> filebot -script fn:xattr '.\Afro Samurai - 1 - Revenge [no group](F20769C4).mkv'
Initialize new disk cache: C:\Users\gcs8\AppData\Roaming\FileBot\cache\1
T:\Anime\Afro Samurai\Afro Samurai - 1 - Revenge [no group](F20769C4).mkv
        net.filebot.mediainfo: ????
        net.filebot.mediainfo.mtime: 1451614320743
Undefined Variable: java.lang.NullPointerException: Cannot invoke method length() on null object at Script::doCall in Script::doCall in Script::run
java.lang.NullPointerException: Cannot invoke method length() on null object
        at Script.doCall(Script:36)
        at Script.doCall(Script:31)
        at Script.run(Script:29)
        at net.filebot.GroovyEngine.eval(Unknown Source)
        at net.filebot.cli.ScriptShell.evaluate(Unknown Source)
        at net.filebot.cli.ScriptShell.runScript(Unknown Source)
        at net.filebot.cli.ArgumentProcessor.runScript(Unknown Source)
        at net.filebot.cli.ArgumentProcessor.run(Unknown Source)
        at net.filebot.Main.main(Unknown Source)

Error (o_O)
PS T:\Anime\Afro Samurai>
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

xattr metadata refers to the extended attribute named net.filebot.metadata that contains JSON encoded episode information including the series ID:

Console Output: Select all

$ filebot -script fn:xattr *.mkv
Afro Samurai - 01 - Revenge.mkv
	...
	net.filebot.metadata: {"@type":"Episode","seriesName":"Afro Samurai","episode":1,"title":"Revenge","absolute":1,"airdate":{"year":2007,"month":1,"day":4},"id":66029,"seriesInfo":{"database":"AniDB","order":"Absolute","language":"en-US","type":"TV Series","id":2656,"name":"Afro Samurai","aliasNames":["Afro Samurajus","Афро Самурай","アフロサムライ","Афросамурай","Afrosamuraj","Afro Szamuráj","آفرو سامورایی"],"startDate":{"year":2007,"month":1,"day":4},"genres":[],"rating":4.66}}
	...

:idea: You can view xattr metadata in the FileBot Desktop application:
Screenshot
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

huh, I am not getting that -_-

Code: Select all

PS T:\Anime\Afro Samurai> filebot -script fn:xattr *.mkv
No xattr metadata found
Done ?(?????)?
PS T:\Anime\Afro Samurai>
Screenshot
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

whoops, sorry, wrong tab.

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

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

Yep, you'll need to process the files with FileBot / AniDB first.
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

ok, let me try and go RTFM, back in a bit.
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

rednoah wrote: 06 Apr 2024, 17:53 Yep, you'll need to process the files with FileBot / AniDB first.
At that point you can just use T:/{plex.id} as format to name / organize files correctly at once. ☑ Import companion files will take care of moving along the *.jpg files as well.
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

rednoah wrote: 06 Apr 2024, 17:56 At that point you can just use T:/{plex.id} as format to name / organize files correctly at once. ☑ Import companion files will take care of moving along the *.jpg files as well.
Well, I use AoM to match everything by hash and add the extra stuff I want from there, so I don't want to touch the files, I only want to have it tag the folders for me with the AniDB series/index/database ID of the series.
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

gcs8 wrote: 06 Apr 2024, 18:13 Well, I use AoM to match everything by hash and add the extra stuff I want from there, so I don't want to touch the files, I only want to have it tag the folders for me with the AniDB series/index/database ID of the series.
:?: Why not have AoM generate file paths with AniDB ID?

:?: How can FileBot know the AniDB ID? Does AoM generate / write any kind of metadata that FileBot can read to know the AniDB ID for any given file / folder?
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

rednoah wrote: 06 Apr 2024, 18:14
gcs8 wrote: 06 Apr 2024, 18:13 Well, I use AoM to match everything by hash and add the extra stuff I want from there, so I don't want to touch the files, I only want to have it tag the folders for me with the AniDB series/index/database ID of the series.
:?: Why not have AoM generate file paths with AniDB ID?

:?: How can FileBot know the AniDB ID? Does AoM generate / write any kind of metadata that FileBot can read to know the AniDB ID for any given file / folder?
So, I am starting to look at seeing if AoM can/will do it, but it's super old code and does not do some things well like long file paths and the renaming script language is kinda suck.

This is the data AoM has, but it's using the local copy of the DB to pull this.

Screenshot

Screenshot
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

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

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

I guess AoM knows the AniDB ID, so I think you best course of action is to configure AoM to include the AniDB ID. The link from the previous post is from some sort of "custom format" language, so it's probably possible, though ugly and unreadable to code may look at a glance.


FileBot itself cannot do much if it cannot read the ID from somewhere. A text / xml / json file would be easy to read. If AoM has some sort of local database in some unknown binary format, then you will probably not get anywhere.
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

So, you could reference this like HAMA does to get the title > ID mapping for FileBot. https://github.com/Anime-Lists/anime-li ... t-full.xml

This it's just in this format.

Code: Select all

 <anime anidbid="2656" tvdbid="79755" defaulttvdbseason="1">
    <name>Afro Samurai</name>
  </anime>
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

Yep, that'll work:

Format: Select all

{
	def name = 'Afro Samurai'
	def xml = xml('https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-full.xml')
	xml.anime.find{ it.name == name }.'@anidbid'
}

Code: Select all

2656
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

So, am I looking for something like this for dynamic?

Format: Select all

{
	def name = '{n}'
	def xml = xml('https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-full.xml')
	xml.anime.find{ it.name == name }.'@anidbid'
	name + ' {anidb-' + '@anidbid' + '}'
}
User avatar
rednoah
The Source
Posts: 23006
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename folders only for HAMA by [anidb-###]

Post by rednoah »

n is the file name in Plain File Mode so:

Format: Select all

{
	def xml = xml('https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-full.xml')
	def aid = xml.anime.find{ it.name == n }.'@anidbid'
	n + ' {anidb-' + aid + '}'
}
:idea: Please read the FAQ and How to Request Help.
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

Oh, cool, let me try that, I picked a fight with AoM and made this work also.

Groovy: Select all

// Anime title
set('atitle', at('en'))
if(length(atitle)=0, set('atitle', at('x-jat')))
if(length(atitle)=0, set('atitle', A.Name))
set('atitle', replace(atitle, '\', ' '))
if(start(atitle, '.'), set('atitle', copy(atitle, 2, length(atitle))))
set('atitle', replace(atitle, '...', ''))
set('atitle', replace(atitle, '1/2', '½'))
set('atitle', trim(atitle))
set('uncensored', (F.State and 64) > 1)
set('censored', (F.State and 128) > 1)

// Episode title
set('etitle', et('en'))
if(length(etitle)=0, set('etitle', et('x-jat')))
if(length(etitle)=0, set('etitle', et('ja')))
if(length(etitle)=0, set('etitle', E.Name))
set('etitle', replace(etitle, '\', ' '))
set('etitle', replace(etitle, '...', ''))
set('etitle', trim(etitle))

// Version
set('version', if(F.Version>1, 'v'+F.Version, ''))
set('v2n', version)

// Episode number and prefix
set('mepno', if(E.TypeId=1, max(A.TotalEpisodeCount, E.EpisodeTypeCount), E.EpisodeTypeCount))
set('epno', padl(E.EpisodeNo, max(1, length(mepno)), '0') + version)
if(E.TypeId=2, set('epno', 'S'+epno))
if(E.TypeId=3, set('epno', 'C'+epno))
if(E.TypeId=4, set('epno', 'T'+epno))
if(E.TypeId=5, set('epno', 'P'+epno))
if(E.TypeId=6, set('epno', 'O'+epno))

// Group name
set('groupname', if(G, if(length(G.Shortname)>0, G.Shortname, G.Name), 'no group'))
set('groupname', if(length(groupname)>0, '['+groupname+']'))
set('groupname', replace(groupname, '\', ' '))

// CRC
set('crc', if(H, H.Crc32, F.Crc))
if(length(crc)>0, set('crc', '('+uc(crc)+')'))

// piece together the file name
set('filename', limit(limit(limit(atitle, 90) + ' - ' + epno + ' - ' + etitle, 190)  + ' ' + groupname, 235) + crc + '.' + F.FileType)

// Folder for first letter in anime title
set('head', copy(atitle, 90))
//if(numeric(head) or (head='.'), set('head', '0-9'))
set('head', head+'\')

// Subfolder for anime
set('head', head + limit(atitle, 90) + ' ' + '['+'anidb-'+A.Id+']' + '\')

// Prepend a subfolder for plot
//set('filename', if(A.Restricted, 'Hentai\') + head + filename)

// remove invalid characters
set('head', replace(head, '*', ' '))
set('head', replace(head, '/', ' '))
set('head', replace(head, '?', ' '))
set('head', replace(head, ':', ' '))
set('head', replace(head, '"', ' '))
set('head', replace(head, '<', ' '))
set('head', replace(head, '>', ' '))
set('head', replace(head, '|', ' '))
set('head', replace(head, '`', "'"))
set('head', replace(head, '  ', ' '))

head

// remove invalid characters
set('filename', replace(filename, '*', ' '))
set('filename', replace(filename, '/', ' '))
set('filename', replace(filename, '?', ' '))
set('filename', replace(filename, ':', ' '))
set('filename', replace(filename, '"', ' '))
set('filename', replace(filename, '<', ' '))
set('filename', replace(filename, '>', ' '))
set('filename', replace(filename, '|', ' '))
set('filename', replace(filename, '`', "'"))
set('filename', replace(filename, '  ', ' '))

filename
gcs8
Posts: 18
Joined: 06 Apr 2024, 15:17

Re: Rename folders only for HAMA by [anidb-###]

Post by gcs8 »

ok, sweet, now I have two ways to do this.

I had to modify yours a touch to play nice with HAMA + ASS.

Groovy: Select all

{
	def xml = xml('https://raw.githubusercontent.com/Anime-Lists/anime-lists/master/anime-list-full.xml')
	def aid = xml.anime.find{ it.name == n }.'@anidbid'
	n + ' [anidb-' + aid + ']'
}
Screenshot
Post Reply