Board index Scripting and Automation How about sharing your CLI scripts?

How about sharing your CLI scripts?

Running FileBot from the console, Groovy / FileBot scripting, shell scripts, etc

rednoah User avatar
The Source

Posts: 2145
Location: 北京

FileBot has introduced it's own integrated Groovy script engine so you can easily script things and then share that with people on any platform. So if you have come up with some nice scripts, why not share them with people here?

Script Index:

I'll add the really useful / interesting ones to the script repository:
http://filebot.net/scripts/

Revision history and change logs:
https://sourceforge.net/p/filebot/code/HEAD/tree/trunk/website/scripts/

TIP: Scripts listed here can easily be called via -script fn:name, e.g. fn:name will resolve to http://filebot.net/scripts/name.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 10 Dec 2011, 10:16
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
  1. Unrar completed downloads and delete archive volumes after extraction
  2. Fetch subtitles
  3. Sort/move/rename files into the given folder structure
  4. Notify XBMC about updates
Download Script:
http://filebot.net/scripts/sorty.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 10 Dec 2011, 10:25
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
  1. Write media info of all video files in the given folder and subfolders to an easily readable CSV file (e.g. open in Excel)
Usage:
filebot -script fn:mi /path/to/media/ "MediaIndex.csv"

Download Script:
http://filebot.net/scripts/mi.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2145
Location: 北京

For this tasks there is actually two different scripts. One that actually hooks into the OS watching folders for changes (requires Java 7) and one that just organized everything in now and then in an predefined interval.

*** Note that these two scripts here are console-interactive so you must not redirect I/O ***

:arrow: watcher.groovy (Java 7+)
Description:
  1. Hook into the OS and recieve File modification events. Start organizing files once there are no changes for more than 5 seconds
  2. The script supports extracting archives, downloading subtitles and organizing video files. Each feature can be enabled or disabled by setting or not setting the -extract, -get-subtitles and -rename cmdline flags.
Usage:
filebot -script fn:watcher -extract -rename /path/to/completed/ --output /final/destination/ --format "TV Shows/{n}/Season {s}/{n} {sxe} {t}" --db TheTVDB

Download Script:
http://filebot.net/scripts/watcher.groovy


:arrow: housekeeping.groovy
Description:
  1. Watch folder by checking for new files every 5 minutes
  2. The script supports extracting archives, downloading subtitles and organizing video files. Each feature can be enabled or disabled by setting or not setting the -extract, -get-subtitles and -rename cmdline flags.
Usage:
filebot -script fn:housekeeping -extract -rename /path/to/completed/ --output /final/destination/ --format "Movies/{n} {y}/{n} ({y}){" CD$pi"}" --db TheMovieDB

Download Script:
http://filebot.net/scripts/housekeeping.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
  1. Download artwork for all your TV Shows from TheTVDB. Fetch tvshow nfo, series and season artwork and save files according to XBMC standards.
  2. Disable confirmation dialogs via -non-strict option (on headless machines this is the default).

Usage:
filebot -script fn:artwork.tvdb /path/to/tvshows/


Options:
--q name to force search query manually instead of auto-detection
--conflict override to fetch artwork from scratch and not just missing artwork
-non-strict to disable user-interaction and run headless

Notes:
* Episodes are expected to be organized into Show/Season N/Episode XY structure. The TV Show will be auto-detected from files and the folder structure.

Download Script:
http://filebot.net/scripts/artwork.tvdb.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
  1. Download artwork for all your Movies from TheMovieDB. Fetch Movie nfo and all kinds of artwork and save files according to XBMC standards.
  2. Disable GUI tv series confirmation dialogs via -non-strict option (on headless machines this is the default).

Usage:
filebot -script fn:artwork.tmdb /path/to/movies/


Options:
--conflict override to fetch artwork from scratch (not just missing artwork)
-non-strict to disable user-interaction and run headless

Notes:
* Movies are expected to be organized into folders. The movie is determined using the name of the parent folder of each video file.

Download Script:
http://filebot.net/scripts/artwork.tmdb.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 04 Mar 2012, 04:20
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Sort out various movie and tv series files that are all in the same folder.

1. Check each file and figure out whether it is a movie file or an episode file and handle it accordingly.
2. Move / Rename according to the given movie or episode naming scheme.

Note:
Even if there is very little information (e.g. movie name without year, series name and episode title without SxE or original airdate) this script will still work, except there is multiple options (e.g. Serenity.mkv => Serenity (2003), Serenity (2005), etc) in which case you may need to specify -non-strict.

