Rename posters separated from the movies

All your suggestions, requests and ideas for future development
Post Reply
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Rename posters separated from the movies

Post by hama4reall »

So i have searched through the form and found one topic about renaming images but that topic had different use case my use case is i have a zip that contains all the posters (with somewhat random names) and a sheet that have all the name of the poster files and their movie names and year and tmdbid, to simplify the process for filebot i renamed the files to there movies names like for example:
Original file name:

Code: Select all

iron-sky-the-coming-race26.webp

Code: Select all

Iron Sky The Coming Race (2019).webp
using the sheet so filebot can match theme (i could add the tmdbid but i don't know if that makes filebot match precisely and where should i put it), i want to sort them out to the movies folders with the pattern i have in my filebot but it wont match the posters since they're *.webp now i have a workaround for this which is rename the extensions to *.mkv and then match it and sort them with filebot afterwards rename those *-poster.mkv to *-poster.webp but this is not a great solution for me since some movies might not exist and that will only create empty folder with just the poster inside
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

You can probably Plain File Mode to rename given files based on the information of your spreadsheet, i.e. CSV / TSV file.


e.g. use current file name as key to lookup some other value in a TSV table:

Format: Select all

{ csv('/path/to/spreadsheet.tsv')[fn] }
e.g. spreadsheet.tsv

Code: Select all

xyz	Avatar (2009)
:idea: This seems to be the first step of what you have already done. But you could extend this step (NOTE: much more use case details required from your side regarding input / output details) to lookup the corresponding movie file (NOTE: TMDB ID will be useful for that) and then have the format return the file path of that movie file (without extension) as target file path.




:idea: We assume that you you have all the *.webp files in some folder, separate from the movie files, linked to the movie file only via your spreadsheet. However, if the *.webp file is in the same folder as the movie file, then there are other options.
:idea: Please read the FAQ and How to Request Help.
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

Thanks for the reference but i want to sort them out to different folders like in my filebot format

Code: Select all

/Media/{f.path.match(/Badini/).upperInitial()}/{any { anime ? 'Anime' : '' }{ genres =~ /Animation/ ? 'Animation' : '' }}/{any {f.path.match(/Documentary/).upperInitial()}{ genre =~ /Documentary/ ? 'Documentary' : '' }}/{info.OriginalLanguage.toLocale().displayLanguage}/{~jellyfin.id}
According to this structure i want the posters to be sorted to but filebot won't match with TheMovieDatabase
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

And yes i have the posters in a different folder separated from the movie files
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

In a nutshell i want to extract information from TMDB and rename the files based on them, my sheet doesn't have all the info needed so I'm trying to use FileBot for that matter
And for matching the files with tmdb i have three columns (Movie Name, Release Year, TMDBid)
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

hama4reall wrote: 04 Oct 2023, 09:48 In a nutshell i want to extract information from TMDB and rename the files based on them, my sheet doesn't have all the info needed so I'm trying to use FileBot for that matter
And for matching the files with tmdb i have three columns (Movie Name, Release Year, TMDBid)
You cannot (easily) do that. You can however (easily) process files based on already previously processed files.


e.g.

Format: Select all

{
	// get movie ID for poster file at hand (assuming <TMDBID>.webp naming)
	// TIP: you could directly lookup the TMDB ID from your spreadsheet for the given *.webp file, 
	//      but you didn't provide a sample for your spreadsheet so we can't write code that reads that spreadsheet,
	//      so we assume file name = TMDB ID for example purposes here
	def mid = fn as int
	// find previously processed movie file with that ID and return the corresponding file path
	csv('/path/to/Movies').findResult{ f, m -> if (mid == m.id) f.dir / f.nameWithoutExtension }
}
-poster
e.g. sample companion files

Code: Select all

19995.webp
e.g. sample files with xattr metadata

Code: Select all

/path/to/Movies/Avatar (2009)/Avatar (2009).mp4
:idea: csv() can be used with a folder as argument (as opposed to a TSV text file) which then provides a File ➔ Metadata Object map of the folder contents.
:idea: Please read the FAQ and How to Request Help.
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

Sorry for not attaching the spreadsheet, Here is it:
https://drive.google.com/file/d/1A_M12B ... sp=sharing
Could you make an example from it I'm not experienced in java and coding in general
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

e.g.

Format: Select all

{
	def mid = csv('/path/to/ids.tsv')[f.name] as int
	csv('/path/to/Movies').findResult{ f, m -> if (mid == m.id) f.dir / f.nameWithoutExtension }
}
-poster
e.g. /path/to/ids.tsv

Code: Select all

chernobyl.webp	87108
** export the last 2 columns as TSV file to make it easier to read in the data from your format expression
:idea: Please read the FAQ and How to Request Help.
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

Ok i have been trying to make it work but the format gives this error:

Code: Select all

Expression yields empty value: Cannot invoke "java.lang.Integer.intValue()" because "
Yesterday the format were applied on half of the files but today after converting them from .webp to .jpg none of them can be applied all gives the error above.
The format i have applied is:

Code: Select all

{
	def mid = csv('/files/Movies.tsv')[f.name] as int
	csv('/Media/Movies/').findResult{ f, m -> if (mid == m.id) f.dir / 'poster' }
}
And the tsv file i use is:
https://drive.google.com/file/d/1iks8vA ... sp=sharing

My Movies Fomrat is:

Code: Select all

/Media/{f.path.match(/Badini/).upperInitial()}/{ hd == /UHD/ ? '4K Movies' : 'Movies' }/{f.path.match(/Short/).upperInitial}/{ genres =~ /Animation/ ? 'Animation' : '' }/{ genre =~ /Documentary/ ? 'Documentary' : '' }/{info.OriginalLanguage.toLocale().displayLanguage}/{~jellyfin.id}
I want the posters to go to

Code: Select all

/Media/Movies/{Movie Language}/{Movie Name} ({Year}) [tmdbid-{TMDBID}]/poster.jpg
I use filebot as xpra application
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

If you change the filename, then the filename no longer matches the filename in the TSV file and so the mapping no longer works.


:idea: You can use {fn} (name without extension) as key and remove all the .webp in your TSV file, to make sure the key in the format matches the key in the TSV file.


e.g.

Groovy: Select all

{
	def key = fn
	def value = csv('/files/Movies.tsv')[key]
	if (value == null) {
		throw new Exception("File '$key' is not on the list")
	}

	def mid = value as int
	def movieFile = csv('/Media/Movies/').findResult{ f, m -> if (mid == m.id) f }
	if (movieFile == null) {
		throw new Exception("ID '$mid' does not correspond to any file")
	}

	return movieFile.dir / 'poster'
}
/files/Movies.tsv

Code: Select all

romeo-and-the-black-brothers	35832
:idea: Adding error messages makes the code a bit longer. But just read it and it'll make sense.
:idea: Please read the FAQ and How to Request Help.
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

Oh, i just realized that. Thanks a lot for the extended code it works now after a quick find (.webp) & replace (.jpg) in the spreadsheet.
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

If you've got it working, please create a tutorial for the next guy. You've effectively created your own tool for your own ultra-specific use case, but others may be able to adapt and re-use for their ultra-specific use case. Typical users wouldn't expect this possible, much less in ~2 lines of code, so some documentation would be useful.
:idea: Please read the FAQ and How to Request Help.
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

Sure, when i finish sorting my Medias, i will ;)
hama4reall
Posts: 23
Joined: 13 May 2023, 12:21

