Hello everyone,
I'm currently working on a FileBot script for post-processing my movie collection, and I'm facing a specific challenge that I need assistance with. I hope some experienced FileBot users here can help me out.
Background:
I have a large collection of movies that I want to organize into folders based on their original language using FileBot. Additionally, I want to ensure that the file naming follows the Plex movie naming conventions. To achieve this, I've created two separate scripts: one for fetching movie details from TMDb and another for applying the Plex formatting.
The Challenge:
I'm having trouble getting these two scripts to work together within FileBot. Specifically, I want to ensure that the movie details are fetched from TMDb, and then the Plex formatting is applied to the renamed files in the correct language-based folders.
Current Setup:
Here's my current setup:
I have a script that fetches movie details from TMDb and organizes the files into language-based folders, but it doesn't apply Plex formatting.
I have a preset in FileBot that applies Plex formatting, but it doesn't organize the files into language-based folders.
What I Need:
I need a way to combine these two scripts so that I can fetch movie details from TMDb, apply Plex formatting, and ensure the files are organized correctly into language-based folders.
Questions:
Is it possible to create a wrapper script that combines the TMDb fetching and Plex formatting logic?
How can I set up FileBot to ensure this wrapper script runs as a post-processing step after applying the Plex preset?
Are there any examples or templates available that I can use as a starting point for this combined script?
I would greatly appreciate any guidance, examples, or suggestions from the community on how to tackle this challenge effectively. Thank you in advance for your help!
Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting
Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting
You'll want to express the target file path you want via your custom format, and then let FileBot move / rename files accordingly, no need for multiple custom scripts, just one filebot command:
Note that Plex will expect that en is added as Movie folder, so you'll have to add each language folder as Movie folder to your Movies library if you follow this naming scheme.
Console Output: Select all
$ filebot -rename -r ./input --db TheMovieDB --output ./output --format "{info.OriginalLanguage}/{~plex.id}" --action TEST --log INFO
[TEST] from [input/Avatar.2009.mp4] to [output/en/Avatar (2009) {tmdb-19995}/Avatar (2009).mp4]

Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting
Is there a way to do it on the filebot UI? I'm not running filebot as a script but using file-bot node as a program in my synology NAS?
I'm trying to do the following as a post-process after renaming the files per the preset according to plex format:
I'm trying to do the following as a post-process after renaming the files per the preset according to plex format:
Groovy: Select all
// Set your TMDb API key
def apiKey = "e90fd22e1f7a120d5703975fac12501e"
// TMDb API base URL
def tmdbBaseUrl = "https://api.themoviedb.org/3"
// Mapping of Plex movie formatting language codes to full language names
def languageMap = [
"en": "English",
"hi": "Hindi",
"te": "Telugu",
// Add more languages here...
]
// Function to fetch movie details
def fetchMovieDetails = { movieTitle ->
def encodedMovieTitle = URLEncoder.encode(movieTitle, "UTF-8")
def tmdbUrl = "${tmdbBaseUrl}/search/movie?api_key=${apiKey}&query=${encodedMovieTitle}"
def response = new URL(tmdbUrl).getText()
def searchResults = new groovy.json.JsonSlurper().parseText(response)
if (!searchResults.results.isEmpty()) {
def movie = searchResults.results[0]
return movie
} else {
return null
}
}
// Define the root destination folder where you want to organize your movies
def destinationRoot = "G:\\Media\\OrganizedMovies"
// Get the original language code from the file path using Plex naming convention
def getOriginalLanguageCode = { filePath ->
def matcher = filePath =~ /\/(en|hi|te)\//
return matcher ? matcher[0][1] : null
}
// Main script execution
def organizeMovies = { file, movieTitle ->
def movieInfo = fetchMovieDetails(movieTitle)
if (movieInfo) {
def originalLanguageCode = getOriginalLanguageCode(file.toString())
def originalLanguage = languageMap.getOrDefault(originalLanguageCode, "Unknown")
def destinationLanguageFolder = new File("${destinationRoot}\\${originalLanguage}")
if (!destinationLanguageFolder.exists()) {
destinationLanguageFolder.mkdirs()
}
def movieFolderName = movieInfo.title ?: "Unknown Movie"
def destinationMovieFolder = new File("${destinationLanguageFolder}\\${movieFolderName}")
if (!destinationMovieFolder.exists()) {
destinationMovieFolder.mkdirs()
}
def destinationFilePath = "${destinationMovieFolder}\\${file.name}"
file.renameTo(new File(destinationFilePath))
println "Moved '${file.name}' to '${destinationMovieFolder}\\'"
} else {
println "Movie details not found for '${movieTitle}'. '${file.name}' was not moved."
}
}
// Process the incoming file list
def movieFiles = args*.toFile()
movieFiles.each { movieFile ->
def movieTitle = movieFile.name - ".mkv"
organizeMovies(movieFile, movieTitle)
}
Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting

Format: Select all
/path/to/Media/{info.OriginalLanguage}/{~plex.id}

Format: Select all
/path/to/Media/
{
// split by either Windows \ or Unix /
def folders = folder.path.split(/\\|\//)
if ('en' in folders)
return 'English'
if ('hi' in folders)
return 'Hindi'
if ('te' in folders)
return 'Telugu'
return 'Unknown'
}
/
{ ~plex.id }


EDIT:

Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting
I'm testing the script in my windows machine for now and will test it in my NAS after modifying it per Linux paths. I did try ChatGPT to modify my basic code but will try what you've suggested with the formats in the UI.
Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting
Also, what should I do if the movie info is not found by the script? How do I handle that scenario?
Re: Subject: Need Help with FileBot Script to Organize Movies by Language and Plex Formatting

