Guest User

Untitled

a guest
Aug 10th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #! /bin/bash
  2. {
  3. # Log file, file where we tell what events have been processed.
  4. LOG_FILE=/var/log/posttorrent.log
  5. # Username for transmission remote.
  6. # TR_USERNAME="username"
  7. # Password for transmission remote.
  8. # TR_PASSWORD="password"
  9. # Get current time.
  10. NOW=$(date +%Y-%m-%d\ %H:%M:%S)
  11. # Source directory, should not be changed.
  12. SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}"
  13. # Directory to store the un-compressed files in..
  14. DEST_DIR="/home/pdq/Videos/tempvideo"
  15. # This parameter string could be passed from Transmission in the future.
  16. TR_TORRENT_PARAMETER="EXTRACT SLEEP1h"
  17.  
  18. if [ -e "$SRC_DIR/keep" ]; then
  19. TR_TORRENT_PARAMETER="$TR_TORRENT_PARAMETER KEEP"
  20. fi
  21.  
  22. if [ -e "$SRC_DIR/exit" ]; then
  23. TR_TORRENT_PARAMETER="EXIT"
  24. fi
  25.  
  26. # Actual processing starts here.
  27. if [[ "$TR_TORRENT_PARAMETER" =~ "EXIT" ]]; then
  28. echo $NOW "Exiting $TR_TORRENT_NAME" >> $LOG_FILE
  29. exit 0
  30. fi
  31.  
  32. if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
  33. cd $TR_TORRENT_DIR
  34. if [ -d "$SRC_DIR" ]; then
  35. IFS=$'\n'
  36. unset RAR_FILES i
  37. for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do
  38. RAR_FILES[i++]=$RAR_FILE
  39. done
  40. unset IFS
  41.  
  42. if [ ${#RAR_FILES} -gt 0 ]; then
  43. for RAR_FILE in "${RAR_FILES[@]}"; do
  44. unrar x -inul "$RAR_FILE" "$DEST_DIR"
  45. done
  46. if [[ ! "$TR_TORRENT_PARAMETER" =~ "KEEP" ]]; then
  47. SLEEP=$(expr match "$TR_TORRENT_PARAMETER" '.*SLEEP\([0-9a-zA-Z]*\)')
  48. if [ ${#SLEEP} -gt 0 ]; then
  49. sleep $SLEEP
  50. fi
  51. #sudo vlc $DEST_DIR/$TR_TORRENT_NAME.* --playlist-enqueue
  52. #transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --remove-and-delete
  53. fi
  54. echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
  55. fi
  56. fi
  57. fi
  58. } &
Add Comment
Please, Sign In to add comment