filebot -script fn:sortivo <folder> [-non-strict] [--output path/to/folder]

Download Script:
http://filebot.net/scripts/sortivo.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 26 Apr 2012, 16:34
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Here's a script that you can use with µTorrent as "Run program when torrent finishes" command to automatically sort out your downloads. Basically it's a combination of sorty, sortivo, artwork.* plus some code for µTorrent specific input.

The utorrent-postprocess / amc script has out grown these little scripts here and has become a key filebot feature by itself. It's got it's own thread here now:
http://filebot.sourceforge.net/forums/v ... 1561#p1561
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 21 Jul 2012, 09:50
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
  1. Delete clutter files like artwork, samples, etc in folders that have been left over after moving video files.
  2. Won't touch any file in folders where there is at least one video file.

Usage:
filebot -script fn:cleaner /path/to/media/


Options:
--action test only print files that would be deleted, but don't actually do anything
--def root=y Delete given folder as well if left empty
--def "exts=jpg|nfo|etc" pattern for what extensions will be cleansed
--def "terms=sample|trailer|etc" pattern for for what paths will be cleansed (only applies to files smaller than 100 MB)

Download Script:
http://filebot.net/scripts/cleaner.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 13 Oct 2012, 04:58
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
Regular-expression based mass-rename utility, FileBot style! Find & Replace is applied to the absolute path and not just the filename so you can restructure your folder hierarchy as well.

Simple Usage:
filebot -script fn:replace --def "e=.eng.srt" "r=.srt" /path/to/files


Advanced Usage:
filebot -script fn:replace --action copy --filter "[.]srt$" --def "e=[.](eng|english)" "r=.en" /path/to/files


Options:
--action test only print files that would be moved/copied
--conflict override allow override destination file if it already exists, otherwise it'll be skipped
--filter pattern process only files matching the given pattern

Download Script:
http://filebot.net/scripts/replace.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
This simple rename script will run through all folders and rename process everything folder by folder. It's pretty much like running filebot -rename <folder> for each folder. There is series/movie detection but it's very basic, so it's recommended to force a specific mode via setting --db <datasource>.

Rename episode or movie files:
filebot -script fn:renall "path/to/media" -non-strict


Rename movie folders:
filebot -script fn:renall "path/to/movies" -non-strict --db TheMovieDB --def target=folder


It's highly recommended to first do a dry-run in TEST MODE and see what would happen. Here's the options for that:
--action test --log info


Options:
--def target=folder rename movie folders as a whole instead of the files inside. This mode requires that each movie is already placed in its own folder.

Download Script:
http://filebot.net/scripts/renall.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 13 Nov 2012, 12:41
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names or just want to find out the original name of a given file. Here's a script to help with that.

Print the entire rename history:
filebot -script fn:history

Print rename history for the given files or folders:
filebot -script fn:history "X:/path/to/files"


Options:
--format specify your own line format, e.g. --format "${from}\t${to}" if you want tab-separated paths

Download Script:
http://filebot.net/scripts/history.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
FileBot keeps an internal history of all rename operations in case you want to revert files to their original names. Run this script on the specified file or folder and revert all files to their original names.

Revert files to their original paths:
filebot -script fn:revert path/to/files


Options:
--action define revert operation, e.g. --action move (default) will move files back to their original location whereas --action rename will only change the filename back to the original filename but keep the file in it's current folder. You can run the script in test mode via --action test.

Download Script:
http://filebot.net/scripts/revert.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

Post 06 Dec 2012, 20:37
rednoah User avatar
The Source

Posts: 2145
Location: 北京

Description:
Here's a script for automatically updating your MyEpisodes profile. On http://www.myepisodes.com you can keep track of your favorite shows, what episodes you have already aquired/watched and quickly check just how much time you've been wasting on watching TV. If your files are already reasonably well-named you can just run this script and it will add all your shows that are not on your list yet and tick each episode you have as 'acquired'.

Add shows and mark episodes as 'acquired':
filebot -script fn:update-mes "X:/path/to/episodes" --def login=user:pwd addshows=y


Options:
--def addshows=y|n auto-add new shows to your list or just ignore any show that is not on your list
--def tick=acquired|seen define whether episodes should be ticked as 'acquired' or 'watched'

Download Script:
http://filebot.net/scripts/update-mes.groovy
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image


Posts: 5
On "Rename All Media Folder by Folder":

1. The script is not renaming the media files inside folders for me.

2. Some titles get renamed to their English equivalent, some don't (even when available).

