Unrar .rar files in .rar archives

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
EndoMorph
Posts: 5
Joined: 16 May 2015, 22:38

Re: Unrar .rar files in .rar archives

Post by EndoMorph » 16 May 2015, 22:47

Hello guys

i've got some errors with this script if the path or file contains spaces.
So here a short workaround for this problem (maybe i can help someone with the same problem!)

You must edit line 149 and 153 (line 149 is optional):

line 149:
replace the old

Code: Select all

print UnrarPath+" e -o- "+dirpath+"/"+file+" "+os.environ['NZBPP_DIRECTORY']
with this

Code: Select all

print UnrarPath+" e -o- '"+dirpath+"/"+file+"' '"+os.environ['NZBPP_DIRECTORY']+"'"
line 153:
replace the old

Code: Select all

retcode = subprocess.call(UnrarPath+" e -o- "+dirpath+"/"+file+" "+os.environ['NZBPP_DIRECTORY'], shell=True)
with this

Code: Select all

retcode = subprocess.call(UnrarPath+" e -o- '"+dirpath+"/"+file+"' '"+os.environ['NZBPP_DIRECTORY']+"'", shell=True)
Cheers

EndoMorph

starpc
Posts: 5
Joined: 03 Sep 2015, 20:29

Re: Unrar .rar files in .rar archives

Post by starpc » 04 Sep 2015, 02:07

Is there a newer version of the ExtendUnrar script available?

starpc
Posts: 5
Joined: 03 Sep 2015, 20:29

Re: Unrar .rar files in .rar archives

Post by starpc » 16 Sep 2015, 05:54

The script keeps failing for me :(

Code: Select all

ERROR	Tue Sep 15 2015 17:42:43	Post-process-script ExtendedUnrar.py for Random.2014.LIMITED.720p.BluRay.x264-DRONES failed (terminated with unknown status)
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: ValueError: could not convert string to float:
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: time.sleep(float(waittime))
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: File "C:\ProgramData\NZBGet\scripts\ExtendedUnrar.py", line 129, in <module>
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: Traceback (most recent call last):
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: Waiting seconds to give NZBGet time to delete old rar files
INFO	Tue Sep 15 2015 17:42:43	ExtendedUnrar: All preliminary checks successfully performed...

thorli
Posts: 5
Joined: 02 Jan 2015, 15:00

Re: Unrar .rar files in .rar archives

Post by thorli » 17 Oct 2015, 17:53

It seems that the timeout value is not correct, it must be a floting point value something like "5.0" then it should work.

You can configure it in the Web-Interface under Settings > ExtendedUnrar > WaitTime (see attached screenshot)

I have done this script quickly in the past so i have not implemented a thorough input value validation or type casting, sorry for that ;)
Attachments
ext-unrar-settings.jpg
Settings

kjKmcQN3
Posts: 64
Joined: 29 Aug 2015, 15:09

Re: Unrar .rar files in .rar archives

Post by kjKmcQN3 » 04 Dec 2017, 11:17

I stumbled upon this script while searching for a way to process .sub files that are double packed (.rar within a .rar).

Here is a typical scenario for double rared subtitle releases. The file Example.nzb contains the following files.
Example.rar
Example.r00
Example.r01
Example.r02
Example.r03
Example.subs.rar
Example.par2


The file Example.subs.rar, when unpacked, creates a folder Example.subs, which in turn has the files Example.idx and Example.rar. The Example.rar file has to be further unpacked to get the Example.sub file.

Here are my experiences with this script so far and the issues I faced.
  • The script doesn't always work. In a few instances it was able to output the .sub file but not always.
  • Every time I have run the script it has reported a failure (ExtendedUnrar: Unpack Failed with Returncode 10)
Given that it's been a while since this script was updated I would wondering if these issues are a result of it not being current with the latest developments on the NZBGet side of things.

@hugbug - Would it be possible to bake this functionality into NZBGet itself so that one doesn't have to rely on an external script? An elegant solution that takes care of double-rared files would be great! Thanks.

JonM
Posts: 3
Joined: 25 Apr 2018, 09:46

Re: Unrar .rar files in .rar archives

Post by JonM » 25 Apr 2018, 09:53

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

hugbug
Developer & Admin
Posts: 6969
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: Unrar .rar files in .rar archives

Post by hugbug » 25 Apr 2018, 10:08

You probably saved the file with Windows line endings.

JonM
Posts: 3
Joined: 25 Apr 2018, 09:46

Re: Unrar .rar files in .rar archives

Post by JonM » 25 Apr 2018, 11:28

I had indeed... How silly. editing with notepad++ seems to have fixed it. Doh.

But, I have a new issue...

Files that don't have any nested rar files are now all failing with;
ExtendedUnrar: Unpack failed, setting status "failed"

files which have the nested rars are working exactly as they should. Is there a way to stop it reporting failed on these files? Technically I have the files downloaded ok but it's breaking my automation with the "failed" status.

Thanks for the help,
Jon

JonM
Posts: 3
Joined: 25 Apr 2018, 09:46

Re: Unrar .rar files in .rar archives

Post by JonM » 25 Apr 2018, 11:44

I fixed it...

I replaced

Code: Select all

    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
 
With...

Code: Select all

    if os.environ['NZBPP_TOTALSTATUS'] != 'SUCCESS':
        print "Download Failed, setting status \"failed\""
        status = 1
NZBPP_UNPACKSTATUS is depreciated although it should still work, but I think if an unpack hasn't been done then the return code will be something other than 2.

NZBPP_TOTALSTATUS should catch everything.

Cheers,
Jon

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests