Package: media-management-scripts
Media Management ScriptsThis is a collection of command line tools for managing media files such as movies or TV shows.It also simplifies some common tasks such as converting files by wrapping complexffmpegcommands.For example, to convert a file to H.265/HEVC with GPU acceleration and AAC audio, plus scale it down to 480p, you would normally have to run a command like:ffmpeg-hwaccelcuda-hwaccel_output_formatcuda-itest.mp4-vfscale=-1:480-c:vh264_nvenc-presetfast-c:aaac-c:scopy-map0out.mp4Using this toolkit, it would be this instead:manage-mediaconvert--hw-nv--scale480--vch264test.mp4out.mp4InstallationInstall the tools:pip install media_management_scriptsYou also need to installffmpeg(for most commands) anddialog(for a few commands).MacOSbrew install ffmpeg dialogDebian/Ubuntusudo apt update && sudo apt install ffmpeg dialogMost distros have an older version offfmpeg(which should still work!). You can install a newer version by following the instructionshere.TVDBIf you want to use TVDB for some commands, create an account onhttps://www.thetvdb.comand create a legacy API keyhereCreate a file~/.config/tvdb/tvdb.iniwith contents:[tvdb]username=<your_user_name>userkey=<your_user_key>apikey=<your_api_key>UsagePass--helpto the subcommands for detailed help. Major features are explained in detail below.Most commands that rename or move files have a dry-run mode (-nor--dry-run) which will output the actions without executing so you can verify the plan.Main toolsconvertmetadatarenamesearchtv-renameHelp outputusage: manage-media [-h] [-v]

Sub commands
    create-test-video   Create a test video file with the specified definitions
    combine-subtitles   Combine a video files with subtitle file
    combine-all         Combine a directory tree of video files with subtitle file
    concat-mp4          Concat multiple mp4 files together
    convert             Convert a file
    executables         Print the executables that will be used in other commands
    find-episodes       Find Season/Episode/Part using file names
    itunes              Attempts to rename iTunes episodes to the standard Plex format.
    metadata            Show metadata for a file
    compare             Compare metadata between files
    compare-directory   Compare metadata for files in a directory
    movie-rename        Renames a file based on TheMovieDB
    rename              Renames a set of files to the specified template
    search              Search for video files matching the specified parameters
    select-streams      Extract specific streams in a video file to a new file
    subtitles           Convert subtitles to SRT
    thumbnail           Extract a number of thumbnails from a video
    tv-rename           Renames files in a directory to sXXeYY. Can also use TVDB to name files (<show> - SxxeYY - <episode_name>)

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Display versionconvertmanage-media convert <input> <output>Convert a video file to different video or audio codecs. By default if no codecs are given, the file will be converted to H.264 with AAC audio.The source file is left intact.Examples:Convert to H.264manage-media convert --video-codec h264 <input> <output>Convert to HEVC/H.265:manage-media convert --video-codec hevc <input> <output>Convert to HEVC with AC3 audio:manage-media convert --video-codec hevc --audio-codec ac3 <input> <output>Convert to HEVC, but don't convert audio:manage-media convert --vc hevc --ac copy <input> <output>Scale to 480pmanage-media convert --scale 480  <input> <output>Convert to H.264 and remove interlacing (such as on mpeg2 DVDs)manage-media convert --vc h264 --deinterlace  <input> <output>Convert a whole directory of filesmanage-media convert --vc h264 --bulk <input dir> <output dir>Extract a portion of the videomanage-media convert --vc copy --ac copy --start 3m45s --end 10m00s <input> <output>Hardware AccelerationIf yourffmpegsupports it, you can use NVIDIA GPU hardware acceleration to speed up the conversion. You can see the supported codecs for decoding & encoding for each GPUhere.To use this, just add--hardware-nvidiaor--hw-nvto themanage-media convertcommand.manage-media convert --hw-nv --video-codec hevc --audio-codec ac3 <input> <output>metadataGet a simple output of metadata for a file. Or get lots of metadata in json formatSimple outputmanage-media metadata <input>Battlestar Galatica (2003) - s00e01 - Battlestar Galactica The Miniseries (1).mkv
   Directory: /Volumes/Media/TV Shows/Battlestar Galactica/Season 0/
   Title: Battlestar Galactica: Season 1 (Disc 1)
   Size: 6.8GB
   Format: matroska,webm
   Duration: 1h34m39s
   Bitrate: 10117 Kbps
   Video: h264 8 bit (1920x1080)
   Audio:
     aac (eng, 5.1)
   Subtitles: eng, spa, fra
   Ripped: TrueJsonmanage-media metadata --json <input>{"file":"/Volumes/Media/TV Shows/Battlestar Galactica/Season 0/Battlestar Galatica (2003) - s00e01 - Battlestar Galactica The Miniseries (1).mkv","title":"Battlestar Galactica: Season 1 (Disc 1)","duration":5679.362,"duration_str":"1h34m39s","size":7354722701,"size_str":"6.8GB","resolution":"HIGH_DEF","bit_rate":10359928,"bit_rate_str":"10117 Kbps","ripped":true,"format":"matroska,webm","format_long_name":"Matroska / WebM","mime_type":"video/x-matroska","tags":{"title":"Battlestar Galactica: Season 1 (Disc 1)","RIPPED":"true","ENCODER":"Lavf57.56.100"},"video_streams":[...],"audio_streams":[...],"subtitle_streams":[...],"other_streams":[...],"chapters":[...],"interlace":null}renamemanage-media rename <template> <input file>ormanage-media rename --recursive <template> <input directory>A flexible tool to rename files based on a template.Templates can include variables or expressions by surrounding with ${...}. Functions can be called like${upper(i)}or${i | upper}.The following variables are available:i/index- The index of the current file being renamedwo_ext- The file name basename without the extensionext- The file extension of the current file (without '.')filename- The filename of the current file (basename)re/regex- A list of regex match groups (usere[0],re[1], etc)The following functions are available:upper- Upper cases the inputlower- Lower cases the inputifempty(a, b, c)- If a is empty or null, then b, otherwise clpad(a, b:int)- Left pads a to length b (defaults to 2+) with spaceszpad(a, b:int)- Left pads a to length b (defaults to 2+) with zeroslpad/zpad- By default pads to at least 2 characters. If there are 100+ files, then 3 characters, 1000+ files, then 4 characters, etc.Regular Expressions:
If a regex is included, the match groups (0=whole match, >0=match group) are available in a list 're' or 'regex'.
Each match group is converted to an int if possible, so a zero padded int will lose the zeros.Example Templates:Input: S02E04.mp4
Regex: S(\d+)E(\d+)

Template: 'Season ${re[1]} Episode ${re[2]}.{ext}'
Result: 'Season 2 Episode 4.mp4'

Template: 'Season ${re[1] | zpad} Episode ${zpad(re[2], 3)}.{ext}'
Results: 'Season 02 Episode 004.mp4'Input: whatever.mp4
Regex: S(\d+)E(\d)
Template: 'Season ${ifempty(re[1], 'unknown', re[1])} Episode ${re[2]}.{ext}'
Result: 'Season unknown Episode .mp4'searchmanage-media search <input directory> <query>Searches a directory for video files matching parameters. Note: this can take a LONG time as it has to read the metadata for each file.
You can speed up multiple searches in the same directory with--db <filewhich caches the metadata.If a video has multiple streams, comparisons mean at least one stream matches.Available parameters:Video:v.codec- The video codec (h264, h265, mpeg2, etc)v.width- The video pixel widthv.height- The video pixel heightAudio:a.codec- The audio codec (aac, ac3)a.channels- The number of audio channels (stereo=2, 5.1=6, etc)a.lang- The language of the audio trackSubtitles:s.codec- The subtitle codec (srt, hdmv_pgs, mov_text, etc)s.lang- The language of the subtitle trackOthers:ripped- Whether the video is marked as ripped or notbit_rate- The overall average bitrateresolution- The resolution name (LOW_DEF, HIGH_DEF, etc)Metadata:meta.xyz- Follows the basic JSON metadata output (e.g.meta.titleormeta.video_streams[0].codec)Functions:isNull(xyz)- Returns true if the value is nullall(xyz)- Instead of one stream matching, check all of themExample Queries:Find all videos that are H264v.codec = h264Find all videos that are H264 with stereo AACv.codec = h264 and a.codec = aac and a.channels = 2Find all videos that are H265 or H264 and AACa.codec = aac and (v.codec = h265 or v.codec = h264)a.codec = aac and v.codec in [h265, h264]Find all videos without English Subtitless.lang != engFind videos that are lower resolution than 1080v.height < 1080Find all videos that have ONLY AAC audioall(a.codec) = aactv-renameRenames files in a directory to sXXeYYFor example, if you ripped some Battlestar Galactica blurays, you might have a file structure like:BSG_Season1_Disc1BSG_Season1_Disc1_t00.mkvBSG_Season1_Disc1_t01.mkvBSG_Season1_Disc1_t02.mkvBSG_Season1_Disc1_t03.mkvBSG_Season1_Disc2BSG_Season1_Disc2_t00.mkvBSG_Season1_Disc2_t01.mkvBSG_Season1_Disc2_t02.mkvBSG_Season1_Disc2_t03.mkvmanage-media tv-rename -s 1 -e 1 --tvdb --show "Battlestar Galactica" --output "BSG/Season 1" BSG_Season1_Disc*ResultBSGSeason 1Battlestar Galatica (2003) - S01E01 - 33.mkvBattlestar Galatica (2003) - S01E02 - Water.mkvBattlestar Galatica (2003) - S01E03 - Bastille Day.mkvBattlestar Galatica (2003) - S01E04 - Act of Contrition.mkvBattlestar Galatica (2003) - S01E05 - You Can't Go Home Again.mkvBattlestar Galatica (2003) - S01E06 - Litmus.mkvBattlestar Galatica (2003) - S01E07 - Six Degrees of Separation.mkvBattlestar Galatica (2003) - S01E08 - Flesh and Bone.mkvConfigurationYou can configuration where to find various executables by creating a file~/.config/mms/config.ini. By default, commands will use the executables found in your path.You can see which tools are being used withmanage-media executablesConfig File Example[main]ffmpeg=/path/to/ffmpeg