e.g. "Kasi az gorbehaye irani khabar nadareh" doesn't rename to "No One Knows About Persian Cats" (http://www.imdb.com/title/tt1426378/)

I'm using IMDB as source.

rednoah User avatar
The Source

Posts: 2145
Location: 北京

1. It's not supposed to. Just run it twice if you first wanna rename folders and then files. If you restructure your stuff you'd normally define a format for that and move everything into the new structure rather then renaming files in place.

2. Depends on the database you're using. TMDB respects the --lang option. With IMDb you'll get what you get regardless of your prefs.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

d3x

Posts: 7
http://filebot.net/scripts/artwork.tmdb.groovy

I have all my movies in one folder. I am trying to modify the script to work with my setup but am failing horribly. I also only want the XML information and a single poster for each both (named the same as the movie just with .xml and .jpg extensions.)

rednoah User avatar
The Source

Posts: 2145
Location: 北京

The artwork.* scripts define mostly how the folder structure is traversed and how movie/series detection works. The actual artwork downloading and naming is all in the lib/htpc include.

Best thing to do is to organize each movie into it's own folder.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

d3x

Posts: 7
I can read the scripts no problem I just can't write changes very well as my Java is weak and Groovy is non existent.

options = options.sortBySimilarity(query, { it.name })


Where is sortBySimilarity defined? Does it.name really need the { and } around it?

rednoah User avatar
The Source

Posts: 2145
Location: 北京

Here's the stuff I pre-define:
https://sourceforge.net/p/filebot/code/ ... force=True

The { ... } is the toString function used for comparison. It's passing in a function, not a value. So you need the { ... }
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

d3x

Posts: 7
args.getFiles{ it.isVideo() }
.each{
def movieName = detectMovie(it, false)
def movieInfo = TheMovieDB.searchMovie(movieName.name, _args.locale).sortBySimilarity(movieName.name, {it.name})[0]
println movieInfo
}


Seems to be working okay except Kiss.Kiss.Bang.Bang.2005.DVDRip.x264.AC3-SiC.mp4 is being identified as Kiss Kiss... Bang Bang (1966)

rednoah User avatar
The Source

Posts: 2145
Location: 北京

You first have filebot correctly detect it as Kiss Kiss Bang Bang (2005) via detectMovie(), then you go on and take only the movie name Kiss Kiss Bang Bang and do another search, that is completely useless btw, at best giving you the same result, at worst a different movie.

You only need detectMovie() and it'll get you the best-guess movie object with name/year/tmdbid.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

d3x

Posts: 7
args.getFiles{ it.isVideo() }
.each{
def movieName = detectMovie(it, false)
println movieName
def movieInfo = TheMovieDB.searchMovie(movieName.name, _args.locale)
println movieInfo
println movieInfo.sortBySimilarity(movieName.toString(), {it.name})
}


Kiss Kiss Bang Bang (2005)
[Kiss Kiss... Bang Bang (1966), Kiss Kiss Bang Bang (2005), Kiss Kiss (Bang Bang) (2001)]
[Kiss Kiss... Bang Bang (1966), Kiss Kiss Bang Bang (2005), Kiss Kiss (Bang Bang) (2001)]


sortBySimilarity is not working movieName.toString() is exactly "Kiss Kiss Bang Bang (2005)" yet it does not move it to the front of array.

rednoah User avatar
The Source

Posts: 2145
Location: 北京

It's sorting by the text similarity of movieName.toString() and it.name, since the ... is ignored both match equally by name, and since you do it.name you specifically make sure the year part is not part of the equasion. Just do sortBySimilarity(string) and let it use the default toString function for the comparison value.

Also, detectMovie already gives you the best result. If you use detectMovie it's a complete waste to do a TMDb.searchMovie afterwards. It's probably called internally as part of detectMovie already anyway, relevance sorting as well.
FileBot is free software. Please help support FileBot by writing a review or considering a donation.
Image

d3x

Posts: 7
I am doing TMDb.searchMovie() because I would like to pull a couple more details but I think I will just write the movie name to file then use a more reasonable language to do the rest like I had originally planned.

import groovy.json.JsonBuilder
args.getFiles{ it.isVideo() }.each{
 def f = new File(it.name[0..-5] + '.json')
 if (f.exists())
  return
 def m = detectMovie(it, false)
 f.write(new JsonBuilder(m).toPrettyString())
}


Thanks for all the help and fast replies

Edit: I just realized detectMovie gets the tmdbId so I can just use TheMovieDB.getMovie() lol

Next

Return to Scripting and Automation