Skip to content

Commit

Permalink
pushed some lingering updates from pynzbget
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Nov 23, 2016
1 parent ba6126c commit 8e45fdf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 43 deletions.
28 changes: 24 additions & 4 deletions DirWatch/nzbget/ScriptBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
information) was found, then an empty dictionary is returned
instead.
* is_unique_instance() - Allows you to ensure your instance of your script is
unique. This is useful for Scheduled scripts which can be
called and then run concurrently with NZBGet.
Ideally, you'll write your script using this class as your base wrapper
requiring you to only define a main() function and call run().
You no longer need to manage the different return codes NZBGet uses,
Expand Down Expand Up @@ -147,6 +151,7 @@
from logging import Logger
from datetime import datetime
from Utils import tidy_path
from urllib import unquote

from Logger import VERBOSE_DEBUG
from Logger import VERY_VERBOSE_DEBUG
Expand Down Expand Up @@ -1018,9 +1023,6 @@ def _pid_running(pid):
except (ValueError, TypeError), e:
# Bad data
if verbose:
self.logger.debug(
'PID-File - Access Exception %s' % str(e))

self.logger.info(
'Removed (dead) PID-File: %s' % self.pidfile)
try:
Expand Down Expand Up @@ -1422,7 +1424,7 @@ def parse_nzbfile(self, nzbfile, check_queued=False):

return results

