I'm having a real hard time getting this script to work in a freenas jail.
I think its the shebang line causing issues.
If I use;
#!/usr/bin/env python
I get "ExtendedUnrar: env: python : No such file or directory"
That command works fine in the console though!
So I've tried;
#!/usr/bin/local/python (the location I get with whereis python)
Which gives me;
"ExtendedUnrar: Could not start /media/Downloads/scripts/ExtendedUnrar.py: No such file or directory"
I've been tearing my hair out on this one... anyone else seen this issue? my full script is;
Code: Select all
#!/usr/bin/local/python
#
# ExtendedUnrar post-processing script for NZBGet
#
# Copyright (C) 2014 thorli <thor78@gmx.at>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Version 1.0 (2014-06-01)
#
#
##############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
# Unrar double packed files
#
# This script unpacks downloads which are packed twice.
#
# NOTE: This script requires Python to be installed on your system.
##############################################################################
### OPTIONS ###
# Path to Unrar binary - if empty default path to Unrar from NZBGet config is used
#UnrarPath=/usr/local/bin/unrar
# File extension of rar files to search for NOTE: only one entry for the extension mask is currently supported. Possible to use "*" and "?" as wildcard.
#RarExtensions=.r??
# Time in seconds to suspend start of script to give NZBGet time to perform "UnpackCleanupDisk" action on slow systems
#WaitTime=5.0
### NZBGET POST-PROCESSING SCRIPT ###
##############################################################################
import glob
import os
import sys
import subprocess
import time
# NZBGet V11+
# Check if the script is called from nzbget 11.0 or later
if os.environ.has_key('NZBOP_SCRIPTDIR') and not os.environ['NZBOP_VERSION'][0:5] < '11.0':
print "Script triggered from NZBGet (11.0 or later).\o/"
# 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
# Check nzbget.conf options
required_options = ('NZBOP_UNRARCMD', 'NZBPO_UNRARPATH', 'NZBPO_RAREXTENSIONS', 'NZBPO_WAITTIME')
for optname in required_options:
if (not optname in os.environ):
print('[ERROR] Option %s is missing in configuration file. Please check script settings' % optname)
sys.exit(POSTPROCESS_ERROR)
rarext=os.environ['NZBPO_RAREXTENSIONS']
waittime=os.environ['NZBPO_WAITTIME']
UnrarPath=os.environ['NZBPO_UNRARPATH']
#print "os.envir.UnrarPath= ",UnrarPath
if UnrarPath == "":
#print "No path given for unrar, please set path in Settings\-\>Unrar"
#sys.exit(POSTPROCESS_ERROR)
print "No path given to unrar binary, using default Unrar path from NZBGet config file"
UnrarPath=os.environ['NZBOP_UNRARCMD']
print "UnrarPath ",UnrarPath
status = 0
unpack = 0
#files = []
if os.environ['NZBOP_UNPACK'] != 'yes':
print "Please enable option \"Unpack\" in nzbget configuration file, exiting"
sys.exit(POSTPROCESS_ERROR)
# Check par status
if os.environ['NZBPP_PARSTATUS'] == '3':
print "Par-check successful, but Par-repair disabled, exiting"
sys.exit(POSTPROCESS_NONE)
if os.environ['NZBPP_PARSTATUS'] == '1':
print "Par-check failed, setting status \"failed\""
status = 1
# Check unpack status
if os.environ['NZBPP_UNPACKSTATUS'] != '2':
print "Unpack failed, setting status \"failed\""
status = 1
if os.path.isfile(os.path.join(os.environ['NZBPP_DIRECTORY'], "_brokenlog.txt")) and not status == 1:
print "Post-Process: _brokenlog.txt exists, download is probably damaged, exiting"
sys.exit(POSTPROCESS_ERROR)
if not status == 1:
print "_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']):
print "Post-Process: Nothing to post-process: destination directory ", os.environ['NZBPP_DIRECTORY'], "doesn't exist"
sys.exit(POSTPROCESS_NONE)
# All checks done, now launching the script.
print "All preliminary checks successfully performed..."
#Traverse download files to check for not extracted rar files
print "Waiting "+waittime+" seconds to give NZBGet time to delete old rar files"
time.sleep(float(waittime))
print "Searching for rar files"
for dirpath, dirnames, filenames in os.walk(os.environ['NZBPP_DIRECTORY']):
#find all possible extensions for rar-files
#files = sorted(glob.glob(dirpath+"/*.r??"))
files = sorted(glob.glob(dirpath+"/"+rarext))
"""
if len(files) > 0:
for filematch in files:
print "found rar: "+filematch
"""
for file in filenames:
filePath = os.path.join(dirpath, file)
fileName, fileExtension = os.path.splitext(file)
#print filePath, fileName, fileExtension
if fileExtension in ['.rar']: # If the file is a rar file
print "Found rar-file, try to extract ", file
print UnrarPath+" e -o- '"+dirpath+"/"+file+"' '"+os.environ['NZBPP_DIRECTORY']+"'"
try:
print "extracting...", file
#os.system(UnrarPath+" t "+dirpath+"/"+file)
retcode = subprocess.call(UnrarPath+" e -o- '"+dirpath+"/"+file+"' '"+os.environ['NZBPP_DIRECTORY']+"'", shell=True)
#retcode = 0
if retcode == 0:
print "Unpack Successful"
unpack = 1
else:
print "Unpack Failed with Returncode", retcode
status = 1;
except OSError as e:
print "Error: Execution of Unrar-Command failed:", e
print "Error: Unable to unpack file", file
status = 1
#break
if unpack == 1:
print "Deleting rar files"
for rar in files:
try:
os.remove(rar)
except OSError as e:
print "Error: Delete failed:", e
print "Error: Unable to delete file", file
#print "status: ",status
if status == 0:
sys.exit(POSTPROCESS_SUCCESS)
else:
sys.exit(POSTPROCESS_ERROR)
else:
print "This script can only be called from NZBGet (11.0 or later)."
sys.exit(0)
Thanks,
Jon