• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Renaming script for TV shows [Bash]
#1
Anyone who uses Linux will know how tedious this is when dealing a few seasons of a show.

Code:
cp badly.named.file.Season1.Episode1.H264.mpeg.rip.blah.blah.mp4 ~/TV_Shows/SHOW_TITLE/S01E01.mp4

So I made a script that can rename them in a flash.

All you need to do is copy the TV show files to the correctly named directory for the show.

eg.

Code:
cp *.mp4 ~/TV_Shows/Breaking\ Bad/

then cd to the directory for 'Breaking Bad'

Run the script below.

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

Feel free to share Smile
Raspberry Pi 2 Model B

arch Linux ARM

Kodi setup - Kodi-rbp 16.1-4 / omxplayer-git 494.791d7df-1 / xorg-xrefresh 1.0.5-1 / xorg-xset 1.2.3-1

A few other packages I use a lot - nfs-utils / libtorrent / rtorrent / weechat / vim / bitlbee / newsbeuter / mutt / python2 + 3
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)