How about sharing your CLI scripts?

Running FileBot from the console, Groovy scripting, shell scripts, etc
Locked
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

How about sharing your CLI scripts?

Post by rednoah »

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?


Scripts and change logs are available on GitHub:
https://github.com/filebot/scripts


:idea: Scripts listed here can easily be called via -script fn:name. FileBot will automatically fetch and cache the script repository.

:idea: You can use -script dev:name to use the latest script from the development branch directly from GitHub.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Media Index TSV

Post by rednoah »

Description:
Write media info of all video files in the given folder to an easily readable TSV spreadsheet file.

Export media info for all files to a *.tsv file:

Shell: Select all

filebot -script fn:mi /path/to/media --output /path/to/media-index.tsv
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Fetch artwork and NFO files

Post by rednoah »

Description:
Fetch artwork for your movie folders, series folders and season folders from TheMovieDB or TheTVDB and generate movie and series *.nfo files.

Fetch movie artwork:

Shell: Select all

filebot -script fn:artwork.tmdb "/path/to/Movies"
Fetch series artwork:

Shell: Select all

filebot -script fn:artwork.tvdb "/path/to/TV Shows"
Options:
--q name force series or movie name (i.e. disable auto-detection)
-non-strict force non-interactive mode (default on headless machines)

Notes:
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Fetch artwork and NFO files (v2)

Post by rednoah »

Description:
Fetch artwork and generate *.nfo files for movie folders, series folders, season folders and episode files.

Fetch artwork:

Shell: Select all

filebot -script fn:artwork /path/to/media/
Generate NFO files:

Shell: Select all

filebot -script fn:nfo /path/to/media/
Notes:
  • This script does not parse or guess any information from the filename. Files that do not have xattr metadata will be ignored.
  • This script will fetch artwork and movie / series information from the database that was used when renaming the files as per xattr metadata.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

The Cleaner

Post by rednoah »

Description:
Delete clutter files like artwork, samples, etc in folders that have been left over after moving video files, but do not touch any file in any folder where there is at least one video file (that is larger than --def minsize) remaining.

Delete left-behind clutter files:

Shell: Select all

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

Advanced Options:
--def exts=pattern override default pattern for what extensions will be cleansed
--def terms=pattern override default pattern for for what paths will be cleansed
--def ignore=pattern paths that match this pattern will never be considered as clutter or deleted
--def minsize=bytes files smaller than minsize will be deleted as clutter regardless of extension (20 MB by default)
--def maxsize=bytes files larger than maxsize will never be deleted (120 MB by default)
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Query Rename History

Post by rednoah »

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.

Print the entire rename history:

Shell: Select all

filebot -script fn:history
Print rename history for the given files or folders:

Shell: Select all

filebot -script fn:history "/path/to/files"

Options:
-mediainfo <options> perform -mediainfo command on duplicate files
-rename <options> perform -rename command on duplicate files
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

View or Clear Extended Attributes

Post by rednoah »

Description:
If extended attributes are enabled and supported on your platform and filesystem FileBot will store original filename and episode/movie metadata into extended attributes for future reference by FileBot or other applications. This script allows you to view and clear these extended attributes.

View xattr for files:

Shell: Select all

filebot -script fn:xattr /path/to/files
Clear xattr from files:

Shell: Select all

filebot -script fn:xattr /path/to/files --action clear
Prune orphaned .xattr folders where the corresponding media file no longer exists:

Shell: Select all

filebot -script fn:xattr /path/to/files --action prune
Reverse rename previously renamed files to their original filenames based on original filename xattr:

Shell: Select all

filebot -rename -r /path/to/files --db xattr --format "{original}"
View FileBot xattr metadata in json format:

Shell: Select all

filebot -mediainfo -r /path/to/files --format "{json}"
Options:
--action clear Clear xattr metadata
--action prune Delete orphaned .xattr folders
--action import Import xattr metadata into macOS Finder tags
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Fetch subtitles for all files

Post by rednoah »

Description:
If you want to download subtitles for more than just a single folder then -get-subtitles -r in one batch with many many files can be a bad bad idea. This script will fetch subtitles folder per folder to make fetching large amounts of subtitles more reliable. Files may be included or excluded based on file creation date, last modified date, file size, video length, embedded subtitles, etc

:!: If you call this script repeatedly on the same folders or files then you MUST SET --def maxAgeDays to 30 days or less and call it no more than once per day.

Fetch subtitles for all files that have recently been created:

Shell: Select all

filebot -script fn:suball /path/to/media -non-strict --def minAgeDays=1 maxAgeDays=7
Fetch subtitles for all files:
You must not lookup subtitles for all files repeatedly in any kind of automated setup, or you will get banned. If you use the suball script in an automated setup then you MUST SET --def maxAgeDays to 30 days or less.

Shell: Select all

filebot -script fn:suball /path/to/media

Files will be ignored and excluded from processing if one of the following conditions holds true:
  • file path matches your --def ignore pattern
  • time passed since file last-modified date is more than --def maxAgeDays
  • time passed since file last-modified date is less than --def minAgeDays
  • file size is less than --def minFileSize
  • video duration is less than --def minLengthMS
  • video file already contains embedded subtitles in a language matching your --def ignoreTextLanguage pattern (by default no additional subtitles are fetched if there already are embedded subtitles of any language)

Options:
--lang zho set preferred subtitle language (default: eng)
-non-strict enable Fuzzy Search (default: Exact Search)
--def maxAgeDays=7 set a max-age for files that will be processed, older files will be ignored
--def minAgeDays=1 set a min-age for files that will be processed, newer files will be ignored (so better subtitles can be downloaded later)
--def minFileSize=0 set a minimum file size, smaller files will be ignored (default: 50 MB)
--def minLengthMS=0 set a minimum video duration, shorter videos will be ignored (default: 10 min)
--def ignore=regex set an ignore pattern for paths that should be ignored
--def ignoreTextLanguage=regex set an ignore pattern for video files that already contain embedded subtitles in certain languages (default: en)
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Verify File Integrity

