mirror of
https://github.com/moparisthebest/SickRage
synced 2024-12-13 03:22:22 -05:00
Merge pull request #697 from cptjhmiller/dev
Trakt method, error checking, remove series
This commit is contained in:
commit
8bec8751fb
@ -1237,8 +1237,13 @@
|
|||||||
<div class="field-pair">
|
<div class="field-pair">
|
||||||
<input type="checkbox" name="trakt_remove_watchlist" id="trakt_remove_watchlist" #if $sickbeard.TRAKT_REMOVE_WATCHLIST then "checked=\"checked\"" else ""# />
|
<input type="checkbox" name="trakt_remove_watchlist" id="trakt_remove_watchlist" #if $sickbeard.TRAKT_REMOVE_WATCHLIST then "checked=\"checked\"" else ""# />
|
||||||
<label class="clearfix" for="trakt_remove_watchlist">
|
<label class="clearfix" for="trakt_remove_watchlist">
|
||||||
<span class="component-title">Remove from Watchlist:</span>
|
<span class="component-title">Remove episode:</span>
|
||||||
<span class="component-desc">Remove an episode from the watchlist after it is downloaded</span>
|
<span class="component-desc">Remove an episode from the watchlist after it is downloaded</span>
|
||||||
|
</label>
|
||||||
|
<input type="checkbox" name="trakt_remove_serieslist" id="trakt_remove_serieslist" #if $sickbeard.TRAKT_REMOVE_SERIESLIST then "checked=\"checked\"" else ""# />
|
||||||
|
<label class="clearfix" for="trakt_remove_serieslist">
|
||||||
|
<span class="component-title">Remove series:</span>
|
||||||
|
<span class="component-desc">Remove the whole series from the watchlist after any download</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-pair">
|
<div class="field-pair">
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import urllib2
|
from urllib2 import Request, urlopen, HTTPError, URLError
|
||||||
|
|
||||||
|
import base64
|
||||||
|
from sha import new as sha1
|
||||||
|
|
||||||
from hashlib import sha1
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -25,25 +26,35 @@ def TraktCall(method, api, username=None, password=None, data={}):
|
|||||||
if not api:
|
if not api:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# if the username isn't given then it failed
|
|
||||||
if username and password:
|
|
||||||
password = sha1(password).hexdigest()
|
|
||||||
data["username"] = username
|
|
||||||
data["password"] = password
|
|
||||||
|
|
||||||
# replace the API string with what we found
|
# replace the API string with what we found
|
||||||
method = method.replace("%API%", api)
|
method = method.replace("%API%", api)
|
||||||
|
|
||||||
|
# make the full url
|
||||||
|
url = 'https://api.trakt.tv/' + method
|
||||||
|
|
||||||
# take the URL params and make a json object out of them
|
# take the URL params and make a json object out of them
|
||||||
encoded_data = json.dumps(data)
|
encoded_data = json.JSONEncoder().encode(data)
|
||||||
|
|
||||||
|
request = Request(url, encoded_data)
|
||||||
|
|
||||||
|
# if the username isn't given then it failed
|
||||||
|
if username and password:
|
||||||
|
pwdsha1 = sha1(password).hexdigest()
|
||||||
|
base64string = base64.encodestring('%s:%s' % (username, pwdsha1)).replace('\n', '')
|
||||||
|
request.add_header("Accept", "*/*")
|
||||||
|
request.add_header("User-Agent", "CPython/2.7.5 Unknown/Unknown")
|
||||||
|
request.add_header("Authorization", "Basic %s" % base64string)
|
||||||
|
|
||||||
# request the URL from trakt and parse the result as json
|
# request the URL from trakt and parse the result as json
|
||||||
try:
|
try:
|
||||||
#logger.log("trakt: Calling method http://api.trakt.tv/" + method + ", with data" + encoded_data, logger.DEBUG)
|
#logger.log("trakt: Calling method http://api.trakt.tv/" + method + ", with data" + encoded_data, logger.DEBUG)
|
||||||
stream = urllib2.urlopen("http://api.trakt.tv/" + method, encoded_data)
|
stream = urlopen(request).read()
|
||||||
resp = stream.read()
|
|
||||||
|
|
||||||
resp = json.loads(resp)
|
# check if results are valid
|
||||||
|
if stream == '[]':
|
||||||
|
resp = 'NULL'
|
||||||
|
else:
|
||||||
|
resp = json.JSONDecoder().decode(stream)
|
||||||
|
|
||||||
if ("error" in resp):
|
if ("error" in resp):
|
||||||
raise Exception(resp["error"])
|
raise Exception(resp["error"])
|
||||||
|
@ -351,6 +351,7 @@ TRAKT_USERNAME = None
|
|||||||
TRAKT_PASSWORD = None
|
TRAKT_PASSWORD = None
|
||||||
TRAKT_API = ''
|
TRAKT_API = ''
|
||||||
TRAKT_REMOVE_WATCHLIST = False
|
TRAKT_REMOVE_WATCHLIST = False
|
||||||
|
TRAKT_REMOVE_SERIESLIST = False
|
||||||
TRAKT_USE_WATCHLIST = False
|
TRAKT_USE_WATCHLIST = False
|
||||||
TRAKT_METHOD_ADD = 0
|
TRAKT_METHOD_ADD = 0
|
||||||
TRAKT_START_PAUSED = False
|
TRAKT_START_PAUSED = False
|
||||||
|
@ -53,6 +53,10 @@ class TraktChecker():
|
|||||||
def findShow(self, indexer, indexerid):
|
def findShow(self, indexer, indexerid):
|
||||||
library = TraktCall("user/library/shows/all.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
library = TraktCall("user/library/shows/all.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
||||||
|
|
||||||
|
if library == 'NULL':
|
||||||
|
logger.log(u"No shows found in your library, aborting library update", logger.DEBUG)
|
||||||
|
return
|
||||||
|
|
||||||
if not library:
|
if not library:
|
||||||
logger.log(u"Could not connect to trakt service, aborting library check", logger.ERROR)
|
logger.log(u"Could not connect to trakt service, aborting library check", logger.ERROR)
|
||||||
return
|
return
|
||||||
@ -102,6 +106,10 @@ class TraktChecker():
|
|||||||
logger.log(u"Starting trakt show watchlist check", logger.DEBUG)
|
logger.log(u"Starting trakt show watchlist check", logger.DEBUG)
|
||||||
watchlist = TraktCall("user/watchlist/shows.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
watchlist = TraktCall("user/watchlist/shows.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
||||||
|
|
||||||
|
if watchlist == 'NULL':
|
||||||
|
logger.log(u"No shows found in your watchlist, aborting watchlist update", logger.DEBUG)
|
||||||
|
return
|
||||||
|
|
||||||
if not watchlist:
|
if not watchlist:
|
||||||
logger.log(u"Could not connect to trakt service, aborting watchlist update", logger.ERROR)
|
logger.log(u"Could not connect to trakt service, aborting watchlist update", logger.ERROR)
|
||||||
return
|
return
|
||||||
@ -134,6 +142,10 @@ class TraktChecker():
|
|||||||
logger.log(u"Starting trakt episode watchlist check", logger.DEBUG)
|
logger.log(u"Starting trakt episode watchlist check", logger.DEBUG)
|
||||||
watchlist = TraktCall("user/watchlist/episodes.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
watchlist = TraktCall("user/watchlist/episodes.json/%API%/" + sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
||||||
|
|
||||||
|
if watchlist == 'NULL':
|
||||||
|
logger.log(u"No episodes found in your watchlist, aborting watchlist update", logger.DEBUG)
|
||||||
|
return
|
||||||
|
|
||||||
if not watchlist:
|
if not watchlist:
|
||||||
logger.log(u"Could not connect to trakt service, aborting watchlist update", logger.ERROR)
|
logger.log(u"Could not connect to trakt service, aborting watchlist update", logger.ERROR)
|
||||||
return
|
return
|
||||||
|
@ -2252,7 +2252,7 @@ class ConfigNotifications(MainHandler):
|
|||||||
use_trakt=None, trakt_username=None, trakt_password=None, trakt_api=None,
|
use_trakt=None, trakt_username=None, trakt_password=None, trakt_api=None,
|
||||||
trakt_remove_watchlist=None, trakt_use_watchlist=None, trakt_method_add=None,
|
trakt_remove_watchlist=None, trakt_use_watchlist=None, trakt_method_add=None,
|
||||||
trakt_start_paused=None, trakt_use_recommended=None, trakt_sync=None,
|
trakt_start_paused=None, trakt_use_recommended=None, trakt_sync=None,
|
||||||
trakt_default_indexer=None,
|
trakt_default_indexer=None, trakt_remove_serieslist=None,
|
||||||
use_synologynotifier=None, synologynotifier_notify_onsnatch=None,
|
use_synologynotifier=None, synologynotifier_notify_onsnatch=None,
|
||||||
synologynotifier_notify_ondownload=None, synologynotifier_notify_onsubtitledownload=None,
|
synologynotifier_notify_ondownload=None, synologynotifier_notify_onsubtitledownload=None,
|
||||||
use_pytivo=None, pytivo_notify_onsnatch=None, pytivo_notify_ondownload=None,
|
use_pytivo=None, pytivo_notify_onsnatch=None, pytivo_notify_ondownload=None,
|
||||||
@ -2360,6 +2360,7 @@ class ConfigNotifications(MainHandler):
|
|||||||
sickbeard.TRAKT_PASSWORD = trakt_password
|
sickbeard.TRAKT_PASSWORD = trakt_password
|
||||||
sickbeard.TRAKT_API = trakt_api
|
sickbeard.TRAKT_API = trakt_api
|
||||||
sickbeard.TRAKT_REMOVE_WATCHLIST = config.checkbox_to_value(trakt_remove_watchlist)
|
sickbeard.TRAKT_REMOVE_WATCHLIST = config.checkbox_to_value(trakt_remove_watchlist)
|
||||||
|
sickbeard.TRAKT_REMOVE_SERIESLIST = config.checkbox_to_value(trakt_remove_serieslist)
|
||||||
sickbeard.TRAKT_USE_WATCHLIST = config.checkbox_to_value(trakt_use_watchlist)
|
sickbeard.TRAKT_USE_WATCHLIST = config.checkbox_to_value(trakt_use_watchlist)
|
||||||
sickbeard.TRAKT_METHOD_ADD = trakt_method_add
|
sickbeard.TRAKT_METHOD_ADD = trakt_method_add
|
||||||
sickbeard.TRAKT_START_PAUSED = config.checkbox_to_value(trakt_start_paused)
|
sickbeard.TRAKT_START_PAUSED = config.checkbox_to_value(trakt_start_paused)
|
||||||
@ -2795,6 +2796,11 @@ class NewHomeAddShows(MainHandler):
|
|||||||
|
|
||||||
logger.log(u"Getting recommended shows from Trakt.tv", logger.DEBUG)
|
logger.log(u"Getting recommended shows from Trakt.tv", logger.DEBUG)
|
||||||
recommendedlist = TraktCall("recommendations/shows.json/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
recommendedlist = TraktCall("recommendations/shows.json/%API%", sickbeard.TRAKT_API, sickbeard.TRAKT_USERNAME, sickbeard.TRAKT_PASSWORD)
|
||||||
|
|
||||||
|
if recommendedlist == 'NULL':
|
||||||
|
logger.log(u"No shows found in your recommendedlist, aborting recommendedlist update", logger.DEBUG)
|
||||||
|
return
|
||||||
|
|
||||||
if recommendedlist is None:
|
if recommendedlist is None:
|
||||||
logger.log(u"Could not connect to trakt service, aborting recommended list update", logger.ERROR)
|
logger.log(u"Could not connect to trakt service, aborting recommended list update", logger.ERROR)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user