Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ##############################################################################
- ### NZBGET POST-PROCESSING SCRIPT ###
- # Rename garbled MKV files to season and episode numbering.
- # Useful for QoQ releases.
- # Directory allowed to rename files in (should be equal to tv category DestDir)
- #AllowedDir=/volume1/video/tv
- ### NZBGET POST-PROCESSING SCRIPT ###
- ##############################################################################
- # Tested on Synology DSM 4.3-3810 Update 2 (BusyBox v1.16.1)
- # INSTALLATION INSTRUCTIONS:
- #
- # 1. Place script in ppscripts directory,
- # e.g. /usr/local/ppscripts/RenameMKV.sh
- #
- # 2. Make script executable:
- # chmod a+x /usr/local/ppscripts/RenameMKV.sh
- #
- # 3. Restart NZBGet
- #
- # 4. NZBGet Settings > RenameMKV: set AllowedDir to tv category DestDir,
- # e.g. /volume1/video/tv
- #
- # 5. NZBGet Settings > Post-Processing Scripts: move RenameMKV.sh after DeleteSamples.py,
- # e.g. DeleteSamples.py, RenameMKV.sh, nzbToMedia*.py, Email.py, Logger.py
- #
- # 6. NZBGet Settings > Categories: set RenameMKV.sh as DefScript for tv category,
- # e.g. RenameMKV.sh, nzbToMedia/nzbToSickBeard.py
- #
- # NZBGet will now execute RenameMKV.sh for tv NZBs added from this point onwards.
- # Manually change the PP-Parameters for any tv NZBs that were already queued.
- # CHANGELOG:
- #
- # 2013/12/08
- # * [FIX] Typo prevented AllowedDir to work with non-default settings
- # * [ADD] Strip year from NZB name
- # * [ADD] AllowedDir error message now includes directories for debugging
- ALLOWED_DIR=$NZBPP_ALLOWEDDIR
- if [ "$ALLOWED_DIR" = "" ]; then
- ALLOWED_DIR="/volume1/video/tv"
- fi
- # Sanity checks: require NZB post-processing directory and name from NZBGet
- if [ "$NZBPP_DIRECTORY" == "" ]; then
- echo "[ERROR] Empty directory name, skipping."
- exit 95
- fi
- if [ "$NZBPP_NZBNAME" == "" ]; then
- echo "[ERROR] Empty NZB name, skipping."
- exit 95
- fi
- echo "[INFO] Fixing MKV filenames in $NZBPP_DIRECTORY for $NZBPP_NZBNAME"
- # Sanity check: disallow post-processing directory to be root or the working directory
- if [ "$NZBPP_DIRECTORY" == "." -o "$NZBPP_DIRECTORY" == "/" ]; then
- echo "[ERROR] Illegal directory name, skipping."
- exit 95
- fi
- # Sanity check: require post-processing directory to contain AllowedDir
- if [ `echo "$NZBPP_DIRECTORY" | grep "$ALLOWED_DIR" | wc -l` == "0" ]; then
- echo "[ERROR] Directory $NZBPP_DIRECTORY not in allowed $ALLOWED_DIR, skipping."
- exit 95
- fi
- # Find files which already have season and episode numbering
- if [ `find "$NZBPP_DIRECTORY" -maxdepth 1 -type f -regex '.*[sS][0-9][0-9]*[eE][0-9][0-9]*.*\.[mM][kK][vV]$' | wc -l` == "0" ]; then
- # No parsed files found, try to find MKV files now
- NZB_NAME=`echo $NZBPP_NZBNAME | sed 's/([0-9][0-9][0-9][0-9])//g' | sed 's/ / /g' | sed 's/\.\./\./g'`
- echo "[DETAIL] Renaming MKV files to $NZB_NAME.mkv"
- find "$NZBPP_DIRECTORY" -name *.mkv -exec mv {} "$NZBPP_DIRECTORY/$NZB_NAME.mkv" \;
- RESULT=$?
- if ! [ "$RESULT" == 0 ]; then
- echo "[ERROR] Error $RESULT"
- exit 94
- fi
- else
- echo "[DETAIL] No MKV files to rename."
- fi
- exit 93
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement