diff --git a/apps/templates/deluge/plugins/autoremoveplus.conf b/apps/templates/deluge/plugins/autoremoveplus.conf index 4947a11..f23c6ba 100644 --- a/apps/templates/deluge/plugins/autoremoveplus.conf +++ b/apps/templates/deluge/plugins/autoremoveplus.conf @@ -1,23 +1,23 @@ { "file": 1, "format": 1 - }{ +}{ "interval": 1.0, - "max_seeds": 0, - "sel_func": "or", - "trackers": [], - "remove_data": true, - "labels": [], - "enabled": true, - "count_exempt": false, - "remove": true, - "filter": "func_ratio", - "tracker_rules": {}, - "min": 1.5, - "hdd_space": -1.0, - "filter2": "func_seed_time", - "rule_2_enabled": true, - "min2": 15.0, - "rule_1_enabled": true, + "max_seeds": 0, + "sel_func": "or", + "trackers": [], + "remove_data": true, + "labels": [], + "enabled": true, + "count_exempt": false, + "remove": true, + "filter": "func_ratio", + "tracker_rules": {}, + "min": 1.5, + "hdd_space": -1.0, + "filter2": "func_seed_time", + "rule_2_enabled": true, + "min2": 15.0, + "rule_1_enabled": true, "label_rules": {} -} +} \ No newline at end of file diff --git a/apps/templates/deluge/plugins/execute.conf b/apps/templates/deluge/plugins/execute.conf index 49f50b4..f0f83b0 100644 --- a/apps/templates/deluge/plugins/execute.conf +++ b/apps/templates/deluge/plugins/execute.conf @@ -1,12 +1,12 @@ { - "file": 1, + "file": 1, "format": 1 - }{ +}{ "commands": [ - [ - "0", - "complete", - "/config/scripts/extract.sh" + [ + "0", + "complete", + "/config/scripts/extract.sh" + ] ] - ] -} +} \ No newline at end of file diff --git a/apps/templates/deluge/plugins/extractor.conf b/apps/templates/deluge/plugins/extractor.conf index af84fb3..32e8ff4 100644 --- a/apps/templates/deluge/plugins/extractor.conf +++ b/apps/templates/deluge/plugins/extractor.conf @@ -1,7 +1,7 @@ { "file": 1, "format": 1 - }{ +}{ "use_name_folder": true, "extract_path": "/downloads/deluge/" } diff --git a/apps/templates/deluge/scripts/deluge_extract.sh b/apps/templates/deluge/scripts/deluge_extract.sh index 689c021..9c14361 100644 --- a/apps/templates/deluge/scripts/deluge_extract.sh +++ b/apps/templates/deluge/scripts/deluge_extract.sh @@ -11,7 +11,8 @@ torrentid=$1 torrentname=$2 torrentpath=$3 -log() { +log() +{ logger -t deluge-extractarchives "$@" } @@ -23,11 +24,11 @@ for format in "${formats[@]}"; do cd "$(dirname "$file")" file=$(basename "$file") # if extraction_subdir is not empty, extract to subdirectory - if [[ ! -z "$extraction_subdir" ]]; then + if [[ ! -z "$extraction_subdir" ]] ; then mkdir "$extraction_subdir" cd "$extraction_subdir" file="../$file" fi ${commands[$format]} "$file" - done < <(find "$torrentpath/$torrentname" -iname "*.${format}") -done + done < <(find "$torrentpath/$torrentname" -iname "*.${format}" ) +done \ No newline at end of file diff --git a/apps/templates/nzbget/MP4_Automator/TEMPLATEPPScript b/apps/templates/nzbget/MP4_Automator/TEMPLATEPPScript index 7a14ba8..6eb7055 100644 --- a/apps/templates/nzbget/MP4_Automator/TEMPLATEPPScript +++ b/apps/templates/nzbget/MP4_Automator/TEMPLATEPPScript @@ -14,31 +14,31 @@ ### OPTIONS ### # Change to full path to MP4 Automator folder. No quotes and a trailing / -# MP4_FOLDER=~/sickbeard_mp4_automator/ +#MP4_FOLDER=~/sickbeard_mp4_automator/ # Convert file before passing to destination (True, False) -# SHOULDCONVERT=False +#SHOULDCONVERT=False # Category for Couchpotato -# CP_CAT=Couchpotato +#CP_CAT=Couchpotato # Category for Sonarr -# SONARR_CAT=Sonarr +#SONARR_CAT=Sonarr # Category for Radarr -# RADARR_CAT=Radarr +#RADARR_CAT=Radarr # Category for Sickbeard -# SICKBEARD_CAT=Sickbeard +#SICKBEARD_CAT=Sickbeard # Category for Sickrage -# SICKRAGE_CAT=Sickrage +#SICKRAGE_CAT=Sickrage # Category list (comma seperated) for bypassing any further processing but still converting -# BYPASS_CAT=tv,movies +#BYPASS_CAT=tv,movies # Custom output_directory setting -# OUTPUT_DIR= +#OUTPUT_DIR= ### NZBGET POST-PROCESSING SCRIPT ### ############################################################################## @@ -56,7 +56,7 @@ MP4folder = MP4folder.replace("'", "") MP4folder = MP4folder.replace("\\", "/") if not(MP4folder.endswith("/")): MP4folder += "/" -# DEBUG#print MP4folder+" the original is "+os.environ['NZBPO_MP4_FOLDER'] +#DEBUG#print MP4folder+" the original is "+os.environ['NZBPO_MP4_FOLDER'] output_dir = None if 'NZBPO_OUTPUT_DIR' in os.environ: @@ -67,7 +67,7 @@ if 'NZBPO_OUTPUT_DIR' in os.environ: output_dir = output_dir.replace("\\", "/") if not(output_dir.endswith("/")): output_dir += "/" - # DEBUG#print Overriding output directory + #DEBUG#print Overriding output directory sys.path.append(MP4folder) try: @@ -77,8 +77,7 @@ try: import logging from logging.config import fileConfig except ImportError: - print("[ERROR] Wrong path to sickbeard_mp4_automator: " + - os.environ['NZBPO_MP4_FOLDER']) + print("[ERROR] Wrong path to sickbeard_mp4_automator: " + os.environ['NZBPO_MP4_FOLDER']) print("[ERROR] %s" % traceback.print_exc()) sys.exit(0) @@ -91,32 +90,28 @@ elif not os.path.isdir(logpath): os.mkdir(logpath) except: logpath = MP4folder -configPath = os.path.abspath(os.path.join( - MP4folder, 'logging.ini')).replace("\\", "\\\\") -logPath = os.path.abspath(os.path.join( - logpath, 'index.log')).replace("\\", "\\\\") +configPath = os.path.abspath(os.path.join(MP4folder, 'logging.ini')).replace("\\", "\\\\") +logPath = os.path.abspath(os.path.join(logpath, 'index.log')).replace("\\", "\\\\") fileConfig(configPath, defaults={'logfilename': logPath}) log = logging.getLogger("NZBGetPostProcess") # Determine if conversion will take place -shouldConvert = (os.environ['NZBPO_SHOULDCONVERT'].lower() in ( - "yes", "true", "t", "1")) +shouldConvert = (os.environ['NZBPO_SHOULDCONVERT'].lower() in ("yes", "true", "t", "1")) if 'NZBOP_SCRIPTDIR' in os.environ and not os.environ['NZBOP_VERSION'][0:5] < '11.0': log.info("Script triggered from NZBGet (11.0 or later).") path = os.environ['NZBPP_DIRECTORY'] # Path to NZB directory nzb = os.environ['NZBPP_NZBFILENAME'] # Original NZB name - # NZB Category to determine destination - category = os.environ['NZBPP_CATEGORY'] - # DEBUG#print "Category is %s." % category + category = os.environ['NZBPP_CATEGORY'] # NZB Category to determine destination + #DEBUG#print "Category is %s." % category couchcat = os.environ['NZBPO_CP_CAT'].lower() sonarrcat = os.environ['NZBPO_SONARR_CAT'].lower() radarrcat = os.environ['NZBPO_RADARR_CAT'].lower() sickbeardcat = os.environ['NZBPO_SICKBEARD_CAT'].lower() sickragecat = os.environ['NZBPO_SICKRAGE_CAT'].lower() - bypass = os.environ['NZBPO_BYPASS_CAT'].lower().replace(' ', '').split(',') + bypass = os.environ['NZBPO_BYPASS_CAT'].lower().replace(' ','').split(',') categories = [sickbeardcat, couchcat, sonarrcat, radarrcat, sickragecat] @@ -137,8 +132,7 @@ if 'NZBOP_SCRIPTDIR' in os.environ and not os.environ['NZBOP_VERSION'][0:5] < '1 status = 0 if os.environ['NZBOP_UNPACK'] != 'yes': - log.error( - "Please enable option \"Unpack\" in nzbget configuration file, exiting.") + log.error("Please enable option \"Unpack\" in nzbget configuration file, exiting.") sys.exit(POSTPROCESS_NONE) # Check par status @@ -165,31 +159,26 @@ if 'NZBOP_SCRIPTDIR' in os.environ and not os.environ['NZBOP_VERSION'][0:5] < '1 fileExtension = os.path.splitext(file)[1] if fileExtension in ['.par2']: - log.error( - "Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\".") + log.error("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\".") status = 1 break if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")) and not status == 1: - log.error( - "Post-Process: _brokenlog.txt exists, download is probably damaged, exiting.") + log.error("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting.") status = 1 if not status == 1: - log.error( - "Neither par2-files found, _brokenlog.txt doesn't exist, considering download successful.") + log.error("Neither par2-files found, _brokenlog.txt doesn't exist, considering download successful.") # Check if destination directory exists (important for reprocessing of history items) if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): - log.error("Post-Process: Nothing to post-process: destination directory ", - os.environ['NZBPP_DIRECTORY'], "doesn't exist.") + log.error("Post-Process: Nothing to post-process: destination directory ", os.environ['NZBPP_DIRECTORY'], "doesn't exist.") status = 1 sys.exit(POSTPROCESS_NONE) # Make sure one of the appropriate categories is set if category.lower() not in categories and category.lower() not in bypass: - log.error( - "Post-Process: No valid category detected. Category was %s." % (category)) + log.error("Post-Process: No valid category detected. Category was %s." % (category)) status = 1 sys.exit(POSTPROCESS_NONE) @@ -209,8 +198,8 @@ if 'NZBOP_SCRIPTDIR' in os.environ and not os.environ['NZBOP_VERSION'][0:5] < '1 for r, d, f in os.walk(path): for files in f: inputfile = os.path.join(r, files) - # DEBUG#print inputfile - # Ignores files under 50MB + #DEBUG#print inputfile + #Ignores files under 50MB if os.path.getsize(inputfile) > 50000000: if MkvtoMp4(settings, logger=log).validSource(inputfile): try: @@ -221,33 +210,33 @@ if 'NZBOP_SCRIPTDIR' in os.environ and not os.environ['NZBOP_VERSION'][0:5] < '1 if converter.output_dir: path = converter.output_dir if (category.lower() == categories[0]): - # DEBUG#print "Sickbeard Processing Activated" + #DEBUG#print "Sickbeard Processing Activated" autoProcessTV.processEpisode(path, settings, nzb) sys.exit(POSTPROCESS_SUCCESS) elif (category.lower() == categories[1]): - # DEBUG#print "CouchPotato Processing Activated" + #DEBUG#print "CouchPotato Processing Activated" autoProcessMovie.process(path, settings, nzb, status) sys.exit(POSTPROCESS_SUCCESS) elif (category.lower() == categories[2]): - # DEBUG#print "Sonarr Processing Activated" + #DEBUG#print "Sonarr Processing Activated" success = sonarr.processEpisode(path, settings, True) if success: sys.exit(POSTPROCESS_SUCCESS) else: sys.exit(POSTPROCESS_ERROR) elif (category.lower() == categories[3]): - # DEBUG#print "Radarr Processing Activated" + #DEBUG#print "Radarr Processing Activated" success = radarr.processMovie(path, settings, True) if success: sys.exit(POSTPROCESS_SUCCESS) else: sys.exit(POSTPROCESS_ERROR) elif (category.lower() == categories[4]): - # DEBUG#print "Sickrage Processing Activated" + #DEBUG#print "Sickrage Processing Activated" autoProcessTVSR.processEpisode(path, settings, nzb) sys.exit(POSTPROCESS_SUCCESS) elif (category.lower() in bypass): - # DEBUG#print "Bypass Further Processing" + #DEBUG#print "Bypass Further Processing" sys.exit(POSTPROCESS_NONE) else: diff --git a/apps/templates/nzbget/MP4_Automator/autoProcess.ini b/apps/templates/nzbget/MP4_Automator/autoProcess.ini index 65c5740..8122743 100644 --- a/apps/templates/nzbget/MP4_Automator/autoProcess.ini +++ b/apps/templates/nzbget/MP4_Automator/autoProcess.ini @@ -141,3 +141,4 @@ host = plex port = 32400 refresh = False token = + diff --git a/apps/templates/nzbget/cont-init.d/30-config b/apps/templates/nzbget/cont-init.d/30-config index 79024ed..deaaacd 100644 --- a/apps/templates/nzbget/cont-init.d/30-config +++ b/apps/templates/nzbget/cont-init.d/30-config @@ -1,11 +1,11 @@ #!/usr/bin/with-contenv bash # delete lock file if found -[[ -f /downloads/nzbget.lock ]] && +[[ -f /downloads/nzbget.lock ]] && \ rm /downloads/nzbget.lock # check if config file exists in /config -[[ ! -f /config/nzbget.conf ]] && +[[ ! -f /config/nzbget.conf ]] && \ cp /defaults/nzbget.conf /config/nzbget.conf # permissions @@ -20,8 +20,8 @@ chmod u+rw \ chmod 777 -R \ /config chmod 777 -R \ - /app/nzbget + /app/nzbget chmod 777 -R \ - /downloads + /downloads exec /config/installer/installer.sh diff --git a/apps/templates/nzbget/ffmpeg-build/build-ffmpeg b/apps/templates/nzbget/ffmpeg-build/build-ffmpeg index 6d28362..fc9fee9 100644 --- a/apps/templates/nzbget/ffmpeg-build/build-ffmpeg +++ b/apps/templates/nzbget/ffmpeg-build/build-ffmpeg @@ -15,39 +15,39 @@ ADDITIONAL_CONFIGURE_OPTIONS="" # Speed up the process # Env Var NUMJOBS overrides automatic detection if [[ -n $NUMJOBS ]]; then - MJOBS=$NUMJOBS + MJOBS=$NUMJOBS elif [[ -f /proc/cpuinfo ]]; then - MJOBS=$(grep -c processor /proc/cpuinfo) + MJOBS=$(grep -c processor /proc/cpuinfo) elif [[ "$OSTYPE" == "darwin"* ]]; then MJOBS=$(sysctl -n machdep.cpu.thread_count) ADDITIONAL_CONFIGURE_OPTIONS="--enable-videotoolbox" else - MJOBS=4 + MJOBS=4 fi -make_dir() { +make_dir () { if [ ! -d $1 ]; then if ! mkdir $1; then - printf "\n Failed to create dir %s" "$1" + printf "\n Failed to create dir %s" "$1"; exit 1 fi fi } -remove_dir() { +remove_dir () { if [ -d $1 ]; then rm -r "$1" fi } -download() { - - DOWNLOAD_PATH=$PACKAGES +download () { + DOWNLOAD_PATH=$PACKAGES; + if [ ! -z "$3" ]; then mkdir -p $PACKAGES/$3 DOWNLOAD_PATH=$PACKAGES/$3 - fi + fi; if [ ! -f "$DOWNLOAD_PATH/$2" ]; then @@ -57,7 +57,7 @@ download() { EXITCODE=$? if [ $EXITCODE -ne 0 ]; then echo "" - echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds" + echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds"; sleep 10 curl -L --silent -o "$DOWNLOAD_PATH/$2" "$1" fi @@ -65,34 +65,34 @@ download() { EXITCODE=$? if [ $EXITCODE -ne 0 ]; then echo "" - echo "Failed to download $1. Exitcode $EXITCODE" + echo "Failed to download $1. Exitcode $EXITCODE"; exit 1 fi echo "... Done" if ! tar -xvf "$DOWNLOAD_PATH/$2" -C "$DOWNLOAD_PATH" 2>/dev/null >/dev/null; then - echo "Failed to extract $2" + echo "Failed to extract $2"; exit 1 fi fi } -execute() { +execute () { echo "$ $*" OUTPUT=$($@ 2>&1) if [ $? -ne 0 ]; then - echo "$OUTPUT" - echo "" - echo "Failed to Execute $*" >&2 - exit 1 - fi + echo "$OUTPUT" + echo "" + echo "Failed to Execute $*" >&2 + exit 1 + fi } -build() { +build () { echo "" echo "building $1" echo "=======================" @@ -106,14 +106,15 @@ build() { } command_exists() { - if ! [[ -x $(command -v "$1") ]]; then - return 1 - fi + if ! [[ -x $(command -v "$1") ]]; then + return 1 + fi - return 0 + return 0 } -build_done() { + +build_done () { touch "$PACKAGES/$1.done" } @@ -128,18 +129,18 @@ case "$1" in echo "Cleanup done." echo "" exit 0 - ;; -"--build") ;; + ;; +"--build") -\ - *) - echo "Usage: $0" - echo " --build: start building process" - echo " --cleanup: remove all working dirs" - echo " --help: show this help" - echo "" - exit 0 - ;; + ;; +*) + echo "Usage: $0" + echo " --build: start building process" + echo " --cleanup: remove all working dirs" + echo " --help: show this help" + echo "" + exit 0 + ;; esac echo "Using $MJOBS make jobs simultaneously." @@ -150,18 +151,18 @@ make_dir $WORKSPACE export PATH=${WORKSPACE}/bin:$PATH if ! command_exists "make"; then - echo "make not installed." - exit 1 + echo "make not installed."; + exit 1 fi if ! command_exists "g++"; then - echo "g++ not installed." - exit 1 + echo "g++ not installed."; + exit 1 fi if ! command_exists "curl"; then - echo "curl not installed." - exit 1 + echo "curl not installed."; + exit 1 fi if build "yasm"; then @@ -192,14 +193,14 @@ if build "opencore"; then fi if build "libvpx"; then - download "https://github.com/webmproject/libvpx/archive/v1.7.0.tar.gz" "libvpx-1.7.0.tar.gz" - cd $PACKAGES/libvpx-*0 || exit + download "https://github.com/webmproject/libvpx/archive/v1.7.0.tar.gz" "libvpx-1.7.0.tar.gz" + cd $PACKAGES/libvpx-*0 || exit - if [[ "$OSTYPE" == "darwin"* ]]; then - echo "Applying Darwin patch" - sed "s/,--version-script//g" build/make/Makefile >build/make/Makefile.patched - sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched >build/make/Makefile - fi + if [[ "$OSTYPE" == "darwin"* ]]; then + echo "Applying Darwin patch" + sed "s/,--version-script//g" build/make/Makefile > build/make/Makefile.patched + sed "s/-Wl,--no-undefined -Wl,-soname/-Wl,-undefined,error -Wl,-install_name/g" build/make/Makefile.patched > build/make/Makefile + fi execute ./configure --prefix=${WORKSPACE} --disable-unit-tests --disable-shared execute make -j $MJOBS @@ -218,14 +219,14 @@ fi if build "xvidcore"; then download "http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz" "xvidcore-1.3.4.tar.gz" - cd $PACKAGES/xvidcore || exit - cd build/generic || exit + cd $PACKAGES/xvidcore || exit + cd build/generic || exit execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static execute make -j $MJOBS execute make install if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then - execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib" + execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib" fi build_done "xvidcore" @@ -237,11 +238,11 @@ if build "x264"; then if [[ "$OSTYPE" == "linux-gnu" ]]; then execute ./configure --prefix=${WORKSPACE} --enable-static --enable-pic CXXFLAGS="-fPIC" - else - execute ./configure --prefix=${WORKSPACE} --enable-static --enable-pic - fi + else + execute ./configure --prefix=${WORKSPACE} --enable-static --enable-pic + fi - execute make -j $MJOBS + execute make -j $MJOBS execute make install execute make install-lib-static build_done "x264" @@ -268,7 +269,7 @@ fi if build "libtheora"; then download "http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz" "libtheora-1.1.1.tar.bz" cd $PACKAGES/libtheora-1.1.1 || exit - sed "s/-fforce-addr//g" configure >configure.patched + sed "s/-fforce-addr//g" configure > configure.patched chmod +x configure.patched mv configure.patched configure execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --with-vorbis-libraries=${WORKSPACE}/lib --with-vorbis-includes=${WORKSPACE}/include/ --enable-static --disable-shared --disable-oggtest --disable-vorbistest --disable-examples --disable-asm @@ -288,7 +289,7 @@ fi if build "cmake"; then download "https://cmake.org/files/v3.11/cmake-3.11.3.tar.gz" "cmake-3.11.3.tar.gz" - cd $PACKAGES/cmake-3.11.3 || exit + cd $PACKAGES/cmake-3.11.3 || exit rm Modules/FindJava.cmake perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt @@ -314,7 +315,7 @@ if build "x265"; then execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} -DENABLE_SHARED:bool=off . execute make -j $MJOBS execute make install - sed "s/-lx265/-lx265 -lstdc++/g" "$WORKSPACE/lib/pkgconfig/x265.pc" >"$WORKSPACE/lib/pkgconfig/x265.pc.tmp" + sed "s/-lx265/-lx265 -lstdc++/g" "$WORKSPACE/lib/pkgconfig/x265.pc" > "$WORKSPACE/lib/pkgconfig/x265.pc.tmp" mv "$WORKSPACE/lib/pkgconfig/x265.pc.tmp" "$WORKSPACE/lib/pkgconfig/x265.pc" build_done "x265" fi @@ -328,16 +329,17 @@ if build "fdk_aac"; then build_done "fdk_aac" fi + build "ffmpeg" download "http://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2" "ffmpeg-snapshot.tar.bz2" cd $PACKAGES/ffmpeg-4.1 || exit ./configure $ADDITIONAL_CONFIGURE_OPTIONS \ - --pkgconfigdir="$WORKSPACE/lib/pkgconfig" \ - --prefix=${WORKSPACE} \ - --pkg-config-flags="--static" \ - --extra-cflags="-I$WORKSPACE/include" \ - --extra-ldflags="-L$WORKSPACE/lib" \ - --extra-libs="-lpthread -lm" \ + --pkgconfigdir="$WORKSPACE/lib/pkgconfig" \ + --prefix=${WORKSPACE} \ + --pkg-config-flags="--static" \ + --extra-cflags="-I$WORKSPACE/include" \ + --extra-ldflags="-L$WORKSPACE/lib" \ + --extra-libs="-lpthread -lm" \ --enable-static \ --disable-debug \ --disable-shared \ @@ -366,13 +368,14 @@ execute make install INSTALL_FOLDER="/usr/bin" if [[ "$OSTYPE" == "darwin"* ]]; then - INSTALL_FOLDER="/usr/local/bin" +INSTALL_FOLDER="/usr/local/bin" fi echo "" echo "Building done. The binary can be found here: $WORKSPACE/bin/ffmpeg" echo "" + if [[ $AUTOINSTALL == "yes" ]]; then if command_exists "sudo"; then sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg" @@ -385,11 +388,11 @@ elif [[ ! $SKIPINSTALL == "yes" ]]; then read -r -p "Install the binary to your $INSTALL_FOLDER folder? [Y/n] " response case $response in - [yY][eE][sS] | [yY]) - sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg" - sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe" - echo "Done. ffmpeg is now installed to your system" - ;; + [yY][eE][sS]|[yY]) + sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg" + sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe" + echo "Done. ffmpeg is now installed to your system" + ;; esac fi fi diff --git a/apps/templates/nzbget/ffmpeg-build/web-install.sh b/apps/templates/nzbget/ffmpeg-build/web-install.sh index 6c87270..ffe4158 100644 --- a/apps/templates/nzbget/ffmpeg-build/web-install.sh +++ b/apps/templates/nzbget/ffmpeg-build/web-install.sh @@ -1,13 +1,13 @@ #!/bin/bash # Helper script to download and run the build-ffmpeg script. -make_dir() { +make_dir () { if [ ! -d $1 ]; then - if ! mkdir $1; then - printf "\n Failed to create dir %s" "$1" + if ! mkdir $1; then + printf "\n Failed to create dir %s" "$1"; exit 1 fi - fi + fi } command_exists() { @@ -21,7 +21,7 @@ command_exists() { TARGET='ffmpeg-build' if ! command_exists "curl"; then - echo "curl not installed." + echo "curl not installed."; exit 1 fi @@ -37,3 +37,4 @@ echo "Now we download and execute the build script" echo "" bash build-ffmpeg --build + diff --git a/apps/templates/nzbget/scripts/DeleteSamples.py b/apps/templates/nzbget/scripts/DeleteSamples.py index 403ba01..395628f 100644 --- a/apps/templates/nzbget/scripts/DeleteSamples.py +++ b/apps/templates/nzbget/scripts/DeleteSamples.py @@ -16,7 +16,6 @@ NZBGET_POSTPROCESS_SUCCESS = 93 NZBGET_POSTPROCESS_ERROR = 94 NZBGET_POSTPROCESS_NONE = 95 - def is_sample(filePath, inputName, maxSampleSize, SampleIDs): # 200 MB in bytes SIZE_CUTOFF = int(maxSampleSize) * 1024 * 1024 @@ -30,18 +29,15 @@ def is_sample(filePath, inputName, maxSampleSize, SampleIDs): # Return False if none of these were met. return False - if not os.environ.has_key('NZBOP_SCRIPTDIR'): print "This script can only be called from NZBGet (11.0 or later)." sys.exit(0) if os.environ['NZBOP_VERSION'][0:5] < '11.0': - print "NZBGet Version %s is not supported. Please update NZBGet." % ( - str(os.environ['NZBOP_VERSION'])) + print "NZBGet Version %s is not supported. Please update NZBGet." % (str(os.environ['NZBOP_VERSION'])) sys.exit(0) -print "Script triggered from NZBGet Version %s." % ( - str(os.environ['NZBOP_VERSION'])) +print "Script triggered from NZBGet Version %s." % (str(os.environ['NZBOP_VERSION'])) status = 0 if os.environ.has_key('NZBPP_TOTALSTATUS'): if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': @@ -73,8 +69,7 @@ else: # Check if destination directory exists (important for reprocessing of history items) if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): - print "Nothing to post-process: destination directory", os.environ[ - 'NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." + print "Nothing to post-process: destination directory", os.environ['NZBPP_DIRECTORY'], "doesn't exist. Setting status \"failed\"." status = 1 # All checks done, now launching the script. @@ -87,9 +82,8 @@ for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']): for file in filenames: filePath = os.path.join(dirpath, file) fileName, fileExtension = os.path.splitext(file) - if fileExtension in mediaContainer or ".*" in mediaContainer: # If the file is a video file - # Ignore samples - if is_sample(filePath, os.environ['NZBPP_NZBNAME'], os.environ['NZBPO_MAXSAMPLESIZE'], SampleIDs): + if fileExtension in mediaContainer or ".*" in mediaContainer : # If the file is a video file + if is_sample(filePath, os.environ['NZBPP_NZBNAME'], os.environ['NZBPO_MAXSAMPLESIZE'], SampleIDs): # Ignore samples print "Deleting sample file: ", filePath try: os.unlink(filePath) diff --git a/apps/templates/nzbget/scripts/flatten.py b/apps/templates/nzbget/scripts/flatten.py index 4b16c79..73dd0d5 100644 --- a/apps/templates/nzbget/scripts/flatten.py +++ b/apps/templates/nzbget/scripts/flatten.py @@ -22,17 +22,14 @@ if not os.environ.has_key('NZBOP_SCRIPTDIR'): sys.exit(0) if os.environ['NZBOP_VERSION'][0:5] < '11.0': - print "[ERROR] NZBGet Version %s is not supported. Please update NZBGet." % ( - str(os.environ['NZBOP_VERSION'])) + print "[ERROR] NZBGet Version %s is not supported. Please update NZBGet." % (str(os.environ['NZBOP_VERSION'])) sys.exit(0) -print "Script triggered from NZBGet Version %s." % ( - str(os.environ['NZBOP_VERSION'])) +print "Script triggered from NZBGet Version %s." % (str(os.environ['NZBOP_VERSION'])) status = 0 if os.environ.has_key('NZBPP_TOTALSTATUS'): if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': - print "[ERROR] Download failed with status %s." % ( - os.environ['NZBPP_STATUS']) + print "[ERROR] Download failed with status %s." % (os.environ['NZBPP_STATUS']) status = 1 else: @@ -67,9 +64,8 @@ if not os.path.isdir(os.environ['NZBPP_DIRECTORY']): if status == 1: sys.exit(NZBGET_POSTPROCESS_NONE) - def removeEmptyFolders(path, removeRoot=True): - # Function to remove empty folders + #Function to remove empty folders if not os.path.isdir(path): return @@ -88,7 +84,6 @@ def removeEmptyFolders(path, removeRoot=True): print "[INFO] Removing empty folder:%s" % path os.rmdir(path) - directory = os.path.normpath(os.environ['NZBPP_DIRECTORY']) if os.environ['NZBPO_DESTINATIONDIRECTORY'] and os.path.isdir(os.environ['NZBPO_DESTINATIONDIRECTORY']): destination = os.environ['NZBPO_DESTINATIONDIRECTORY'] diff --git a/apps/templates/nzbget/scripts/hash.py b/apps/templates/nzbget/scripts/hash.py index 07855b6..f2fbec1 100644 --- a/apps/templates/nzbget/scripts/hash.py +++ b/apps/templates/nzbget/scripts/hash.py @@ -25,25 +25,21 @@ NZBGET_POSTPROCESS_NONE = 95 # EXTENSION STUFF ############################################################ - def do_check(): if not os.environ.has_key('NZBOP_SCRIPTDIR'): print "This script can only be called from NZBGet (11.0 or later)." sys.exit(0) if os.environ['NZBOP_VERSION'][0:5] < '11.0': - print "[ERROR] NZBGet Version %s is not supported. Please update NZBGet." % ( - str(os.environ['NZBOP_VERSION'])) + print "[ERROR] NZBGet Version %s is not supported. Please update NZBGet." % (str(os.environ['NZBOP_VERSION'])) sys.exit(0) - print "Script triggered from NZBGet Version %s." % ( - str(os.environ['NZBOP_VERSION'])) + print "Script triggered from NZBGet Version %s." % (str(os.environ['NZBOP_VERSION'])) status = 0 if 'NZBPP_TOTALSTATUS' in os.environ: if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': - print "[ERROR] Download failed with status %s." % ( - os.environ['NZBPP_STATUS']) + print "[ERROR] Download failed with status %s." % (os.environ['NZBPP_STATUS']) status = 1 else: # Check par status @@ -148,8 +144,7 @@ if not found_files: print("[INFO] No files were found in \"%s\"" % directory) sys.exit(NZBGET_POSTPROCESS_NONE) else: - print("[INFO] Found %d files to check for hashed filenames" % - len(found_files)) + print("[INFO] Found %d files to check for hashed filenames" % len(found_files)) # loop files checking for file hash moved_files = 0 for found_file_path in found_files: @@ -159,18 +154,14 @@ else: # is this a file hash if is_file_hash(file_name): - new_file_path = os.path.join( - dir_name, "%s.%s" % (nzb_name, file_ext)) - print("[INFO] Moving \"%s\" to \"%s\"" % - (found_file_path, new_file_path)) + new_file_path = os.path.join(dir_name, "%s.%s" % (nzb_name, file_ext)) + print("[INFO] Moving \"%s\" to \"%s\"" % (found_file_path, new_file_path)) try: shutil.move(found_file_path, new_file_path) moved_files += 1 except Exception: - print("[ERROR] Failed moving \"%s\" to \"%s\"" % - (found_file_path, new_file_path)) + print("[ERROR] Failed moving \"%s\" to \"%s\"" % (found_file_path, new_file_path)) - print("[INFO] Finished processing \"%s\", moved %d files" % - (directory, moved_files)) + print("[INFO] Finished processing \"%s\", moved %d files" % (directory, moved_files)) sys.exit(NZBGET_POSTPROCESS_SUCCESS) diff --git a/apps/templates/nzbget/scripts/rarfile/__init__.py b/apps/templates/nzbget/scripts/rarfile/__init__.py index e69de29..8b13789 100644 --- a/apps/templates/nzbget/scripts/rarfile/__init__.py +++ b/apps/templates/nzbget/scripts/rarfile/__init__.py @@ -0,0 +1 @@ + diff --git a/apps/templates/nzbget/scripts/rarfile/rarfile.py b/apps/templates/nzbget/scripts/rarfile/rarfile.py index 4b793d3..c6e0d44 100644 --- a/apps/templates/nzbget/scripts/rarfile/rarfile.py +++ b/apps/templates/nzbget/scripts/rarfile/rarfile.py @@ -64,7 +64,7 @@ For more details, refer to source. from __future__ import division, print_function ## -# Imports and compat - support both Python 2.x and 3.x +## Imports and compat - support both Python 2.x and 3.x ## import sys @@ -113,16 +113,13 @@ try: class AES_CBC_Decrypt(object): """Decrypt API""" - def __init__(self, key, iv): - ciph = Cipher(algorithms.AES(key), - modes.CBC(iv), default_backend()) + ciph = Cipher(algorithms.AES(key), modes.CBC(iv), default_backend()) self.decrypt = ciph.decryptor().update def pbkdf2_sha256(password, salt, iters): """PBKDF2 with HMAC-SHA256""" - ctx = pbkdf2.PBKDF2HMAC( - hashes.SHA256(), 32, salt, iters, default_backend()) + ctx = pbkdf2.PBKDF2HMAC(hashes.SHA256(), 32, salt, iters, default_backend()) return ctx.derive(password) except ImportError: @@ -131,7 +128,6 @@ try: class AES_CBC_Decrypt(object): """Decrypt API""" - def __init__(self, key, iv): self.decrypt = AES.new(key, AES.MODE_CBC, iv).decrypt @@ -177,7 +173,7 @@ __version__ = '3.0' __all__ = ['is_rarfile', 'RarInfo', 'RarFile', 'RarExtFile'] ## -# Module configuration. Can be tuned after importing. +## Module configuration. Can be tuned after importing. ## #: default fallback charset @@ -226,72 +222,72 @@ HACK_SIZE_LIMIT = 20 * 1024 * 1024 PATH_SEP = '/' ## -# rar constants +## rar constants ## # block types -RAR_BLOCK_MARK = 0x72 # r -RAR_BLOCK_MAIN = 0x73 # s -RAR_BLOCK_FILE = 0x74 # t -RAR_BLOCK_OLD_COMMENT = 0x75 # u -RAR_BLOCK_OLD_EXTRA = 0x76 # v -RAR_BLOCK_OLD_SUB = 0x77 # w -RAR_BLOCK_OLD_RECOVERY = 0x78 # x -RAR_BLOCK_OLD_AUTH = 0x79 # y -RAR_BLOCK_SUB = 0x7a # z -RAR_BLOCK_ENDARC = 0x7b # { +RAR_BLOCK_MARK = 0x72 # r +RAR_BLOCK_MAIN = 0x73 # s +RAR_BLOCK_FILE = 0x74 # t +RAR_BLOCK_OLD_COMMENT = 0x75 # u +RAR_BLOCK_OLD_EXTRA = 0x76 # v +RAR_BLOCK_OLD_SUB = 0x77 # w +RAR_BLOCK_OLD_RECOVERY = 0x78 # x +RAR_BLOCK_OLD_AUTH = 0x79 # y +RAR_BLOCK_SUB = 0x7a # z +RAR_BLOCK_ENDARC = 0x7b # { # flags for RAR_BLOCK_MAIN -RAR_MAIN_VOLUME = 0x0001 -RAR_MAIN_COMMENT = 0x0002 -RAR_MAIN_LOCK = 0x0004 -RAR_MAIN_SOLID = 0x0008 -RAR_MAIN_NEWNUMBERING = 0x0010 -RAR_MAIN_AUTH = 0x0020 -RAR_MAIN_RECOVERY = 0x0040 -RAR_MAIN_PASSWORD = 0x0080 -RAR_MAIN_FIRSTVOLUME = 0x0100 -RAR_MAIN_ENCRYPTVER = 0x0200 +RAR_MAIN_VOLUME = 0x0001 +RAR_MAIN_COMMENT = 0x0002 +RAR_MAIN_LOCK = 0x0004 +RAR_MAIN_SOLID = 0x0008 +RAR_MAIN_NEWNUMBERING = 0x0010 +RAR_MAIN_AUTH = 0x0020 +RAR_MAIN_RECOVERY = 0x0040 +RAR_MAIN_PASSWORD = 0x0080 +RAR_MAIN_FIRSTVOLUME = 0x0100 +RAR_MAIN_ENCRYPTVER = 0x0200 # flags for RAR_BLOCK_FILE -RAR_FILE_SPLIT_BEFORE = 0x0001 -RAR_FILE_SPLIT_AFTER = 0x0002 -RAR_FILE_PASSWORD = 0x0004 -RAR_FILE_COMMENT = 0x0008 -RAR_FILE_SOLID = 0x0010 -RAR_FILE_DICTMASK = 0x00e0 -RAR_FILE_DICT64 = 0x0000 -RAR_FILE_DICT128 = 0x0020 -RAR_FILE_DICT256 = 0x0040 -RAR_FILE_DICT512 = 0x0060 -RAR_FILE_DICT1024 = 0x0080 -RAR_FILE_DICT2048 = 0x00a0 -RAR_FILE_DICT4096 = 0x00c0 -RAR_FILE_DIRECTORY = 0x00e0 -RAR_FILE_LARGE = 0x0100 -RAR_FILE_UNICODE = 0x0200 -RAR_FILE_SALT = 0x0400 -RAR_FILE_VERSION = 0x0800 -RAR_FILE_EXTTIME = 0x1000 -RAR_FILE_EXTFLAGS = 0x2000 +RAR_FILE_SPLIT_BEFORE = 0x0001 +RAR_FILE_SPLIT_AFTER = 0x0002 +RAR_FILE_PASSWORD = 0x0004 +RAR_FILE_COMMENT = 0x0008 +RAR_FILE_SOLID = 0x0010 +RAR_FILE_DICTMASK = 0x00e0 +RAR_FILE_DICT64 = 0x0000 +RAR_FILE_DICT128 = 0x0020 +RAR_FILE_DICT256 = 0x0040 +RAR_FILE_DICT512 = 0x0060 +RAR_FILE_DICT1024 = 0x0080 +RAR_FILE_DICT2048 = 0x00a0 +RAR_FILE_DICT4096 = 0x00c0 +RAR_FILE_DIRECTORY = 0x00e0 +RAR_FILE_LARGE = 0x0100 +RAR_FILE_UNICODE = 0x0200 +RAR_FILE_SALT = 0x0400 +RAR_FILE_VERSION = 0x0800 +RAR_FILE_EXTTIME = 0x1000 +RAR_FILE_EXTFLAGS = 0x2000 # flags for RAR_BLOCK_ENDARC -RAR_ENDARC_NEXT_VOLUME = 0x0001 -RAR_ENDARC_DATACRC = 0x0002 -RAR_ENDARC_REVSPACE = 0x0004 -RAR_ENDARC_VOLNR = 0x0008 +RAR_ENDARC_NEXT_VOLUME = 0x0001 +RAR_ENDARC_DATACRC = 0x0002 +RAR_ENDARC_REVSPACE = 0x0004 +RAR_ENDARC_VOLNR = 0x0008 # flags common to all blocks -RAR_SKIP_IF_UNKNOWN = 0x4000 -RAR_LONG_BLOCK = 0x8000 +RAR_SKIP_IF_UNKNOWN = 0x4000 +RAR_LONG_BLOCK = 0x8000 # Host OS types RAR_OS_MSDOS = 0 -RAR_OS_OS2 = 1 +RAR_OS_OS2 = 1 RAR_OS_WIN32 = 2 -RAR_OS_UNIX = 3 +RAR_OS_UNIX = 3 RAR_OS_MACOS = 4 -RAR_OS_BEOS = 5 +RAR_OS_BEOS = 5 # Compression methods - '0'..'5' RAR_M0 = 0x30 @@ -373,7 +369,7 @@ RAR5_OS_WINDOWS = 0 RAR5_OS_UNIX = 1 ## -# internal constants +## internal constants ## RAR_ID = b"Rar!\x1a\x07\x00" @@ -383,7 +379,6 @@ EMPTY = b'' UTC = timezone(timedelta(0), 'UTC') BSIZE = 32 * 1024 - def _get_rar_version(xfile): '''Check quickly whether file is rar archive. ''' @@ -396,108 +391,83 @@ def _get_rar_version(xfile): return 0 ## -# Public interface +## Public interface ## - def is_rarfile(xfile): '''Check quickly whether file is rar archive. ''' return _get_rar_version(xfile) > 0 - class Error(Exception): """Base class for rarfile errors.""" - class BadRarFile(Error): """Incorrect data in archive.""" - class NotRarFile(Error): """The file is not RAR archive.""" - class BadRarName(Error): """Cannot guess multipart name components.""" - class NoRarEntry(Error): """File not found in RAR""" - class PasswordRequired(Error): """File requires password""" - class NeedFirstVolume(Error): """Need to start from first volume.""" - class NoCrypto(Error): """Cannot parse encrypted headers - no crypto available.""" - class RarExecError(Error): """Problem reported by unrar/rar.""" - class RarWarning(RarExecError): """Non-fatal error""" - class RarFatalError(RarExecError): """Fatal error""" - class RarCRCError(RarExecError): """CRC error during unpacking""" - class RarLockedArchiveError(RarExecError): """Must not modify locked archive""" - class RarWriteError(RarExecError): """Write error""" - class RarOpenError(RarExecError): """Open error""" - class RarUserError(RarExecError): """User error""" - class RarMemoryError(RarExecError): """Memory error""" - class RarCreateError(RarExecError): """Create error""" - class RarNoFilesError(RarExecError): """No files that match pattern were found""" - class RarUserBreak(RarExecError): """User stop""" - class RarWrongPassword(RarExecError): """Incorrect password""" - class RarUnknownError(RarExecError): """Unknown exit code""" - class RarSignalExit(RarExecError): """Unrar exited with signal""" - class RarCannotExec(RarExecError): """Executable not found.""" @@ -764,15 +734,13 @@ class RarFile(object): # entry lookup inf = self.getinfo(fname) if inf.isdir(): - raise TypeError( - "Directory does not have any data: " + inf.filename) + raise TypeError("Directory does not have any data: " + inf.filename) # check password if inf.needs_password(): psw = psw or self._password if psw is None: - raise PasswordRequired( - "File %s requires password" % inf.filename) + raise PasswordRequired("File %s requires password" % inf.filename) else: psw = None @@ -863,7 +831,7 @@ class RarFile(object): return self._file_parser.strerror() ## - # private methods + ## private methods ## def _parse(self): @@ -914,7 +882,6 @@ class RarFile(object): # File format parsing # - class CommonParser(object): """Shared parser parts.""" _main = None @@ -1044,8 +1011,7 @@ class CommonParser(object): # RAR 2.x does not set FIRSTVOLUME, # so check it only if NEWNUMBERING is used if (h.flags & RAR_MAIN_FIRSTVOLUME) == 0: - raise NeedFirstVolume( - "Need to start from first volume") + raise NeedFirstVolume("Need to start from first volume") if h.flags & RAR_MAIN_PASSWORD: self._needs_password = True if not self._password: @@ -1128,8 +1094,7 @@ class CommonParser(object): raise BadRarFile('cannot find copied file') if inf.flags & RAR_FILE_SPLIT_BEFORE: - raise NeedFirstVolume( - "Partial file, please start from first volume: " + inf.filename) + raise NeedFirstVolume("Partial file, please start from first volume: " + inf.filename) # is temp write usable? use_hack = 1 @@ -1216,7 +1181,6 @@ class CommonParser(object): # RAR3 format # - class Rar3Info(RarInfo): """RAR3 specific fields.""" extract_version = 15 @@ -1414,7 +1378,7 @@ class RAR3Parser(CommonParser): if stype == RAR_BLOCK_OLD_COMMENT and pos + S_COMMENT_HDR.size <= pos_next: declen, ver, meth, crc = S_COMMENT_HDR.unpack_from(hdata, pos) pos += S_COMMENT_HDR.size - data = hdata[pos: pos_next] + data = hdata[pos : pos_next] cmt = rar3_decompress(ver, meth, data, declen, sflags, crc, self._password) if not self._crc_check: @@ -1500,7 +1464,6 @@ class RAR3Parser(CommonParser): # RAR5 format # - class Rar5Info(RarInfo): """Shared fields for RAR5 records. """ @@ -1908,14 +1871,12 @@ class RAR5Parser(CommonParser): return self._open_hack_core(inf, psw, RAR5_ID + main_hdr, endarc_hdr) ## -# Utility classes +## Utility classes ## - class UnicodeFilename(object): """Handle RAR3 unicode filename decompression. """ - def __init__(self, name, encdata): self.std_name = bytearray(name) self.encdata = bytearray(encdata) @@ -2232,10 +2193,10 @@ class PipeReader(RarExtFile): vbuf = memoryview(buf) res = got = 0 while got < cnt: - res = self._fd.readinto(vbuf[got: cnt]) + res = self._fd.readinto(vbuf[got : cnt]) if not res: break - self._md_context.update(vbuf[got: got + res]) + self._md_context.update(vbuf[got : got + res]) self._remain -= res got += res return got @@ -2355,10 +2316,10 @@ class DirectReader(RarExtFile): cnt = self._cur_avail # read into temp view - res = self._fd.readinto(vbuf[got: got + cnt]) + res = self._fd.readinto(vbuf[got : got + cnt]) if not res: break - self._md_context.update(vbuf[got: got + res]) + self._md_context.update(vbuf[got : got + res]) self._cur_avail -= res self._remain -= res got += res @@ -2367,7 +2328,6 @@ class DirectReader(RarExtFile): class HeaderDecrypt(object): """File-like object that decrypts from another file""" - def __init__(self, f, key, iv): self.f = f self.ciph = AES_CBC_Decrypt(key, iv) @@ -2454,16 +2414,12 @@ class XFile(object): class NoHashContext(object): """No-op hash function.""" - def __init__(self, data=None): """Initialize""" - def update(self, data): """Update data""" - def digest(self): """Final hash""" - def hexdigest(self): """Hexadecimal digest.""" @@ -2554,10 +2510,9 @@ class Blake2SP(object): return tohex(self.digest()) ## -# Utility functions +## Utility functions ## - S_LONG = Struct(' len(buf): raise BadRarFile('cannot load bytes') - return buf[pos: end], end - + return buf[pos : end], end def load_vstr(buf, pos): """Load bytes prefixed by vint length""" slen, pos = load_vint(buf, pos) return load_bytes(buf, slen, pos) - def load_dostime(buf, pos): """Load LE32 dos timestamp""" stamp, pos = load_le32(buf, pos) tup = parse_dos_time(stamp) return to_datetime(tup), pos - def load_unixtime(buf, pos): """Load LE32 unix timestamp""" secs, pos = load_le32(buf, pos) dt = datetime.fromtimestamp(secs, UTC) return dt, pos - def load_windowstime(buf, pos): """Load LE64 windows timestamp""" # unix epoch (1970) in seconds from windows epoch (1601) @@ -2637,8 +2584,6 @@ def load_windowstime(buf, pos): return dt, pos # new-style next volume - - def _next_newvol(volfile): i = len(volfile) - 1 while i >= 0: @@ -2648,8 +2593,6 @@ def _next_newvol(volfile): raise BadRarName("Cannot construct volume name: " + volfile) # old-style next volume - - def _next_oldvol(volfile): # rar -> r00 if volfile[-4:].lower() == '.rar': @@ -2657,8 +2600,6 @@ def _next_oldvol(volfile): return _inc_volname(volfile, len(volfile) - 1) # increase digits with carry, otherwise just increment char - - def _inc_volname(volfile, i): fn = list(volfile) while i >= 0: @@ -2670,8 +2611,6 @@ def _inc_volname(volfile, i): return ''.join(fn) # rar3 extended time fields - - def _parse_ext_time(h, data, pos): # flags and rest of data can be missing flags = 0 @@ -2689,8 +2628,6 @@ def _parse_ext_time(h, data, pos): return pos # rar3 one extended time field - - def _parse_xtime(flag, data, pos, basetime=None): res = None if flag & 8: @@ -2711,13 +2648,11 @@ def _parse_xtime(flag, data, pos, basetime=None): # dostime has room for 30 seconds only, correct if needed if flag & 4 and basetime.second < 59: - res = basetime.replace( - microsecond=usec, second=basetime.second + 1) + res = basetime.replace(microsecond=usec, second=basetime.second + 1) else: res = basetime.replace(microsecond=usec) return res, pos - def is_filelike(obj): """Filename or file object? """ @@ -2730,7 +2665,6 @@ def is_filelike(obj): raise ValueError("Invalid object passed as file") return True - def rar3_s2k(psw, salt): """String-to-key hash for RAR3. """ @@ -2749,7 +2683,6 @@ def rar3_s2k(psw, salt): key_le = pack("LLLL", key_be)) return key_le, iv - def rar3_decompress(vers, meth, data, declen=0, flags=0, crc=0, psw=None, salt=None): """Decompress blob of compressed data. @@ -2801,7 +2734,6 @@ def rar3_decompress(vers, meth, data, declen=0, flags=0, crc=0, psw=None, salt=N tmpf.close() os.unlink(tmpname) - def to_datetime(t): """Convert 6-part time tuple into datetime object. """ @@ -2840,7 +2772,6 @@ def to_datetime(t): day = 28 return datetime(year, mon, day, h, m, s) - def parse_dos_time(stamp): """Parse standard 32-bit DOS timestamp. """ @@ -2852,7 +2783,6 @@ def parse_dos_time(stamp): yr = (stamp & 0x7F) + 1980 return (yr, mon, day, hr, mn, sec * 2) - def custom_popen(cmd): """Disconnect cmd from parent fds, read only from stdout. """ @@ -2867,12 +2797,10 @@ def custom_popen(cmd): creationflags=creationflags) except OSError as ex: if ex.errno == errno.ENOENT: - raise RarCannotExec( - "Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL) + raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL) raise return p - def custom_check(cmd, ignore_retcode=False): """Run command, collect output, raise error if needed. """ @@ -2882,7 +2810,6 @@ def custom_check(cmd, ignore_retcode=False): raise RarExecError("Check-run failed") return out - def add_password_arg(cmd, psw, ___required=False): """Append password switch to commandline. """ @@ -2893,7 +2820,6 @@ def add_password_arg(cmd, psw, ___required=False): else: cmd.append('-p-') - def check_returncode(p, out): """Raise exception according to unrar exit code. """ @@ -2925,12 +2851,10 @@ def check_returncode(p, out): raise exc(msg) - def hmac_sha256(key, data): """HMAC-SHA256""" return HMAC(key, data, sha256).digest() - def membuf_tempfile(memfile): memfile.seek(0, 0) @@ -2950,7 +2874,6 @@ def membuf_tempfile(memfile): raise return tmpname - class XTempFile(object): __slots__ = ('_tmpfile', '_filename') @@ -2977,13 +2900,11 @@ class XTempFile(object): # Check if unrar works # - ORIG_UNRAR_TOOL = UNRAR_TOOL ORIG_OPEN_ARGS = OPEN_ARGS ORIG_EXTRACT_ARGS = EXTRACT_ARGS ORIG_TEST_ARGS = TEST_ARGS - def _check_unrar_tool(): global UNRAR_TOOL, OPEN_ARGS, EXTRACT_ARGS, TEST_ARGS try: @@ -3007,5 +2928,5 @@ def _check_unrar_tool(): # no usable tool, only uncompressed archives work pass - _check_unrar_tool() + diff --git a/apps/templates/nzbget/scripts/reverse_name.py b/apps/templates/nzbget/scripts/reverse_name.py index 6e09d32..98819d0 100644 --- a/apps/templates/nzbget/scripts/reverse_name.py +++ b/apps/templates/nzbget/scripts/reverse_name.py @@ -18,8 +18,8 @@ reverse_list = [r"\.\d{2}e\d{2}s\.", r"\.p0612\.", r"\.[pi]0801\.", r"\.p027\.", reverse_pattern = re.compile('|'.join(reverse_list), flags=re.IGNORECASE) season_pattern = re.compile(r"(.*\.\d{2}e\d{2}s\.)(.*)", flags=re.IGNORECASE) word_pattern = re.compile(r"([^A-Z0-9]*[A-Z0-9]+)") -char_replace = [[r"(\w)1\.(\w)", r"\1i\2"] - ] +char_replace = [[r"(\w)1\.(\w)",r"\1i\2"] +] garbage_name = re.compile(r"^[a-zA-Z0-9]{2,}$") media_list = [r"\.s\d{2}e\d{2}\.", r"\.2160p\.", r"\.1080[pi]\.", r"\.720p\.", r"\.576[pi]\.", r"\.480[pi]\.", r"\.360p\.", r"\.[xh]26[45]\b", r"\.bluray\.", r"\.[hp]dtv\.", r'\.web(?:[.-]?dl)?\.', r"\.(vhs|vod|dvd|web|bd|br).?rip\.", r"\.dvdr\b", r"\.stv\.", r"\.screener\.", r"\.vcd\.", r"\bhd(cam|rip)\b", r"\.proper\.", r"\.repack\.", @@ -133,14 +133,12 @@ class ek: def ek(func, *args, **kwargs): if 'nt' == os.name: # convert all str parameter values to unicode - args = tuple([x if not isinstance(x, str) - else ek.win_encode_unicode(x) for x in args]) + args = tuple([x if not isinstance(x, str) else ek.win_encode_unicode(x) for x in args]) kwargs = {k: x if not isinstance(x, str) else ek.win_encode_unicode(x) for k, x in kwargs.iteritems()} func_result = func(*args, **kwargs) else: - func_result = func( - *[ek.encode_item(x) if type(x) == str else x for x in args], **kwargs) + func_result = func(*[ek.encode_item(x) if type(x) == str else x for x in args], **kwargs) if type(func_result) in (list, tuple): return ek.fix_list_encoding(func_result) @@ -166,7 +164,6 @@ def tryInt(s, s_default=0): except: return s_default - # NZBGet V11+ # Check if the script is called from nzbget 11.0 or later nzbget_version = evn.get('NZBOP_VERSION', '0.1') @@ -177,17 +174,16 @@ if nzbget_version >= 11: # NZBGet argv: all passed as environment variables. clientAgent = "nzbget" # Exit codes used by NZBGet - POSTPROCESS_PARCHECK = 92 - POSTPROCESS_SUCCESS = 93 - POSTPROCESS_ERROR = 94 - POSTPROCESS_NONE = 95 + POSTPROCESS_PARCHECK=92 + POSTPROCESS_SUCCESS=93 + POSTPROCESS_ERROR=94 + POSTPROCESS_NONE=95 # Check nzbget.conf options status = 0 if evn['NZBOP_UNPACK'] != 'yes': - logger.log( - "Please enable option \"Unpack\" in nzbget configuration file, exiting") + logger.log("Please enable option \"Unpack\" in nzbget configuration file, exiting") sys.exit(POSTPROCESS_NONE) parstatus = evn['NZBPP_PARSTATUS'] @@ -220,24 +216,20 @@ if nzbget_version >= 11: fileExtension = ek.ek(os.path.splitext, file)[1] if fileExtension in ['.par2']: - logger.log( - "Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\"g") + logger.log("Post-Process: Unpack skipped and par-check skipped (although par2-files exist), setting status \"failed\"g") status = 1 break if ek.ek(os.path.isfile, ek.ek(os.path.join, directory, "_brokenlog.txt")) and not status == 1: - logger.log( - "Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") + logger.log("Post-Process: _brokenlog.txt exists, download is probably damaged, exiting") status = 1 if not status == 1: - logger.log( - "Neither par2-files found, _brokenlog.txt doesn't exist, considering download successful") + logger.log("Neither par2-files found, _brokenlog.txt doesn't exist, considering download successful") # Check if destination directory exists (important for reprocessing of history items) if not ek.ek(os.path.isdir, directory): - logger.log( - "Post-Process: Nothing to post-process: destination directory %s doesn't exist" % directory) + logger.log("Post-Process: Nothing to post-process: destination directory %s doesn't exist" % directory) status = 1 # All checks done, now launching the script. @@ -262,39 +254,33 @@ if nzbget_version >= 11: for wp in word_p: if wp[0] == ".": new_words += "." - new_words += re.sub(r"\W", "", wp) + new_words += re.sub(r"\W","",wp) for cr in char_replace: - new_words = re.sub(cr[0], cr[1], new_words) + new_words = re.sub(cr[0],cr[1],new_words) new_filename = new_words[::-1] + na_parts.group(1)[::-1] else: new_filename = fileName[::-1] - logger.log("reversing filename from: %s to %s" % - (fileName, new_filename)) + logger.log("reversing filename from: %s to %s" % (fileName, new_filename)) try: - ek.ek(os.rename, filePath, ek.ek(os.path.join, - dirpath, new_filename + fileExtension)) + ek.ek(os.rename, filePath, ek.ek(os.path.join, dirpath, new_filename + fileExtension)) rd = True - except Exception, e: + except Exception,e: logger.log(e, logger.ERROR) - logger.log("Error: unable to rename file %s" % - file, logger.ERROR) + logger.log("Error: unable to rename file %s" % file, logger.ERROR) pass elif (fileExtension.lower() in media_extentions) and (garbage_name.search(fileName) is not None) and (media_pattern.search(base_name) is not None): videos += 1 old_name = filePath - new_name = ek.ek(os.path.join, dirname, '%s%s' % - (base_name, fileExtension)) + new_name = ek.ek(os.path.join, dirname, '%s%s' % (base_name, fileExtension)) if not rd and videos == 1 and old_name is not None and new_name is not None: - logger.log("renaming the File %s to the Dirname %s" % - (ek.ek(os.path.basename, old_name), base_name)) + logger.log("renaming the File %s to the Dirname %s" % (ek.ek(os.path.basename, old_name), base_name)) try: ek.ek(os.rename, old_name, new_name) rd = True - except Exception, e: + except Exception,e: logger.log(e, logger.ERROR) - logger.log("Error unable to rename file %s" % - old_name, logger.ERROR) + logger.log("Error unable to rename file %s" % old_name, logger.ERROR) pass if rd: @@ -303,6 +289,5 @@ if nzbget_version >= 11: sys.exit(POSTPROCESS_NONE) else: - logger.log( - "This script can only be called from NZBGet (11.0 or later).", logger.ERROR) + logger.log("This script can only be called from NZBGet (11.0 or later).", logger.ERROR) sys.exit(0) diff --git a/apps/templates/nzbget/scripts/unzip.py b/apps/templates/nzbget/scripts/unzip.py index 204c630..521a50f 100644 --- a/apps/templates/nzbget/scripts/unzip.py +++ b/apps/templates/nzbget/scripts/unzip.py @@ -12,15 +12,7 @@ ### NZBGET SCAN SCRIPT ### ############################################################################## -import os -import zipfile -import tarfile -import gzip -import pickle -import datetime -import re -import struct -import locale +import os, zipfile, tarfile, gzip, pickle, datetime, re, struct, locale import rarfile.rarfile as rarfile from gzip import FEXTRA, FNAME @@ -102,11 +94,9 @@ else: dupescore = None dupemode = None -tmp_zipinfo = os.path.join(os.environ.get( - 'NZBOP_TEMPDIR'), r'nzbget\unzip_scan\info') +tmp_zipinfo = os.path.join(os.environ.get('NZBOP_TEMPDIR'), r'nzbget\unzip_scan\info') nzb_list = [] - def read_gzip_info(gzipfile): gf = gzipfile.fileobj pos = gf.tell() @@ -138,14 +128,13 @@ def read_gzip_info(gzipfile): fname = [] while True: s = gf.read(1) - if not s or s == '\000': + if not s or s=='\000': break fname.append(s) gf.seek(pos) return ''.join(fname), size - def save_obj(obj, name): tp = os.path.dirname(name) if not os.path.exists(tp): @@ -160,7 +149,6 @@ def save_obj(obj, name): except: print "Error saving: " + name - def load_obj(name): if os.path.isfile(name): try: @@ -172,7 +160,6 @@ def load_obj(name): else: return None - def save_nzb_list(): if nzb_list: save_obj(nzb_list, tmp_zipinfo) @@ -183,7 +170,6 @@ def save_nzb_list(): except: print "Error deleting " + tmp_zipinfo - def load_nzb_list(): global nzb_list nzb_list = load_obj(tmp_zipinfo) @@ -194,49 +180,39 @@ def load_nzb_list(): if nzb_list is not None and o_l != len(nzb_list): save_nzb_list() - def get_files(zf): zi = zf.infolist() - zi[:] = [el for el in zi if os.path.splitext( - el.filename)[1].lower() == '.nzb'] + zi[:] = [el for el in zi if os.path.splitext(el.filename)[1].lower() == '.nzb'] return zi - def get_tar_files(tf): ti = tf.getmembers() - ti[:] = [el for el in ti if el.isfile() and os.path.splitext(el.name) - [1].lower() == '.nzb'] + ti[:] = [el for el in ti if el.isfile() and os.path.splitext(el.name)[1].lower() == '.nzb'] return ti - def get_rar_files(rf): ri = rf.infolist() - ri[:] = [el for el in ri if os.path.splitext( - el.filename)[1].lower() == '.nzb'] + ri[:] = [el for el in ri if os.path.splitext(el.filename)[1].lower() == '.nzb'] return ri - def remove_filename(): try: os.unlink(filename) except: print "Error deleting " + filename - if ext == '.zip': load_nzb_list() zipf = zipfile.ZipFile(filename, mode='r') zf = get_files(zipf) if zf: - zipf.extractall(path=dir, members=zf) + zipf.extractall(path = dir, members = zf) now = datetime.datetime.now() for z in zf: if nzb_list: - nzb_list.append([z.filename, cat, prio, top, - pause, dupekey, dupescore, dupemode, now]) + nzb_list.append([z.filename, cat, prio, top, pause, dupekey, dupescore, dupemode, now]) else: - nzb_list = [[z.filename, cat, prio, top, - pause, dupekey, dupescore, dupemode, now]] + nzb_list = [[z.filename, cat, prio, top, pause, dupekey, dupescore, dupemode, now]] save_nzb_list() zipf.close() @@ -247,15 +223,13 @@ elif ext in ['.tar.gz', '.tar', '.tgz']: tarf = tarfile.open(filename, mode='r') tf = get_tar_files(tarf) if tf: - tarf.extractall(path=dir, members=tf) + tarf.extractall(path = dir, members = tf) now = datetime.datetime.now() for z in tf: if nzb_list: - nzb_list.append([z.name, cat, prio, top, pause, - dupekey, dupescore, dupemode, now]) + nzb_list.append([z.name, cat, prio, top, pause, dupekey, dupescore, dupemode, now]) else: - nzb_list = [[z.name, cat, prio, top, pause, - dupekey, dupescore, dupemode, now]] + nzb_list = [[z.name, cat, prio, top, pause, dupekey, dupescore, dupemode, now]] save_nzb_list() tarf.close() @@ -263,7 +237,7 @@ elif ext in ['.tar.gz', '.tar', '.tgz']: elif ext == '.gz': load_nzb_list() - gzf = gzip.open(filename, mode='rb') + gzf =gzip.open(filename, mode='rb') out_filename, size = read_gzip_info(gzf) if out_filename and os.path.splitext(out_filename)[1].lower() == '.nzb': with open(os.path.join(os.path.dirname(filename), out_filename), 'wb') as outf: @@ -273,11 +247,9 @@ elif ext == '.gz': if gzf and out_filename: now = datetime.datetime.now() if nzb_list: - nzb_list.append([os.path.basename( - out_filename), cat, prio, top, pause, dupekey, dupescore, dupemode, now]) + nzb_list.append([os.path.basename(out_filename), cat, prio, top, pause, dupekey, dupescore, dupemode, now]) else: - nzb_list = [[os.path.basename( - out_filename), cat, prio, top, pause, dupekey, dupescore, dupemode, now]] + nzb_list = [[os.path.basename(out_filename), cat, prio, top, pause, dupekey, dupescore, dupemode, now]] save_nzb_list() gzf.close() @@ -288,15 +260,13 @@ elif ext == '.rar': rarf = rarfile.RarFile(filename, mode='r') rf = get_files(rarf) if rf: - rarf.extractall(path=dir, members=rf) + rarf.extractall(path = dir, members = rf) now = datetime.datetime.now() for r in rf: if nzb_list: - nzb_list.append([r.filename, cat, prio, top, - pause, dupekey, dupescore, dupemode, now]) + nzb_list.append([r.filename, cat, prio, top, pause, dupekey, dupescore, dupemode, now]) else: - nzb_list = [[r.filename, cat, prio, top, - pause, dupekey, dupescore, dupemode, now]] + nzb_list = [[r.filename, cat, prio, top, pause, dupekey, dupescore, dupemode, now]] save_nzb_list() rarf.close()