Web Dev Blog

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

Tag: rename

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.

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 (_)