def parse_url(self, url, default_schema='http'):
def parse_url(self, url, default_schema='http', qsd_auth=True):
"""A function that greatly simplifies the parsing of a url
specified by the end user.
Expand Down Expand Up @@ -1558,6 +1560,24 @@ def parse_url(self, url, default_schema='http'):
# and it's already assigned
pass

if qsd_auth:
# Allow people to place a user= inline in the query string
if result['user'] is None:
try:
if 'user' in result['qsd'] and len(result['qsd']['user']):
result['user'] = unquote(result['qsd']['user'])

except AttributeError:
pass

if result['password'] is None:
try:
if 'pass' in result['qsd'] and len(result['qsd']['pass']):
result['password'] = unquote(result['qsd']['pass'])

except AttributeError:
pass

try:
(result['host'], result['port']) = \
re.split('[\s:]+', result['host'])[:2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ Description
=================
This provides a python framework to design NZBGet scripts with. The intent
was to greatly simplify the development and debugging process. It was
initially designed to work with NZBGet v13 but was made to be compatible
with versions 12 and 11 as well.
initially designed to work with NZBGet v13, but was made to be compatible
with versions 12 and 11 as well. Naturally it works with all newer versions as well (v14, v15, v16, etc).

* It contains a built in meta tag parser to extract content from NZB-Files.
_Note: This can only happen if lxml is installed on your system_.
* It can preform very basic obfuscation support on filenames that can not be
interpreted.
* It creates a common SQLite database (optionally) to additionally write
content passed via the set() function. This allows another script to later
content passed via the set() function. This allows another script to later
call get() and retrieve the data set() by another.
* It prepares logging right out of the box for you, there is no setup required
* All return codes have been simplified to None/True/False (you can still
use the old ones if you want)
use the old ones if you want).
* It handles all of the exception handling. By this I mean, your code can throw
an except and it's traceback will be captured gracefully to logging. Then the
framework will look after returning a correct failure error code to NZBGet.
* It provides some very useful functions that are always being re-written
inside of every other NZBGet script such as file scanning.
* It greatly simplifies the handling of environment variables and interaction
to and from NZBGet
to and from NZBGet.

Documentation
=============
Expand All @@ -38,92 +38,95 @@ Simplified Development
======================
The following are some of the functionality that is built in for you:

* validate() - handle environment checking, correct versioning as well
* __validate()__ - Handle environment checking, correct versioning as well
as if the expected configuration variables you specified
are present.

* health_check() - Checks the status of the retrieved content, currently
this is only useful during Post-Processing
* __health_check()__ - Checks the status of the retrieved content, currently
this is only useful during Post-Processing.

* push() - pushes a variables to the NZBGet server
* __push()__ - Pushes a variables to the NZBGet server.


* set()/get()- Hash table get/set attributes that can be set in one script
* __set()/get()__ - Hash table get/set attributes that can be set in one script
and then later retrieved from another. get() can also
be used to fetch content that was previously pushed using
the push() tool. You no longer need to work with environment
variables. If you enable the SQLite database, set content is
put here as well so that it can be retrieved by another
script.

* unset() - This allows you to unset values set by set() and get() as well
as ones set by push()
* __unset()__ - This allows you to unset values set by set() and get() as well
as ones set by push().

* nzb_set() - Similar to the set() function identified above except it
* __nzb_set()__ - Similar to the set() function identified above except it
is used to build an nzb meta hash table which can be later
pushed to the server using push_dnzb().

* add_nzb() - Using the built in API/RPC NZBGet supports, this
* __add_nzb()__ - Using the built in API/RPC NZBGet supports, this
allows you to specify a path to an NZBFile which you want to
enqueue for downloading.

* nzb_get() - Retieves NZB Meta information previously stored.
* __nzb_get()__ - Retieves NZB Meta information previously stored.

* nzb_unset()- Removes a variable previously set completely.
* __nzb_unset()__ - Removes a variable previously set completely.

* get_statistics()- Using the built in API/RPC NZBGet supports, this
* __get_statistics()__ - Using the built in API/RPC NZBGet supports, this
retrieves and returns the statistics in an easy to ready
dictionary (_PostProcessScript_ only).

* get_logs() - Using the built in API/RPC NZBGet supports, this
* __get_logs()__ - Using the built in API/RPC NZBGet supports, this
retrieves and returns the latest logs.

* get_files()- list all files in a specified directory as well as fetching
* __get_files()__ - list all files in a specified directory as well as fetching
their details such as filesize, modified date, etc in an
easy to reference dictionary. You can provide a ton of
different filters to minimize the content returned. Filters
can by a regular expression, file prefixes, and/or suffixes.

* parse_nzbfile() - Parse an NZB-File and extract all of its meta
* __parse_nzbfile()__ - Parse an NZB-File and extract all of its meta
information from it. lxml must be installed on your
system for this to work correctly
system for this to work correctly.

* parse_list() - Takes a string (or more) as well as lists of strings as
* __parse_list()__ - Takes a string (or more) as well as lists of strings as
input. It then cleans it up and produces an easy to
manage list by combining all of the results into 1.
Hence: parse_list('.mkv, .avi') returns:
[ '.mkv', '.avi' ]

* parse_path_list() - Very smilar to parse_list() except that it is used
* __parse_path_list()__ - Very smilar to parse_list() except that it is used
to handle directory paths while cleaning them up at the
same time.

* parse_bool() - Handles all of NZBGet's configuration options such as
* __parse_bool()__ - Handles all of NZBGet's configuration options such as
'on' and 'off' as well as 'yes' or 'no', or 'True' and
'False'. It greatly simplifies the checking of these
variables passed in from NZBGet
variables passed in from NZBGet.


* push_guess() - You can push a guessit dictionary (or one of your own
* __push_guess()__ - You can push a guessit dictionary (or one of your own
that can help identify your release for other scripts
to use later after yours finishes
to use later after yours finishes.

* pull_guess() - Pull a previous guess pushed by another script.
* __pull_guess()__ - Pull a previous guess pushed by another script.
why redo grunt work if it's already done for you?
if no previous guess content was pushed, then an
empty dictionary is returned.

* push_dnzb() - You can push all nzb meta information onbtained to
* __push_dnzb()__ - You can push all nzb meta information onbtained to
the NZBGet server as DNZB_ meta tags.

* pull_dnzb() - Pull all DNZB_ meta tags issued by the server and
* __pull_dnzb()__ - Pull all DNZB_ meta tags issued by the server and
return their values in a dictionary.
if no DNZB_ (NZB Meta information) was found, then an
empty dictionary is returned instead.

* deobfuscate() - Take a filename and return it in a deobfuscated to the
* __deobfuscate()__ - Take a filename and return it in a deobfuscated to the
best of its ability. (_PostProcessScript_ only)

* __is_unique_instance()__ - Allows you to ensure your instance of your script is
unique. This is useful for Scheduled scripts which can be
called and then run concurrently with NZBGet.
How To Use
==========
* Developers are only required to define a class that inherits the NZBGet class
Expand All @@ -134,7 +137,7 @@ _PostProcessScript_, etc.).

Post Process Script Example
===========================
```
```python
#############################################################################
### NZBGET POST-PROCESSING SCRIPT ###
#
Expand Down Expand Up @@ -178,9 +181,9 @@ class MyPostProcessScript(PostProcessScript):
print 'STATUS %s' self.get('STATUS')
print 'SCRIPTSTATUS %s' self.get('SCRIPTSTATUS')

# Set any variable you want by any key. Note that if you use
# Set any variable you want by any key. Note that if you use
# keys that were defined by the system (such as CATEGORY, DIRECTORY,
# etc, you may have some undesirable results. Try to avoid reusing
# etc, you may have some undesirable results. Try to avoid reusing
# system variables already defined (identified above):
self.set('MY_KEY', 'MY_VALUE')

Expand All @@ -206,7 +209,7 @@ class MyPostProcessScript(PostProcessScript):
# as follows:
print 'DEBUG %s' self.get('DEBUG')

# Returns have been made easy. Just return:
# Returns have been made easy. Just return:
# * True if everything was successful
# * False if there was a problem
# * None if you want to report that you've just gracefully
Expand All @@ -215,7 +218,7 @@ class MyPostProcessScript(PostProcessScript):
success status.

# Feel free to use the actual exit codes as well defined by
# NZBGet on their website. They have also been defined here
# NZBGet on their website. They have also been defined here
# from nzbget import EXIT_CODE

return True
Expand All @@ -233,7 +236,7 @@ if __name__ == "__main__":

Scan Script Example
===================
```
```python
############################################################################
### NZBGET SCAN SCRIPT ###
#
Expand Down Expand Up @@ -292,7 +295,7 @@ if __name__ == "__main__":

Scheduler Script Example
=======================
```
```python
############################################################################
### NZBGET SCHEDULER SCRIPT ###
#
Expand Down Expand Up @@ -345,7 +348,7 @@ if __name__ == "__main__":

MultiScript Example
=======================
```
```python
############################################################################
### NZBGET POST-PROCESSING/SCHEDULER SCRIPT ###
#
Expand Down

0 comments on commit 8e45fdf

Please sign in to comment.