[REQUEST] Google Drive upload help

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.
Post Reply
Dec64
Posts: 4
Joined: 18 Jan 2017, 22:19

[REQUEST] Google Drive upload help

Post by Dec64 » 18 Jan 2017, 22:25

I'm trying to make a google drive upload script, that I can run after other PP scripts, e.g CouchPotato or Sickbeard or any renaming/organising script, that then uploads the folder directory with the movie renamed to google drive.

As far as i understand it, all i need to do is run a small PP script after everything that gets the final directory name, and uses that to create the command to run on the system.

I have come up with this so far, but it does not work. I do not know any python so any help would be much appreciated.

I need to run the command "/home/declan/script/gdrive upload -p 0BwEBrlen3gVDWkFfeU5MZ19zN28 -r <directory here>"

and once that has completed, to delete that directory.

Code: Select all

import sys

if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]:
	print "[ERROR] This nzb-file was not processed correctly, terminating the script"
	sys.exit(95)
    
if [ "$NZBPP_TOTALSTATUS" = "SUCCESS" ]:
	myCommand = "/home/declan/script/gdrive upload -p 0BwEBrlen3gVDWkFfeU5MZ19zN28 -r "
	myCommand += NZBPP_DIRECTORY
	return_code = subprocess.call(myCommand, shell=True)
	shutil.rmtree(NZBPP_DIRECTORY)
	sys.exit(93)

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

Re: [REQUEST] Google Drive upload help

Post by hugbug » 19 Jan 2017, 07:41

That script looks like a mix of Python and Bash.

I've tried to convert it to proper Bash script but I haven't tested it meaning it still may contain syntax errors:

Code: Select all

#! /bin/sh

if [ "$NZBPP_TOTALSTATUS" != "SUCCESS" ]; then
    echo "[ERROR] This nzb-file was not processed correctly, terminating the script"
    exit 95
fi

if /home/declan/script/gdrive upload -p 0BwEBrlen3gVDWkFfeU5MZ19zN28 -r $NZBPP_DIRECTORY; then
    echo "[INFO] Uploaded successfully, deleting local files"
    rm -r $NZBPP_DIRECTORY
fi

exit 93
Care must be taken when running the script after any renaming or organizing script as the download directory (NZBPP_DIRECTORY) may not exist anymore or be empty if the renaming/organizing scripts move the files elsewhere.

Dec64
Posts: 4
Joined: 18 Jan 2017, 22:19

Re: [REQUEST] Google Drive upload help

Post by Dec64 » 19 Jan 2017, 08:18

Thank you very much for that, Yeah i did have issues with syntax but i thought i converted it all over to python but bash is fine.

This was just a test with NZBPP_DIRECTORY without any renaming to make sure the script works on it's own. Am i correct in thinking that it's NZBPP_FINALDIR instead?

I assume i can do some sort of check, if NZBPP_FINALDIR is empty or returns nothing, then use NZBPP_DIRECTORY as a failsafe?

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

Re: [REQUEST] Google Drive upload help

Post by hugbug » 19 Jan 2017, 08:55

The issue with NZBPP_FINALDIR is that not all scripts set it. And the other issue is that it may contain files not related to current job, for example if the renaming script puts all files (from all nzbs) into one directory. That may be not a problem in your case but you should be aware of that.
Dec64 wrote:if NZBPP_FINALDIR is empty or returns nothing, then use NZBPP_DIRECTORY as a failsafe?
Looks good.

Dec64
Posts: 4
Joined: 18 Jan 2017, 22:19

Re: [REQUEST] Google Drive upload help

Post by Dec64 » 19 Jan 2017, 09:12

Ok well that worked, so i'm very close to the setup I was aiming, thanks a lot.

One last issue i think, the log shows success for the script but outputs

Code: Select all

drive: 512.0 B/2.0 GB 33.6 MB/2.0 GB 75.5 MB/2.0 GB 117.4 MB/2.0 GB, Rate: 34.7 MB/s 159.4 MB/2.0 GB, Rate: 34.7 MB/s 201.3 MB/2.0 GB, Rate: 34.7 MB/s 243.3 MB/2.0 GB, Rate: 36.5 MB/s 285.2 MB/2.0 GB, Rate: 36.5 MB/s 327.2 MB/2.0 GB, Rate: 36.5 MB/s 360.7 MB/2.0 GB, Rate: 36.0 MB/s 402.7 MB/2.0 GB, Rate: 36.0 MB/s 444.6 MB/2.0 GB, Rate: 35.0 MB/s
So it's outputting the constant upload from the command, is it possible to stop this, and make sure the post process waits to declare success? Just so I can pause the que untill upload is done and then go again?

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

Re: [REQUEST] Google Drive upload help

Post by hugbug » 19 Jan 2017, 09:22

Post-process always waits for script to end.
It's just that the program you execute prints a lot of text into output during it's job. You can check if the program has parameters to adjust that behavior. Or you can redirect it's output into "/dev/null" to suppress all output. The possible errors are usually printed into error output and therefore should be visible nonetheless:

Code: Select all

if /home/declan/script/gdrive upload -p 0BwEBrlen3gVDWkFfeU5MZ19zN28 -r $NZBPP_DIRECTORY > /dev/null; then
The other possibility would be to parse the output of the program (your script would do that) and print to nzbget only important messages. That's more difficult however.

Dec64
Posts: 4
Joined: 18 Jan 2017, 22:19

Re: [REQUEST] Google Drive upload help

Post by Dec64 » 19 Jan 2017, 13:20

Thanks again for the help.

Works perfectly for movies. I'm trying to adapt it for TV now but i'm unsure if it's possible.

the command would be gdrive upload -p 0BwEBrlen3gVDUkNwVW03aUNNX0k -r

The -p 0BwEBrlen3gVDUkNwVW03aUNNX0k is refercning to the folder on gdrive, so 0BwEBrlen3gVDUkNwVW03aUNNX0k is TV. Now in that folder is then a folder for each show. If i kept the script as is, it would upload the individual episode to the root of TV and not into the shows folder?

I need to edit the $NZBPP_DIRECTORY i guess? Is it possible to take a step back from $NZBPP_DIRECTORY? Is there a simple way to do this that anyone can think of

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

Re: [REQUEST] Google Drive upload help

Post by hugbug » 19 Jan 2017, 16:01

Your script can create local subfolders as necessary, move video files there and then upload the folders.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests