Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # posttorrent.sh created by Killemov
- # updated by Jordan Oxborrow 2015-02-23
- {
- umask 0002
- # Log file, file where we tell what events have been processed.
- LOG_FILE="/var/log/transmission-daemon/posttorrent.log"
- # Username for transmission remote
- TR_USERNAME="username"
- # Password for transmission remote
- TR_PASSWORD="password"
- # Directory torrent is in to assume it's a TV show
- TV_SHOW_DIR="/path/to/tvshows"
- # Directory torrent is in to assume it's a movie
- MOVIE_DIR="/path/to/movies"
- # Directory to move post-post-processed torrent data to
- SEED_DIR="/path/to/seeding"
- # Haven't done anything with this information yet
- tv_show_extensions="avi,mkv,divx,mp4,srt,idx,sub"
- movie_extensions="avi,mkv,divx,mp4,ts,iso,img,srt,idx,sub"
- tv_show_extensions_rev="\.$(echo $tv_show_extensions | sed 's;,;\$\|\\\.;g')$"
- movie_extensions_rev="\.$(echo $movie_extensions | sed 's;,;\$\|\\\.;g')$"
- # Get current time.
- NOW=$(date +%Y-%m-%d\ %H:%M:%S)
- # Build Transmission command
- TR_CMD="transmission-remote -n "${TR_USERNAME}":"${TR_PASSWORD}" -t ${TR_TORRENT_HASH}"
- # Source directory, should not be changed.
- SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
- # Directory to store the un-compressed files in..
- DEST_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}/"
- ## Actual processing starts here.
- echo $NOW "Initializing posttorrent script for $TR_TORRENT_NAME" >> $LOG_FILE
- cd "$TR_TORRENT_DIR"
- # Check for any RAR files
- if [ -d "$SRC_DIR" ]; then
- IFS=$'\n'
- unset RAR_FILES i
- for RAR_FILE in $( find "$SRC_DIR" -type f -iname "*.rar" ); do
- if [[ $RAR_FILE =~ .*part.*.rar ]]; then
- if [[ $RAR_FILE =~ .*part0*1.rar ]]; then
- RAR_FILES[i++]=$RAR_FILE
- fi
- else
- RAR_FILES[i++]=$RAR_FILE
- fi
- done
- unset IFS
- # UnRAR any RAR files to the parent directory
- if [ ${#RAR_FILES} -eq 0 ]; then
- echo $NOW "Did not identify RAR files in $TR_TORRENT_NAME" >> $LOG_FILE
- else
- echo $NOW "Identified RAR files in $TR_TORRENT_NAME" >> $LOG_FILE
- for RAR_FILE in "${RAR_FILES[@]}"; do
- nice -n15 unrar x -y -o+ -p- -inul "$RAR_FILE" "${TR_TORRENT_DIR}"
- if [ $? -gt 0 ]; then
- echo $NOW "Error unrarring $TR_TORRENT_NAME: Forcing torrent re-verify and exiting script" >> $LOG_FILE
- transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t $TR_TORRENT_HASH --verify --start
- exit 1
- fi
- done
- echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
- fi
- fi
- ## TV Show specific actions
- if [[ "$SRC_DIR" =~ "$TV_SHOW_DIR" ]]; then
- echo $NOW "Identified $TR_TORRENT_NAME as a TV show" >> $LOG_FILE
- # Actions to perform if the torrent data is fils in a directory
- # The unrarred files should already be in $TVSHOW_DIR now.
- # Hard link supported filetypes to $TVSHOW_DIR. Move torrent data to $SEED_DIR.
- if [ -d "$SRC_DIR" ]; then
- for _supported_file in $(find "${SRC_DIR}" -type f | egrep -i "${tv_show_extensions_rev}"); do
- echo $NOW "Creating hardlink to $_supported_file" >> $LOG_FILE
- ln -f "${_supported_file}" "${TR_TORRENT_DIR}/$(basename ${_supported_file})"
- done
- echo $NOW "Telling Transmission to move $TR_TORRENT_NAME to $SEED_DIR" >> $LOG_FILE
- $TR_CMD --move "${SEED_DIR}"
- # Actions to perform if TV show is a single file
- # Make hard link to seeding dir and tell Transmission to look for it there instead
- elif [ -f "${SRC_DIR}" ]; then
- echo $NOW "Creating hardlink to ${SEED_DIR}/${TR_TORRENT_NAME}" >> $LOG_FILE
- ln -f "${SRC_DIR}" "${SEED_DIR}/${TR_TORRENT_NAME}"
- echo $NOW "Having Transmission find $TR_TORRENT_NAME in $SEED_DIR" >> $LOG_FILE
- $TR_CMD --find "${SEED_DIR}"
- fi
- ## Movie specific commands
- elif [[ "${SRC_DIR}" =~ "${MOVIE_DIR}" ]]; then
- echo its a movie
- ## Not a TV show or movie
- else
- echo "its not a tv or movie. dont touch it."
- fi
- # To Do
- # go through showrss and change feed
- # Do any tv shows actually come with Samples and subs? How to deal?
- echo $NOW "Completed post-processing of $TR_TORRENT_NAME" >> $LOG_FILE
- } &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement