#!/usr/local/bin/bash # Transmission script to move torrent files ################################################################################# # Transmission Environment Variables # ################################################################################# # TR_APP_VERSION - Transmission's short version string, e.g. 4.0.0 # TR_TIME_LOCALTIME # TR_TORRENT_BYTES_DOWNLOADED - Number of bytes that were downloaded for this torrent # TR_TORRENT_DIR - Location of the downloaded data # TR_TORRENT_HASH - The torrent's info hash # TR_TORRENT_ID # TR_TORRENT_LABELS - A comma-delimited list of the torrent's labels # TR_TORRENT_NAME - Name of torrent (not filename) # TR_TORRENT_PRIORITY - The priority of the torrent (Low is "-1", Normal is "0", High is "1") # TR_TORRENT_TRACKERS - A comma-delimited list of the torrent's trackers' announce URLs ################################################################################# # VARIABLES # ################################################################################# DATASTORE="${1:-p0ds0smb}" LOGFILE="/usr/local/etc/transmission/home/scripts/torrentdone.log" RSYNC_LOGFILE="/usr/local/etc/transmission/home/scripts/torrentdone_rsync.log" TORRENT_PATH="$TR_TORRENT_DIR/$TR_TORRENT_NAME" TORRENT_DESTPATH="/mnt/$DATASTORE/temp/ffmpeg-vcodec/" ################################################################################# # SCRIPT CONTROL # ################################################################################# # Log script events function edate { echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> "$LOGFILE" } edate "__________________________NEW TORRENT FILE__________________________" edate "Transmission version: $TR_APP_VERSION" edate "Time: $TR_TIME_LOCALTIME" edate "Torrent name: $TR_TORRENT_NAME" edate "Directory: $TR_TORRENT_DIR" edate "Torrent Hash: $TR_TORRENT_HASH" edate "Torrent ID: $TR_TORRENT_ID" edate "Downloaded: $TR_TORRENT_BYTES_DOWNLOADED" edate "Full Torrent Path: $TORRENT_PATH" ## -f'+ */' tells rsync to inspect all directories on its traversal ## -f'- *' tells rsync to exclude anything else not explicitly included /usr/local/bin/rsync --recursive --update --times --ignore-existing --progress --human-readable \ --stats --verbose --log-file="$RSYNC_LOGFILE" -f'+ */' -f'+ *.[Mm][Kk][Vv]' -f'+ *.[Mm][Pp][34]' \ -f'+ *.[Mm]4[VvAa]' -f'+ *.[Ii][Dd][Xx]' -f'+ *.[Ss][Uu][Bb]' -f'+ *.[Ss][Rr][Tt]' \ -f'+ *.[Aa][Vv][Ii]' -f'+ *.[Ff][Ll][Aa][Cc]' -f'- .git/' -f'- *' \ "$TORRENT_PATH" "$TORRENT_DESTPATH" if [[ $? -eq 0 ]]; then edate "Copy success to: $TORRENT_DESTPATH" exit 0 else edate "Copy failed to: $TORRENT_DESTPATH" exit 1 fi # Legacy rsync include/excludes #/usr/local/bin/rsync --recursive --update --ignore-existing --itemize-changes --progress --human-readable \ # --stats --verbose --log-file="$RSYNC_LOGFILE" --include="*/" --include="*.mkv" --include="*.mp4" \ # --include="*.srt" --include="*.avi" --exclude="*" "$TORRENT_PATH" $TORRENT_DESTPATH