This is a little ruby tool to automatically rename TV Show video files (according to my naming preference) and move them to the appropriate directory for Plex to index.
This took takes an input folder and output folder, then it:
- looks for files with extension
mp4,m4v,aviormkvin the input folder (discarding filenames containingSample) - parses the file name to extract the TVShow name, season number and episode number.
(To do that, it expects the file name to matchShow.Name.S01E02.Anything.ext) - fetches the name of the episode using TheTVDB API
- renames the file to
Show Name - 1x02 - Episode Title.extand moves it to the subfolderShow Name/Season 1/of the output folder.
- the
TheTVDBAPI needs an API Key to use it. You need to get one and write it to a file namedthetvdb.apikeysaved next to the other files so that the script can use it. - Then use
tvshows_organizer.rbas the entry point, invoked either from ruby code (usingTVShowsOrganizermodule) or from the command line
require 'tvshows_organizer'
# Search the TheTVDB's show ID of a given show
TVShowsOrganizer::run_query(:query => 'Game of Thrones')
# Add a show to the shows.yml database
TVShowsOrganizer::add_show(:name => 'Game of Thrones', :id => '121361')
# Move video files to destination, renaming them appropriately.
TVShowsOrganizer::move_files(source_dir, dest_dir, :interactive => true)Use tvshows_organizer.rb --help to know how to use it and which options are available.
# Search the TheTVDB's show ID of a given show
$ ./tvshows_organizer.rb -q "House of Cards"
# Add a show to the shows.yml database: use query + interactive mode
$ ./tvshows_organizer.rb -qi "House of Cards"
# Move video files to destination, renaming them appropriately.
$ ./tvshows_organizer.rb -i source_dir dest_dir