[SOLVED][LINUX] Parse/run rename.sh inside archive ?

Come up with a useful post-processing script? Share it here!
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [LINUX] Run rename.sh inside archive ?

Post by synci » February 11th, 2015, 10:11 am

Code: Select all

$ ls -al SafeRename.py
-rwxrwxrwx 1 sabnzbd users 1910 Feb 11 15:51 SafeRename.py
$ head -1 SafeRename.py
#!/usr/bin/env python
When i replace the first line with #!/usr/bin/python sab says:
Cannot run script /home/sabnzbd/.sabnzbd/scripts/SafeRename.py

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [LINUX] Run rename.sh inside archive ?

Post by sander » February 11th, 2015, 10:23 am

synci wrote:

Code: Select all

$ ls -al SafeRename.py
-rwxrwxrwx 1 sabnzbd users 1910 Feb 11 15:51 SafeRename.py
$ head -1 SafeRename.py
#!/usr/bin/env python
Size 1910 bytes? On my system and github 1858 bytes. Not good on your system.

Can you do this:

Code: Select all

cd /home/sabnzbd/.sabnzbd/scripts/
wget https://raw.githubusercontent.com/sanderjo/SAB-SafeRename/master/SAB-SafeRename.py
chmod +x SAB-SafeRename.py
ls -al SAB-SafeRename.py
./SAB-SafeRename.py BlaBla
Post result here.

synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [LINUX] Run rename.sh inside archive ?

Post by synci » February 11th, 2015, 10:40 am

WTF it runs now ?!?
Ive copied the script 1:1, 4 times ..., never thought what can be wrong with this method.

Thank you so much sander !!!

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [LINUX] Run rename.sh inside archive ?

Post by sander » February 11th, 2015, 10:53 am

Good. Looking forward to your PM.

synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by synci » February 20th, 2015, 4:45 am

Hey sander,

im afraid but the script needs little modification :(
Now they pack(rar) our rename.sh/.bat file but gives us a new .sh file for that process.

a_Linux_2rename.sh:

Code: Select all

unrar x -p923613061 What.rar 
./What.sh
Inside that What.rar archive is our real rename.sh file.
NZB example sent via PM.

Any ideas ?

Thanks !!!

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by sander » February 20th, 2015, 6:16 am

synci wrote: Any ideas ?
My ideas:

- What a mess! An executable creating a new executalbe, which you have to execute. Brrr
- What is the goal of the poster of suchs posts? I can only think of this: create a downloader's habit of randomly clicking on executables he/she downloaded (the last thing you should do), in order to create a path for introducing viruses, worms and other malware
- solving this in a program / SAB-pp-script is a rat race; the poster will always find new things you then have to solve in your program
- maybe running SABnzbd + pp-script in a sandbox (like a docker container) and then deleting the sandbox would be solution. Not an easy thing
- running the SAB-pp-script in a sandbox

And what are your ideas?

synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by synci » February 20th, 2015, 6:39 am

Dont know why they are doing this ...
Already mailed Clinton Hall for this and added an issue on github, he will look over this.

I thought its simple to just execute the new sh file if it contains a unpacking command.
Then do the same like before, parse the rename.sh file and rename the files :)

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by sander » February 20th, 2015, 6:59 am

synci wrote:Dont know why they are doing this ...
Already mailed Clinton Hall for this and added an issue on github, he will look over this.
Clinton Hall has integrated my three fixes back into his script, so that it is now both NZBget and SABnzbd compatible.

synci wrote: I thought its simple to just execute the new sh file if it contains a unpacking command.
Then do the same like before, parse the rename.sh file and rename the files :)
OK, but do you realize that is part of the rat race? Having said that: what do you suggest as pseudo-code? My shot:

Code: Select all

find .sh -script, and parse it:
    mark this script as handled
    if line is a rename, find the parameters and do a safe python rename with those parameters
    if line is an unrar command, find the parameters, do a safe pyhton called unrar
if a new .sh-script is there, and parse it

synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by synci » February 20th, 2015, 7:06 am

Your shot sounds great :)
I know that it is a rat race but i think that they dont change it now for a while.

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by sander » February 21st, 2015, 8:01 am

I see Clinton Hall has changed his code to support your request?

I have a completely different idea: just ignore all .sh/.bat scripts, and just give the extension based on the info that is given by the "file" command:

Code: Select all

$ file 19.02.2015.2
19.02.2015.2: Matroska data
"Matroska" so just add the extension ".mkv" at the end.

Code: Select all

$ file 20.02.2015.50
20.02.2015.50: JPEG image data, JFIF standard 1.02
JPEG, so just add ".jpg" at the end

The file name would stay the same.

Would that work for you?

EDIT: there's a python module for the 'file' command:

Code: Select all

$ sudo pip install python-magic

$ python
>>> import magic
>>> magic.from_file("19.02.2015.2")
'Matroska data'
>>> magic.from_file("19.02.2015.2", mime=True)
'video/x-matroska'


>>> import mimetypes
>>> mimetypes.guess_extension('video/x-matroska', strict=True)
'.mpv'
>>> mimetypes.guess_all_extensions('video/x-matroska', strict=True)
['.mpv', '.mkv']



synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by synci » February 21st, 2015, 10:43 am

Yes Clinton Hall is on it, i think few short changes needed then it should work.

Your idea sounds really great because no changes in the script needed when the board will start another rat race.
But tbh, at the moment i prefer the other method with correct namings when possible.

For example, when SickRage downloads many episodes of different series, i have to change every episode name manual.
the episode dir namings are also crypted so i have to look into each nfo file for the correct episode/series name.

User avatar
sander
Release Testers
Release Testers
Posts: 6046
Joined: January 22nd, 2008, 2:22 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by sander » February 22nd, 2015, 5:44 am

And there is nothing in the job name, NZB name or directory name that reveals the name of the download? Because if so, it could be safely used to also rename the file.

jkoopmann
Newbie
Newbie
Posts: 2
Joined: April 19th, 2015, 10:52 am

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by jkoopmann » September 11th, 2016, 11:25 am

Just hit the same issue. However the latest nzbToCouchpotatoe scripts do not seem to cover it. The latest SafeRename.py I found also did not look as if this was covered (looking for What.sh but not for a_Linux_2rename.sh like files). Have you guys ever solved this? Pretty annoying...

synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

Re: [SOLVED][LINUX] Parse/run rename.sh inside archive ?

Post by synci » November 21st, 2016, 1:30 pm

This version works for me, just tested with brand new nzb and "a_Linux_2rename.sh" inside.
https://github.com/clinton-hall/GetScri ... eRename.py

Its also needed to disable recursive unpacking in Sabnzbd settings (https://sabnzbd.org/wiki/configuration/ ... tches#toc3)
Because Sabnzbd trys to unrar What.rar for a very long time when you use a passwordfile.

Post Reply