[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

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

Post by synci »

Hey guys,

atm i get much content (mostly tv series) that contains a file named "sffdgdfdhhj45657rtghdg" without extension like *.mkv.
But there is also a rename.sh file inside, can anybody help to to post processing that ?
When i run that rename.sh file everything runs fine and the file gets renamed correctly, but i would prefer the auto mode :)

One way could be to simply rename the biggest file as same as the nzb name is, but as i said already there is no extension given to that file.

There is a *nzbget* offical script available that can handle exactly this, it doesnt run that rename.sh file, it reads and uses the name inside that rename.sh file.
I dont know if its allowed to link here ?

Sorry for my english :(

Thanks !
Last edited by synci on February 12th, 2015, 6:35 am, edited 1 time in total.
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

Can you post a link to such a .NZB?
Can you post a link to that nzbget script?
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

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

Post by synci »

Hey sander,

thanks for reply.

Here is the script:
https://github.com/clinton-hall/GetScri ... eRename.py

Here the topic for it:
http://nzbget.net/forum/viewtopic.php?f=8&t=1624

NZB maybe by pm ?
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

Yes, NZB via PM.
Can you post the line from such rename.sh containing the "mv" command? Preferrably a small download.

I had a look at the github code, and this is the core part:

Code: Select all

    if rename_file: 
        rename_lines = [line.strip() for line in open(rename_file)]
        for line in rename_lines:
            cmd = filter(None, re.split('(?:mv|Move)\s+(\S+)\s+(\S+)',line))
            if len(cmd) == 2 and os.path.isfile(os.path.join(dirname, cmd[0])):
                orig = os.path.join(dirname, cmd[0])
                dest = os.path.join(dirname, cmd[1].split('\\')[-1].split('/')[-1])
                if os.path.isfile(dest):
                    continue
                print "[INFO] Renaming file %s to %s" % (orig, dest)
                try:
                    os.rename(orig, dest)
                except Exception,e:
                    print "[ERROR] Unable to rename file due to: %s" % (str(e))
                    sys.exit(NZBGET_POSTPROCESS_ERROR)
So: find the line with "mv" (linux/OSX) or "Move" (windows). In there, get orig and dest filename (some magic handling on dest name), and do the rename.
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

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

Post by synci »

NZB (1,4GB dl) sent via PM.

Thanks !!!

Here the rename.sh:

Code: Select all

#!/bin/bash
mkdir Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON
mv    27.06.2014.1 Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/breaking.bad.s05e09.german.dl.720p.bluray.x264-intention.nfo
mv    27.06.2014.2 Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/breaking.bad.s05e09.german.dl.720p.bluray.x264-intention.mkv
mv    27.06.2014.3   Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs
mv    Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/27.06.2014.4  Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/breaking.bad.s05e09.german.dl.1080p.bluray.x264-intention.idx
mv    Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/27.06.2014.5  Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/breaking.bad.s05e09.german.dl.1080p.bluray.x264-intention.subs.sfv
mv    Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/27.06.2014.6  Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/breaking.bad.s05e09.german.dl.1080p.bluray.x264-intention.sub
mv    Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/27.06.2014.7  Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/breaking.bad.s05e09.german.dl.1080p.bluray.x264-intention-eng.idx
mv    Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/27.06.2014.8  Breaking.Bad.S05E09.German.DL.720p.BluRay.READ.NFO.x264-iNTENTiON/Subs/breaking.bad.s05e09.german.dl.1080p.bluray.x264-intention-eng.sub
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

Does one rename.sh file contain just one, or more mv commands?
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

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

Post by synci »

I forgot to give that information at the beginning.
Yes, its not only the main video file with that crypted name without extension, all files like .nfo, .sub ... have names like that.
And yes, the rename.sh contains all needed mv commands, for each file, like i posted before.
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

OK, so a rename.sh contains a complete list of mv-commands. That's clear.

The NZB you PMed is not downloadable for me, so I'll wait for you to send me a downloadable one.

PS: I wonder why this renaming is done. One thing comes to mind: circumventing early rar scanning ... which is what SABnzbd's feature Unwanted Extensions does ... hmmmm :-\
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

I found more of those downloads: http://nzbindex.com/search/?poster=usen ... %3E&more=1

The MUST_READ.txt says:
Auf win_click2rename.bat klicken und die Filename werden richtig zurückbennant.
lINUX ...
Linux_2Rename.sh doppelklicken und dann ... im Terminal ausführen wählen
Falls das nicht klappt muss Linux_2Rename.sh vorher nochmal ausführbar gemacht werden.
Dazu mit rechts die Eigenschaften aufrufen und im Reiter Zugriffsrechte das Häckchen bei
Als Programm ausführen anklicken.
Dann wie oben ... Doppelklich und .. im Termial ausführen

Viel Spass
Wow ... running an executable that you just downloaded ... :o
... if you dare that, you could write a post-processing script that just finds the *.sh resp *.bat and executes it .... ;D

I really understand why the nzbget script filters the mv commands from the script and executes it own. ;)

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

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

Post by synci »

Okay, so as i understand you are just before completing the script ? :)
Im not able to script something like that, donation is okay ?

You dont need any nzb now ?
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

I have it working. Solved two bugs in the original script.

Here it is:
https://raw.githubusercontent.com/sande ... eRename.py
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

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

Post by synci »

Wow thank you so much !!! (Will send you a PM too regarding don)

Just one question, your scripts works great but only when i run it via SSH (/usr/bin/env python SafeRename.py Release)
Its a problem on my OMV machine for sure, but i think its a simple problem you can solve within seconds.

SAB says "Exit(127) /usr/bin/env: python : No such file or directory"
I already tried to edit the python part in your scripts line 1, but as i said it works via SSH.
So "/usr/bin/env python" is possible and works.

Any ideas ?

Thanks !!!
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

What is the output of the following commands on your Linux system:

Code: Select all

which python
which env
/usr/bin/env python --version
synci
Newbie
Newbie
Posts: 29
Joined: February 10th, 2015, 2:19 pm

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

Post by synci »

Code: Select all

root@omv:~# which python
/usr/bin/python
root@omv:~# which env
/usr/bin/env
root@omv:~# /usr/bin/env python --version
Python 2.7.3
User avatar
sander
Release Testers
Release Testers
Posts: 8811
Joined: January 22nd, 2008, 2:22 pm

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

Post by sander »

Strange.
Post the output of

Code: Select all

ls -al <rename-script>
Example:

Code: Select all

$ ls -al SAB-SafeRename.py
-rwxrwxr-x 1 sander sander 1858 feb 11 14:37 SAB-SafeRename.py
Check first line:

Code: Select all

$ head -1 SAB-SafeRename.py
#!/usr/bin/env python

What if you replace the first line with

Code: Select all

#!/usr/bin/python
Post Reply