clinton-hall / GetScripts

A Collection of NZBGet Post-Process Scripts
GNU General Public License v2.0
100 stars 39 forks source link

SafeRename.py #14

Closed w00druff closed 8 years ago

w00druff commented 8 years ago

Hey Clinton,

can you please check the nzb i just mailed you when you get some time ? Maybe its my fault but it would be nice if you can just try this nzb on your side. Thanks a lot !

I thought it already worked with this one but after many minutes ill get this output:

Traceback (most recent call last): File "/var/opt/sabnzbd/scripts/SafeRename.py", line 211, in <module> rename_script(dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 112, in rename_script cmd = extract_command(shlex.split(line), dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 162, in extract_command if platform.system() == 'Windows': NameError: global name 'platform' is not defined

clinton-hall commented 8 years ago

Please update to latest version and try again.

w00druff commented 8 years ago

Will try, thanks !

w00druff commented 8 years ago

Script triggered from SABnzbd Traceback (most recent call last): File "/var/opt/sabnzbd/scripts/SafeRename.py", line 212, in <module> rename_script(dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 113, in rename_script cmd = extract_command(shlex.split(line), dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 203, in extract_command if not os.path.exist(cmd[-1]): AttributeError: 'module' object has no attribute 'exist'

clinton-hall commented 8 years ago

Please update and try again... Sorry about this.

w00druff commented 8 years ago

Well i also found that typo (what a skill... xD) but got new error then:

Script triggered from SABnzbd Traceback (most recent call last): File "/var/opt/sabnzbd/scripts/SafeRename.py", line 212, in <module> rename_script(dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 113, in rename_script cmd = extract_command(shlex.split(line), dirname) File "/var/opt/sabnzbd/scripts/SafeRename.py", line 207, in extract_command newcmd = EXTRACT_COMMANDS[ext] KeyError: ''

The version before you added that Windows part works fine for me.

clinton-hall commented 8 years ago

can you show the contents of the rename file? it looks like the unrar command is in a different format to expected.

w00druff commented 8 years ago

unrar x -p57534278 What.rar . ./What.sh

This one worked with https://github.com/clinton-hall/GetScripts/blob/062a8c464af4917bb079981df22763827b4cc2bb/SafeRename.py

clinton-hall commented 8 years ago

strange... when I try this manually, the commands work. I'll need to try the actual file, but the url you sent doesn't work for me. Any chance you can email me the nzb file?

w00druff commented 8 years ago

Really strange, just mailed you the sample nzb.

clinton-hall commented 8 years ago

didn't come through... can you zip it and send again?

w00druff commented 8 years ago

Oh looks like it never sent, should be now.

clinton-hall commented 8 years ago

Ok, I tested this out... it should be fixed now. Please update to latest.

w00druff commented 8 years ago

Works great now, thanks a lot bro ! Do you see any possibility to rename the created nzb root dir (crypted nzb name now) with the mkdir dirname command used in the What.sh/Click.bat file ?

Because then it should be possible to catch this download with CP/SR. I think SR/CP just looks for nzb dir name and not folder inside which would be correct in this case.

clinton-hall commented 8 years ago

Sorry for the delay. This could be possible... can you give the folder structure for one of these once extracted? I'll need to make sure the original (seeding) directory isn't renamed, and only the output....

w00druff commented 8 years ago

No problem ! I have enabled "Ignore any folders inside archives" in SABnzbd so there is just one dir created and named "7f247f70_51c43ea1_57af80c7_0168da8-u4e" for example. Inside it there will be created the releasename dir after executing What.sh.

You can try with last example nzb i sent you last time.

Thanks !!!

clinton-hall commented 8 years ago

Can you test the latest?

w00druff commented 8 years ago

Thanks for this but the nzb dir got renamed to the NFO filename now. Would be great to rename it to the mkdir command in What.sh.

clinton-hall commented 8 years ago

Ok... uses mkdir command first, then reverts to base directory from move command (but if same base directory as input, it then renames to the file name less the extension).

Hopefully this covers all likely scenarios?

w00druff commented 8 years ago

Works very well !!! Thanks a lot bro !

clinton-hall commented 8 years ago

Wohoo...

And I added the CHMOD + cleanup that you requested way back when.... I am actually thinking this script has been pretty much custom written for your downloads ;)...

Ok, 9 unique clones in the last month... there may be a few other users too.

w00druff commented 8 years ago

Already recognized but still testing it. (I have to uncomment line 17+22?) Yeah i know that thanks a lot, spent you 2 or 3 beers just now :-)

clinton-hall commented 8 years ago

Thanks for the beers. No, don't uncomment lines. They are for NZBGet settings. I'll need to push a fix for SABnzbd.

w00druff commented 8 years ago

Ahhh okay im waiting, no problem. Just wondered why its not working because you never had to fix something within this script :-)

clinton-hall commented 7 years ago

Yeah... all of these scripts were written for NZBGet. I added SABnzbd functionality to SafeRename only (presumably on request... by you??).

Anyway, I had forgotten that you actually call this from SABnzbd, so when I added this I by-passed SABnzbd.

What I have done is set this up to CHMOD 0775 by default. I have also set this up to delete .sh and .bat by default.

If you want to add/change, you need to change these on lines 103/104 https://github.com/clinton-hall/GetScripts/blob/b0bf2a9f552b8b09937e6c3717f4882494d1d0ec/SafeRename.py#L103-L104

Change from

    CHMOD = int("0775", 8)
    CLEANUP = [".sh", ".bat"]

to

    CHMOD = int("0777", 8)
    CLEANUP = [".sh", ".bat", ".rar", ".zip"]

etc.

I think this will probably mean for future updates you will need to git reset -- hard before doing git pull. And then you will need to edit these after updating... So make a config file I need to add a bit more, and unless I make all scripts SABnzbd compatible, this seems rather un-necessary? Keep in mind, SABnzbd can only launch 1 script, whereas NZBGet can process multiple scripts in a defined order...