Skip to content

Instantly share code, notes, and snippets.

@openback
Created June 8, 2011 16:50
Show Gist options
  • Save openback/1014805 to your computer and use it in GitHub Desktop.
Save openback/1014805 to your computer and use it in GitHub Desktop.
Script to move classic Doctor Who episodes downloaded from zuko on Usenet to the proper directory on my HTPC
#!/bin/bash
#===============================================================================
#
# FILE: move_doctors
#
# USAGE: ./move_doctors
#
# DESCRIPTION: Script to move classic Doctor Who episodes downloaded from
# zuko on Usenet to the proper directory, named for proper
# identification by XBMC or Boxee. Extract each story into one
# directory with the name "Doctor.Who.SXXEYY", where XX is the
# season, and YY is the number of the first actual episode
# number of that story. This can be found by referencing:
#
# http://www.thetvdb.com/?tab=series&id=76107&lid=7
# http://tardis.wikia.com/wiki/Category:Doctor_Who_(1963)_television_stories
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Timothy Caraballo, [email protected]
# COMPANY: Pixelpod International, Inc.
# VERSION: 1.06
# CREATED: 2010-08-25 16:25:00 EST
#===============================================================================
#===============================================================================
# Script variables
#===============================================================================
SHOW_DIR='/Multimedia/Video/TV/Doctor.Who';
shopt -s extglob
#===============================================================================
# Moves the specified files and reports i's status
#===============================================================================
function MOVETHEM() {
EXTENSION=${FILENAME#*.}
mv -n "$FILENAME" "${SHOW_DIR}/Season.${SEASON}/Doctor.Who.S${SEASON}E${EPISODE_NUMBER}.$EXTENSION"
if [ $? -gt 0 ]; then
echo "Error moving Season.${SEASON}/Doctor.Who.S${SEASON}E${EPISODE_NUMBER}.avi"
exit 1
else
echo "Moved Season.${SEASON}/Doctor.Who.S${SEASON}E${EPISODE_NUMBER}.avi"
fi
}
#===============================================================================
# Main routine
#===============================================================================
for i in Doctor.Who.S*E*; do
SEASON=${i:12:2}
START=${i:15:2}
cd $i &>/dev/null
[ $? -gt 0 ] && { echo 'No video directories found.'; exit 0; }
# Specials are umm...special
[ $SEASON = "00" ] && continue
echo "In $i"
# Create the directory if it doesn't exist
if [ ! -d "${SHOW_DIR}/Season.${SEASON}" ]; then
mkdir "${SHOW_DIR}/Season.${SEASON}"
if [ $? -gt 0 ]; then
echo "Could not create ${SHOW_DIR}/Season.${SEASON}"
exit 1
else
echo "Created ${SHOW_DIR}/Season.${SEASON}"
fi
fi
# Loop through 12 episodes, which is the longest number of episodes any
# one story has ever had. (Season 3, episodes 10 - 21, "The Dalek's Master
# Plan")
for EPISODE in {1..12}; do
# Create the proper padded episode number
EPISODE_NUMBER=`printf "%02d" "$((10#$START + $EPISODE - 1))"`
# Now just check against the three naming conventions I've seen in
# zuko's posts
if [ -e Dr\ Who*\ $EPISODE\ of* ]; then
FILENAME=`ls -1 Dr\ Who*\ $EPISODE\ of*`
MOVETHEM
elif [ -e s${SEASON}[es]+([0-9])p?(0)${EPISODE}\ * ]; then
FILENAME=`ls -1 s${SEASON}[es]+([0-9])p?(0)${EPISODE}\ *`
MOVETHEM
elif [ -e *\ $EPISODE-+([0-9]).* ]; then
FILENAME=`ls -1 *\ $EPISODE-+([0-9]).*`
MOVETHEM
fi
done
# Get rid of the directory if possible
rm *.nzb &>/dev/null
cd ..
rmdir $i
done
exit 0
@md2perpe
Copy link

md2perpe commented Jun 8, 2011

Shouldn't line 3 be without prefixing $ ?

show_dir='/Multimedia/Video/TV/Doctor.Who'

Confusion with PHP?

@openback
Copy link
Author

openback commented Jun 8, 2011

You're right, so much PHP lately and a quick edit without testing it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment