Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Category: CLI

Use rename linux command for podcasts in Plex

I’m attempting to integrate podcasts into Plex so that I can listen to them over my Roku. This is something Plex doesn’t do well yet, but I’m following this tutorial on Reddit

how to create a PODCAST library, a VIDEO PODCAST library, an AUDIO BOOK library, and much more – an ultimate plex guide

The rename command, which is implemented in perl, can rename the files.

The files should be in a format like this
“podcast name” – “s01e###” – “title”.mp3

e.x.
the patch – s01e100 – mortal kombat x + halo online.mp3

My goal is to integrate the Escape Pod podcast, so I have the latest Escape Pod download

EP502_GorlacktheDestroyersAllYouCanEatAdventure.mp3

The first command to run against the filename adds Escape Pod to the beginning and puts the episode number into a Season/Episode format (S01E502)

rename -v ‘s/EP(\d+)_(.*[A-Z].+)\.mp3/Escape Pod – S01E$1 – $2\.mp3/’ EP502_GorlacktheDestroyersAllYouCanEatAdventure.mp3
results in
EP502_GorlacktheDestroyersAllYouCanEatAdventure.mp3 renamed as Escape Pod – S01E502 – GorlacktheDestroyersAllYouCanEatAdventure.mp3

The title is still a little ugly, so we run this command which will add a space in front of each capital letter in the title except the first one.
rename -nv ‘s/([a-z])([A-Z])/$1\ $2/g’ ./Escape\ Pod\ -\ S01E502\ -\ GorlacktheDestroyersAllYouCanEatAdventure.mp3
results in
./Escape Pod – S01E502 – GorlacktheDestroyersAllYouCanEatAdventure.mp3 renamed as ./Escape Pod – S01E502 – Gorlackthe Destroyers All You Can Eat Adventure.mp3

This gets us close. Unfortunately “the” wasn’t capitalized, so it’s not easy to add a space in there.
I ran this command
rename -n ‘s/(the\ )/\ $1/’ *mp3
result
Escape Pod – S01E502 – Gorlackthe Destroyers All You Can Eat Adventure.mp3 renamed as Escape Pod – S01E502 – Gorlack the Destroyers All You Can Eat Adventure.mp3
which worked in this situation, but it has a good probability for false positives.

This isn’t perfect, but it gets me much closer to where I want to be.

Shut Off Monitor With Nircmd

I have multiple computers on my work desk and sometimes I want to shut off a monitor. ┬áMaybe I’m watching a video or playing a game with the lights down – whatever the reason, I haven’t found an easy way to blank out a monitor under Windows 7 until now.

Found this great article on howtogeek.com about disabling a monitor.

Create a Shortcut or Hotkey to Turn Off the Monitor

 

It uses the Nircmd.exe app to create a shortcut to disable the monitor.  Very cool.

Removing Special Characters From Linux Filenames

This goes with the previous post concerning converting files from flac to mp3. Sometimes filenames have characters beyond spaces that make it difficult to work with in a script. If you want to rename your files without annoying special characters, use the following command.

for f in *
do
mv "$f" $(echo $f | sed -e 's/[^A-Za-z0-9._-]/_/g')
done

This will replace every non-alphanumeric character in the filename with an underscore _

Converting FLAC to MP3 from the command line in Ubuntu

From time to time I have some flac files I want to convert to mp3 files so they will play on my car radio. This is simple enough to do,and with a Google search I found this command.

for f in *;do flac -cd $f |lame -b 128 - $f.mp3;done
 (http://www.upubuntu.com/2011/06/how-to-convert-flac-to-mp3-from-command.html)

The first problem with this is it doesn’t like spaces in the file names. This can be solved by adding quotation marks

for f in *;do flac -cd "$f" |lame -b 128 - "$f".mp3;done

The second problem is, it creates all the files with the name foo.flac.mp3. After a bit of research I found the rename command can quickly rename all of the files.

rename 's/\.flac.mp3$/.mp3/' *.mp3

You could probably add this to the end of the for loop with a && or something

Remove spaces from filenames on the Ubuntu Linux command line

I’ve been working on sizing a large number of images for a client to go into a WordPress photo gallery. I use a for loop to find all the files and use convert to size them to a good size for viewing on a website. The problem is the convert program doesn’t like file names with spaces in them. It seems like the easiest thing to do is remove the spaces from the file names with a Ubuntu command line script. This is easily accomplished with the rename comannd.

rename 'y/ /_/' *

This script will replace any spaces spaces in the filenames with underscores (_)