Page 2 of 2
Re: Help with a script function
Posted: July 6th, 2013, 10:34 am
by FatalOne
Yes, that makes perfect sense. Question though... why "print" the various info, doesn't that just display it on the console screen? Just trying to understand whats going on is all...
Thank you again!
Re: Help with a script function
Posted: July 6th, 2013, 10:36 am
by sander
FatalOne wrote:Yes, that makes perfect sense. Question though... why "print" the various info, doesn't that just display it on the console screen? Just trying to understand whats going on is all...
Thank you again!
To be sure: does that actually work on your system? Only then we should proceed.
The print statements are just there for clarity ... you can run a pp script also from the command line. And the print output appears in the SABnzbd popup:
/home/sander/Downloads/SABdownloads/bigrandomfile (1).1
bigrandomfile (1)
/home/sander/MyDownloads/bigrandomfile (1)
Re: Help with a script function
Posted: July 6th, 2013, 10:53 am
by FatalOne
Kk, had to step out for about an hour, will test this when I get back.
Re: Help with a script function
Posted: July 6th, 2013, 2:27 pm
by FatalOne
Sanders,
I had a chance to test this, and was not successful. I keep getting a syntax error, here is what the script log says:
File "C:\Program Files (x86)\SickBeard\autoProcessTV\Move-it.py", line 8
destinationdirectory = 'E:\ServerFolders\Videos\Movies\' + jobname
^
SyntaxError: EOL while scanning string literal
And here is the code after I added my path:
Code: Select all
import sys, shutil
sourcedirectory = sys.argv[1] ### The final directory of the job (full path)
jobname = sys.argv[3]
print sourcedirectory
print jobname
destinationdirectory = 'E:\ServerFolders\Videos\Movies\' + jobname
print destinationdirectory
shutil.move(sourcedirectory, destinationdirectory)
exit(0)
The formatting is different here, but the line "destinationdirectory = 'E:\ServerFolders\Videos\Movies\' + jobname" gets word wrapped on to the next line, so the "jobname" portion is on the next line down. Does this make any difference?
Also, I believe using the name parameter passed from SABnzbd to name the folder in the destination directory wont be in the format that I have SABnzb renaming it to. I believe the format would end up as the original folder "The Movie 2013 DVDRIP XVID GROUP" instead of "The Movie (2013)".
*EDIT* Disregard all that, I got it to work, did a lil reading and came up with 'E:\\ServerFolders\\Videos\\Movies\\' + jobname and that seem to do the trick. But what I said about using the name parameter passed form SABnzbd makes the folder be named in the incorrect format is correct.
Re: Help with a script function
Posted: July 6th, 2013, 9:05 pm
by FatalOne
Sanders,
After a couple hours of research, modifications, and trial and error, I've finally got a pp script that does what I want.
This script will take a movie folder that was renamed by SABnzbd, from the movies category completed folder, identify the first letter of the movie title, ignoring "the", and move the movie folder to the destination directory that has an alphabetical structure.
So for the movie download "The.Movie.2011.DVDRIP.XVID.GROUP"
After SABnzbd Renames it
the script will move it to the destination directory:
E:\ServerFolders\Videos\Movies\M\The Movie (2011)
If the movie title starts with a non letter, it will put it:
E:\ServerFolders\Videos\Movies\#\.....
There is probably a cleaner way to do a couple of the things I did, if anything pops out at ya that should be changed or done a different way...please say so.
And again, Thank You for all your help!
Code: Select all
import sys, shutil, os
sourcedirectory = sys.argv[1] ### The final directory of the job (full path)
splitchar = os.sep
print sourcedirectory
print "\n",sourcedirectory
last = sourcedirectory.split(splitchar)[-1]
if last == '':
last = sourcedirectory.split(splitchar)[-2]
print last
lastfolder = last
last = last.upper()
print last
last = last.replace("THE ","")
print last
firstchar = last[0]
print firstchar
if firstchar >= 'A' and firstchar <= 'Z' :
print "Yes"
else:
firstchar = '#'
destinationdirectory = 'E:\\ServerFolders\\Videos\\Movies\\' + firstchar + '\\' + lastfolder
print destinationdirectory
shutil.move(sourcedirectory, destinationdirectory)
exit(0)
Re: Help with a script function
Posted: July 7th, 2013, 1:42 am
by sander
Cool!
Was this your first python programming?
Re: Help with a script function
Posted: July 7th, 2013, 8:10 am
by FatalOne
Yes, it is my first python script

Re: Help with a script function
Posted: July 7th, 2013, 11:48 am
by sander
I found out something: os.sep containts the directory separator symbol, so '/' (on Linux/Unix) versus '\' (on Windows/DOS).
So
can be changed into
to make the script more portable.
Code: Select all
sander@hapee:~$ python
Python 2.7.5+ (default, Jun 5 2013, 10:40:07)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.sep
/
>>>
sander@hapee:~$
So maybe you can change that in your script, and then test?
Re: Help with a script function
Posted: July 7th, 2013, 3:59 pm
by FatalOne
Made the change in the script on my machine, and it seemed to work just fine. Nice one!
On another note, was thinking of starting a new thread here soon, since we have a working script, that way we can title it in a manner that will be a little more obvious of what it does. Is there specific forum rules relating to this?