Post by rednoah »

Description:
This script can be used to verify file integrity over time. On the first run the CRC32 checksum will be stored as xattr metadata. In subsequent runs the original checksum can then be compared to the actual checksum.


Calculate CRC32 and compare it to the previously stored checksum:

Shell: Select all

filebot -script fn:verify /path/to/files
Options:
--log warning print only important output (such as when a CRC32 mismatch is found, or CRC32 metadata is initialized for the first time)

Notes:
  • The initially computed CRC32 checksum will be stored as text value in the xattr field "CRC32" so the checksum will also be instantly available when using {crc32} in the format.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Find missing Episodes

Post by rednoah »

Description:
Finding missing episodes is easy once all your content has been renamed and xattr tagged with FileBot. This script will cross-check your files with the online episode data and tell you which episodes are missing.


Find missing episodes:

Shell: Select all

filebot -script fn:miss /path/to/media
Options:
--log OFF print only missing episodes

Notes:
  • This script does not parse or guess any information from the filename. Files that do not have xattr metadata will be ignored.
  • This script additionally checks for changes in metadata where previously stored xattr metadata does not exactly match current online episode metadata. (e.g. find files where the episode title was changed in the online database)
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Find Duplicate Movie or Episode Files

Post by rednoah »

Description:
Finding duplicate movie or episode files is easy once all your content has been renamed and xattr tagged with FileBot. This script allows you to view or delete duplicates.


List Logical Duplicates:

Shell: Select all

filebot -script fn:duplicates /path/to/files
:idea: There are logical duplicates when multiple files refer to the same movie or episode (e.g. 720p, and 1080p and 4K versions of the same movie or episode).


List Logical Duplicates per Video Format:

Shell: Select all

filebot -script fn:duplicates /path/to/files -non-strict
:idea: There are logical duplicates per video format when multiple files refer to the same movie or episode and have the same video format (e.g. multiple 1080p versions of the same movie or episode).


List Binary Duplicates:

Shell: Select all

filebot -script fn:duplicates --mode binary /input /output /backup
:idea: There are binary duplicates when multiple files are identical byte for byte (i.e. copies of the same file).


Options:
--action delete delete duplicate files
-non-strict allow one logical duplicate per video format
-mediainfo <options> perform -mediainfo command on duplicate files
-rename <options> perform -rename command on duplicate files


Advanced Options:
--order input sort duplicates by input argument order (default in --mode binary)
--order quality sort duplicates by highest quality first (default in --mode logical)
--order date sort duplicates by least recently created (according to Media Encoding Date or File Creation Date)
--order time sort duplicates by least recently modified (according to File Last-Modified Date)


Notes:
  • In --mode logical, as per --order quality, the --action delete option will keep only the one file with the highest video quality.
  • In --mode logical, this script will not parse or guess any information from the filename. Files that do not have xattr metadata will be ignored. Please read the addendum for details.
  • In --mode binary, as per --order input, the --action delete option will keep only the first occurrence of a file according to the input argument order.
  • In --mode binary, this script may read files partially or entirely to compute checksums, which are then stored as xattr to speed up subsequent runs.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Write Embedded Tags

Post by rednoah »

Description:
Write embedded mp4 and mkv tags to the file content based on existing xattr metadata.

Write Embedded Tags:

Shell: Select all

filebot -script fn:tags /path/to/files
:!: Beware! You are modifying files! Proceed with caution!

:!: Be aware of symlinks and hardlinks (i.e. one file accessible via multiple different file paths) when modifying file contents.


Notes:
  • This script requires the mkvpropedit (i.e. mkvtoolnix package) and AtomicParsley (i.e. atomicparsley package) command-line tools to write embedded mkv and mp4 tags. If mkvpropedit or AtomicParsley are not in the $PATH then you can specify the absolute path to the executable via the --def mkvpropedit and --def atomicparsley script parameters:

    Shell: Select all

    --def mkvpropedit="C:/Tools/mkvpropedit.exe" --def atomicparsley="C:/Tools/AtomicParsley.exe"
  • This script will not parse or guess information from the filename. Files that do not have xattr metadata will be ignored.
  • Embedded MP4 or MKV tags are rare an uncommon. There is no established standard for tagging video files. MP4 tagging usually (but not necessarily) refers to iTunes-style metadata. MKV tagging (1, 2) is generally useless because the media player you use (i.e. Plex, Emby, Kodi, etc) likely doesn't use mkv metadata, other than the media title property. Please read the tags script for details.
:idea: Please read the FAQ and How to Request Help.
User avatar
rednoah
The Source
Posts: 22898
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Export selected files as ZIP archive

Post by rednoah »

Description:
Pack selected files into a new zip archive.

Select *.nfo and *.url files and pack them into a new zip archive:

Shell: Select all

filebot -script fn:zip -d /path/to/files --filter "ext =~ /nfo|url/" --output "Companion Files.zip"
Select *.log files from a specific year and pack them into a new zip archive:

Shell: Select all

filebot -script fn:zip -d /path/to/files --filter "ext =~ /log/ && f.lastModified().toDate(/UTC/).year == 2021" --output "Logs 2021.zip"
Export filebot cache for debugging purposes:

Shell: Select all

filebot -script fn:zip -d "%APPDATA%/FileBot" --filter "f =~ /cache/" --output "%USERPROFILE%/Desktop/FileBot Cache.zip"
Options:
-d retain directory structure (i.e. remove -d to flatten the zip file structure)
:idea: Please read the FAQ and How to Request Help.
Locked