Posted (Updated ) in Uncategorized

It’s a pretty common problem. You have a file titled firefly – 02 – the train job.mkv when it should be Firefly – 02 – The Train Job.mkv. It’s slow and arduous to rename manually especially if you have a lot of files so below is a single command to do it all for you!

1
rename "s/ ([a-z])/ \U\1\E/g" *.mkv

In the above example:

  • \U means uppercase
  • \1 means the first match (in our case that’s the first alpha after a space)
  • \E means end uppercase
  • *.mkv applies the rename command to all files ending in .mkv in the current folder.

Thanks to akf from stackoverflow for his helpful answer on this one.

Read More »

Posted (Updated ) in Linux

Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that’s such a hassle. Instead, here’s a handy one-liner to do them all at once:

1
find . -name "*.mkv" -exec mkvpropedit {} --edit track:a1 --set flag-default=0 --edit track:a2 --set flag-default=1 --edit track:s1 --set flag-default=0 --edit track:s2 --set flag-default=1 \;

 

Explanation

At first glance they may look a bit complicated, but let’s break it down a bit:

Find all .mkv files and execute an operation on them:

1
find . -name "*.mkv" -exec ... \;

Do an mkvpropedit on the current matched file:

1
mkvpropedit {}

Set the first audio track to not be default, the second audio track to be default, and do the same with the subtitle tracks:

1
2
3
4
--edit track:a1 --set flag-default=0
--edit track:a2 --set flag-default=1
--edit track:s1 --set flag-default=0
--edit track:s2 --set flag-default=1

 

You’ll need mkvtoolnix installed for the mkvpropedit command. To determine what the various tracks contain, do a

1
mkvinfo /path/to/file.mkv

or mkvinfo -g for you GUI users 🙂 This can be a bit tricky to read though so I tend to just open the file in VLC and look at the audio and video tracks that way.

As an added bonus, here’s the Windows equivalent of the above script:

1
2
3
4
5
6
7
8
9
@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0
	echo.
)
pause

I’ve been told the Windows version works but haven’t tested personally.

Happy viewing!

Read More »

Posted (Updated ) in Linux

I’m a developer. That makes me lazy. Here is the code to recursively tar and untar files (with and without compression):

tar -cvf filename.tar target1 target2 #without compression
tar -cvzf filename.tar.gz target1 target2 #with compression (Just add z)

To untar, simply replace c with x:

tar -xvf filename.tar path #without compression
tar -xvzf filename.tar.gz path #with compression (Just add z)

Read More »