Re: Rename posters separated from the movies

Post by hama4reall »

I have finished sorting the Movie's Posters, now i'm trying to sort the Show's posters but it gives `Expression yields empty value` with the format:

Code: Select all

`{
	def mid = csv('/files/unsorted/Shows.tsv')[f.name] as int
	csv('/Media/Shows/').findResult{ f, m -> if (mid == m.id) f.dir/ 'poster' }
}`
and the second format that contains error types it didn't work but the first one was really good for the movies, my Shows Format is Like so

Code: Select all

`/Media/{f.path.match(/Badini/).upperInitial()}/{ hd == /UHD/ ? '4K' : 'Shows'}/{any { anime ? 'Anime' : '' }{ genres =~ /Animation/ ? 'Animation' : '' }{f.path.match(/Documentary/).upperInitial()}{ genre =~ /Documentary/ ? 'Documentary' : '' }{info.OriginalLanguage.toLocale().displayLanguage}}/{~jellyfin.id}`
The tsv file is the same as the above (first Coloumn Contains File names, second Coloumn contain tmdbid)
User avatar
rednoah
The Source
Posts: 22999
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Rename posters separated from the movies

Post by rednoah »

:idea: You'll want to use the longer version so that you can get better error reporting, of course may need to be adjusted for your specific use case, file paths, TSV columns, etc:
viewtopic.php?p=61298#p61298


:idea: The if (mid == m.id) bit probably doesn't work for episodes, since you'll want to find episode files by series ID and not episode ID. Use if (mid == m.seriesInfo.id) instead. You may also need to modify the target file path bit, since you'll be searching for episode files, which are usually in a season folder, which is then in a series folder where your poster probably wants to go.


e.g.

Format: Select all

{
	def index = csv('/Media/TV Shows')
	def tsv = csv('/Files/Series.tsv')
	def key = f.name

	def value = tsv[key]
	if (value == null) {
		throw new Exception("File '$key' is not on the list")
	}

	def sid = value as int
	def episodeFile = index.findResult{ f, m -> if (sid == m.seriesInfo.id) f }
	if (episodeFile == null) {
		throw new Exception("ID '$sid' does not correspond to any file")
	}

	return episodeFile.dir.dir / 'poster'
}
:idea: Please read the FAQ and How to Request Help.
Post Reply