A few days ago I had to break apart some episodes of Top Cat from the uncompressed Blu-Ray rip to individual MKV files that can be read properly by Plex Media Server (as it’s not working with BDMV folders).

1. Install mkvtoolnix, using the instructions from their Downloads Page

As I’m using Ubuntu 18.04 Server on my home server (if it ain’t broken, why change it?) so I used the respective commands:

_You first have to import my public GPG key because all of my pools are signed. Run this once: _ sudo wget -O /etc/apt/keyrings/gpg-pub-moritzbunkus.gpg https://mkvtoolnix.download/gpg-pub-moritzbunkus.gpg

Then

deb [signed-by=/etc/apt/keyrings/gpg-pub-moritzbunkus.gpg] https://mkvtoolnix.download/ubuntu/ bionic main deb-src [signed-by=/etc/apt/keyrings/gpg-pub-moritzbunkus.gpg] https://mkvtoolnix.download/ubuntu/ bionic main

And then the only things left to do are to run sudo apt update followed by sudo apt install mkvtoolnix mkvtoolnix-gui (I skipped the second package as I’m on the Server variant, so I don’t need a GUI)

2. Create a .sh script in the directory with the MKV files

touch fix_metadata.sh vi fix_metadata.sh

and added this content:

1
2
3
4
5
6
7
8
#!/bin/bash

# This script takes all mkv files in the current directory and sets the filename
# (without .mkv) as its title in metadata

for mkvfile in *.mkv; do
    mkvpropedit "$mkvfile" -e info -s title="${mkvfile%.mkv}"
done

Then you just need to make the file executable and run it:

chmod +x fix_metadata.sh ./fix_metadata.sh

And presto! Each file should have the title set like the filename (so Top Cat - 01x02 - The Maharajah of Pookajee.mkv will have the title “Top Cat - 01x02 - The Maharajah of Pookajee” and generate this fairly generic output:

The file is being analyzed.
The changes are written to the file.
Done.

And this is it!