Renaming scripts for TV shows
#1
I have been working on a script to rename TV shows using bash.

example of a badly named file - Breaking.Bad.S01E01.576p.BluRay.DD5.1.x264-HiSD.mkv

I want to run a script that will rename all files in a folder to be S01E01.mkv etc

I have been manually using
Code:
cp Breaking.Bad.S01E01.576p.BluRay.DD5.1.x264-HiSD.mkv /mnt/2tb_hd/TV_Shows/Breaking\ Bad/S01E01.mkv

But this is tedious when doing it all manually, I would like to just use
Code:
cp *.mkv /mnt/2tb_hd/TV_Shows/Breaking\ Bad/

Then run a script that renames all the files to the format S01E01.mkv and so on for each file.

---------------------

See below for completed and working script. Feel free to use and share Smile
Raspberry Pi 2 Model B

Arch Linux ARM
Reply
#2
I use filebot. If you're familiar with bash then it's a case of putting all of the elements you want together using the format option.

Alternatively, filebot has a built in script called AMC (Automated Media Centre) that does everything. So I strongly suggest you start there.

It is however a Java program which is undesirable for some people.

Sent from my LG-D855
Reply
#3
Thanks for the reply, I don't use any GUI but I see there is a CLI version of filebot so I will take a look at that.
Raspberry Pi 2 Model B

Arch Linux ARM
Reply
#4
Sorted out all the issues with my script to rename TV shows if anyone would like to use it.

Code:
#!/bin/bash
#
# SCRIPT:    rename_tv.sh
# AUTHOR:    s7ntax
# DATE:        26-08-2016
# REV:        1.1.A
# PLATFORM:    Not platform dependent
#
# PURPOSE:    This script will rename TV Show files in pwd to the format S01E01
#         provided the season number and episode number are present in the
#         the correct order at the start of the original filename, disregarding
#         all other numbers and  maintaining the original extension.
#

if [ $? == 1 ]; then
    exit
fi

# Define regex

reg='^([^0-9]*)([0-9][0-9]*)[^0-9]*([0-9][0-9]*).*(\....)$'

# Start a for loop

for filename in *.*; do
      if [[ $filename =~ $reg ]]; then
              printf -v newname 'S%02dE%02d%s' "$((10#${BASH_REMATCH[2]}))" "$((10#${BASH_REMATCH[3]}))" "${BASH_REMATCH[4]}"
                  mv -n "$filename" "$newname"
            fi
        done
    exit
Raspberry Pi 2 Model B

Arch Linux ARM
Reply

Logout Mark Read Team Forum Stats Members Help
Renaming scripts for TV shows0