Advertisement
HashWorks

One Piece Post-Processing Script

Feb 25th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ONEPIECE_FOLDER="/home/hashworks/Share/Series/One Piece/";
  4. TO_REMOVE=".nfo .srr .sfv .nzb .jpg .png .jpeg";
  5.  
  6. PUSHOVER_TITLE="Download finished";
  7. PUSHOVER_TOKEN="";
  8. PUSHOVER_USER="";
  9.  
  10. PLEX_URL="localhost"
  11. PLEX_LIB_KEY=12
  12.  
  13. ############################################################################################################################################
  14. #
  15. # Usage: onepiece "DOWNLOADFOLDER";
  16. #
  17. # Best as Post-Processing script of SabNZBd.
  18. #
  19. # Turns One Piece absolute ordering to "Staffel XX/One Piece - SXXEYYYAZZZ - Title.ext" and moves it to your OP-folder.
  20. #
  21. # Only usefull for downloads of Op-Tube One Piece Anime Episodes - testet with usenet downloads by had551.
  22. # When a new Season is approched, create a new empty folder in $ONEPIECE_FOLDER, f.e. "Staffel 18".
  23. # Remember: This will NOT be able to handle special episodes! Exclude them from download.
  24. #
  25. # ~ HashWorks [2014-02-17]
  26. #
  27. ############################################################################################################################################
  28.  
  29. if [ -z "$1" ] ; then echo "ERROR: No download folder path given. Usage: ""$0"" \"DOWNLOADFOLDER\""; exit 1; fi;
  30.  
  31. echo -e "Post-Processing ""$1""\n";
  32.  
  33. cd "$ONEPIECE_FOLDER";
  34. STAFFEL=$(find -name 'Staffel *' | sort -V | tail -1 | grep -o '[0-9]\{1,2\}');
  35.  
  36. if [ ! -z "${STAFFEL#*[!0-9]*}" ] ; then echo -e "Season number found: ""$STAFFEL""."; else echo "ERROR: Given season (""$STAFFEL"") isn't a number. Make sure your season folders match \"Staffel XY\"."; exit 2; fi;
  37.  
  38. cd "$ONEPIECE_FOLDER"Staffel\ "$STAFFEL";
  39.  
  40. if [ ${#STAFFEL} == 1 ]; then STAFFEL_ZERO="0$STAFFEL"; elif [ ${#STAFFEL} == 2 ]; then STAFFEL_ZERO="$STAFFEL"; fi;
  41.  
  42. EPISODE=$(echo $(find . -regextype sed -regex "./One Piece - S""$STAFFEL_ZERO""E.*" | sort) | sed 's/.*S'"$STAFFEL_ZERO"'E\([0-9]\{1,3\}\)A.*/\1/');
  43. EPISODE=$(echo "$EPISODE + 1" | bc)
  44. if [ ${#EPISODE} == 1 ]; then EPISODE="00$EPISODE"; elif [ ${#EPISODE} == 2 ]; then EPISODE="0$EPISODE"; fi;
  45.  
  46. echo -e "Episode number found: ""$EPISODE"".\n";
  47.  
  48. cd "$1";
  49. for REM in $TO_REMOVE; do find "$1" -name "*$REM" -type f -exec rm -f {} \;; done;
  50.  
  51. FILE=$(find . -regextype sed -regex "./One Piece - Ep\..*" | sort);
  52. if [ -z "$FILE" ] ; then echo "No one piece file found."; exit 3; else echo -e "File found: ""$FILE""\n"; fi;
  53. ABSOLUT=$(echo "$FILE" | sed 's/.*Ep\.\([0-9]\{1,4\}\) -.*/\1/');
  54. if [ ! -z "${ABSOLUT#*[!0-9]*}" ] ; then echo -e "Absolute number found: ""$ABSOLUT""."; else echo "ERROR: Given absolute (""$ABSOLUT"") isn't a number. Make sure you downloaded from op-tube."; exit 4; fi;
  55. TITEL=$(echo "$FILE" | sed 's/.*Ep\.'"$ABSOLUT"' - \(.*\).\[op-tube\].*/\1/');
  56. if [ -z "$TITEL" ] ; then echo "ERROR: No title found."; exit 5; else echo -e "Title found: ""$TITEL"""; fi;
  57. ENDUNG=$(echo "$FILE" | sed 's/.*\.\(.*\)/\1/');
  58. if [ -z "$ENDUNG" ] ; then echo "ERROR: No extension found."; exit 6; else echo -e "Extension found: ""$ENDUNG""\n"; fi;
  59.  
  60. OUTPUT="One Piece - S""$STAFFEL_ZERO""E""$EPISODE""A""$ABSOLUT"" - ""$TITEL"".""$ENDUNG";
  61.  
  62. echo -e "Moving ""$1""$FILE""\nto ""$ONEPIECE_FOLDER""Staffel\ ""$STAFFEL""/""$OUTPUT""";
  63. mv "$1"/One\ Piece\ -\ Ep."$ABSOLUT"*."$ENDUNG" "$ONEPIECE_FOLDER"Staffel\ "$STAFFEL"/"$OUTPUT";
  64.  
  65. echo -e "Removing ""$1""\n";
  66. rm -R "$1";
  67.  
  68. curl -d message="One Piece - S""$STAFFEL_ZERO""E""$EPISODE""A""$ABSOLUT"" - ""$TITEL" -d title="$PUSHOVER_TITLE" -d token="$PUSHOVER_TOKEN" -d user="$PUSHOVER_USER" 'https://api.pushover.net/1/messages.json' >/dev/null 2>&1
  69.  
  70. curl "http://""$PLEX_URL"":32400/library/sections/""$PLEX_LIB_KEY""/refresh" >/dev/null 2>&1
  71.  
  72. echo -e "Done! [""$OUTPUT""]";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement