Merge branch 'dev' of /home/git/repositories/echel0n/sickrage

This commit is contained in:
echel0n 2014-08-09 01:56:30 +00:00
commit a74181dca2
11 changed files with 2112 additions and 2069 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 760 B

View file

@ -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">

View file

@ -1,143 +1,145 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2012 Nicolas Wack <wackou@gmail.com> # Copyright 2012 Nicolas Wack <wackou@gmail.com>
# #
# This file is part of subliminal. # This file is part of subliminal.
# #
# subliminal is free software; you can redistribute it and/or modify it under # subliminal is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by # the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or # the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# subliminal is distributed in the hope that it will be useful, # subliminal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details. # GNU Lesser General Public License for more details.
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with subliminal. If not, see <http://www.gnu.org/licenses/>. # along with subliminal. If not, see <http://www.gnu.org/licenses/>.
from . import ServiceBase from . import ServiceBase
from ..cache import cachedmethod from ..cache import cachedmethod
from ..language import language_set, Language from ..language import language_set, Language
from ..subtitles import get_subtitle_path, ResultSubtitle from ..subtitles import get_subtitle_path, ResultSubtitle
from ..utils import get_keywords from ..utils import get_keywords
from ..videos import Episode from ..videos import Episode
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import logging import logging
import re import re
logger = logging.getLogger("subliminal") logger = logging.getLogger("subliminal")
def match(pattern, string): def match(pattern, string):
try: try:
return re.search(pattern, string).group(1) return re.search(pattern, string).group(1)
except AttributeError: except AttributeError:
logger.debug(u'Could not match %r on %r' % (pattern, string)) logger.debug(u'Could not match %r on %r' % (pattern, string))
return None return None
class TvSubtitles(ServiceBase): class TvSubtitles(ServiceBase):
server_url = 'http://www.tvsubtitles.net' server_url = 'http://www.tvsubtitles.net'
site_url = 'http://www.tvsubtitles.net' site_url = 'http://www.tvsubtitles.net'
api_based = False api_based = False
languages = language_set(['ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fr', 'hu', languages = language_set(['ar', 'bg', 'cs', 'da', 'de', 'el', 'en', 'es', 'fi', 'fr', 'hu',
'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv', 'tr', 'uk', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv', 'tr', 'uk',
'zh', 'pb']) 'zh', 'pb'])
#TODO: Find more exceptions #TODO: Find more exceptions
language_map = {'gr': Language('gre'), 'cz': Language('cze'), 'ua': Language('ukr'), language_map = {'gr': Language('gre'), 'cz': Language('cze'), 'ua': Language('ukr'),
'cn': Language('chi'), 'br': Language('pob')} 'cn': Language('chi'), 'br': Language('pob')}
videos = [Episode] videos = [Episode]
require_video = False require_video = False
required_features = ['permissive'] required_features = ['permissive']
@cachedmethod @cachedmethod
def get_likely_series_id(self, name): def get_likely_series_id(self, name):
r = self.session.post('%s/search.php' % self.server_url, data={'q': name}) r = self.session.post('%s/search.php' % self.server_url, data={'q': name})
soup = BeautifulSoup(r.content, self.required_features) soup = BeautifulSoup(r.content, self.required_features)
maindiv = soup.find('div', 'left') maindiv = soup.find('div', 'left')
results = [] results = []
for elem in maindiv.find_all('li'): for elem in maindiv.find_all('li'):
sid = int(match('tvshow-([0-9]+)\.html', elem.a['href'])) sid = int(match('tvshow-([0-9]+)\.html', elem.a['href']))
show_name = match('(.*) \(', elem.a.text) show_name = match('(.*) \(', elem.a.text)
results.append((show_name, sid)) results.append((show_name, sid))
#TODO: pick up the best one in a smart way
result = results[0] if len(results):
return result[1] #TODO: pick up the best one in a smart way
result = results[0]
@cachedmethod return result[1]
def get_episode_id(self, series_id, season, number):
"""Get the TvSubtitles id for the given episode. Raises KeyError if none @cachedmethod
could be found.""" def get_episode_id(self, series_id, season, number):
# download the page of the season, contains ids for all episodes """Get the TvSubtitles id for the given episode. Raises KeyError if none
episode_id = None could be found."""
r = self.session.get('%s/tvshow-%d-%d.html' % (self.server_url, series_id, season)) # download the page of the season, contains ids for all episodes
soup = BeautifulSoup(r.content, self.required_features) episode_id = None
table = soup.find('table', id='table5') r = self.session.get('%s/tvshow-%d-%d.html' % (self.server_url, series_id, season))
for row in table.find_all('tr'): soup = BeautifulSoup(r.content, self.required_features)
cells = row.find_all('td') table = soup.find('table', id='table5')
if not cells: for row in table.find_all('tr'):
continue cells = row.find_all('td')
episode_number = match('x([0-9]+)', cells[0].text) if not cells:
if not episode_number: continue
continue episode_number = match('x([0-9]+)', cells[0].text)
episode_number = int(episode_number) if not episode_number:
episode_id = int(match('episode-([0-9]+)', cells[1].a['href'])) continue
# we could just return the id of the queried episode, but as we episode_number = int(episode_number)
# already downloaded the whole page we might as well fill in the episode_id = int(match('episode-([0-9]+)', cells[1].a['href']))
# information for all the episodes of the season # we could just return the id of the queried episode, but as we
self.cache_for(self.get_episode_id, args=(series_id, season, episode_number), result=episode_id) # already downloaded the whole page we might as well fill in the
# raises KeyError if not found # information for all the episodes of the season
return self.cached_value(self.get_episode_id, args=(series_id, season, number)) self.cache_for(self.get_episode_id, args=(series_id, season, episode_number), result=episode_id)
# raises KeyError if not found
# Do not cache this method in order to always check for the most recent return self.cached_value(self.get_episode_id, args=(series_id, season, number))
# subtitles
def get_sub_ids(self, episode_id): # Do not cache this method in order to always check for the most recent
subids = [] # subtitles
r = self.session.get('%s/episode-%d.html' % (self.server_url, episode_id)) def get_sub_ids(self, episode_id):
epsoup = BeautifulSoup(r.content, self.required_features) subids = []
for subdiv in epsoup.find_all('a'): r = self.session.get('%s/episode-%d.html' % (self.server_url, episode_id))
if 'href' not in subdiv.attrs or not subdiv['href'].startswith('/subtitle'): epsoup = BeautifulSoup(r.content, self.required_features)
continue for subdiv in epsoup.find_all('a'):
subid = int(match('([0-9]+)', subdiv['href'])) if 'href' not in subdiv.attrs or not subdiv['href'].startswith('/subtitle'):
lang = self.get_language(match('flags/(.*).gif', subdiv.img['src'])) continue
result = {'subid': subid, 'language': lang} subid = int(match('([0-9]+)', subdiv['href']))
for p in subdiv.find_all('p'): lang = self.get_language(match('flags/(.*).gif', subdiv.img['src']))
if 'alt' in p.attrs and p['alt'] == 'rip': result = {'subid': subid, 'language': lang}
result['rip'] = p.text.strip() for p in subdiv.find_all('p'):
if 'alt' in p.attrs and p['alt'] == 'release': if 'alt' in p.attrs and p['alt'] == 'rip':
result['release'] = p.text.strip() result['rip'] = p.text.strip()
subids.append(result) if 'alt' in p.attrs and p['alt'] == 'release':
return subids result['release'] = p.text.strip()
subids.append(result)
def list_checked(self, video, languages): return subids
return self.query(video.path or video.release, languages, get_keywords(video.guess), video.series, video.season, video.episode)
def list_checked(self, video, languages):
def query(self, filepath, languages, keywords, series, season, episode): return self.query(video.path or video.release, languages, get_keywords(video.guess), video.series, video.season, video.episode)
logger.debug(u'Getting subtitles for %s season %d episode %d with languages %r' % (series, season, episode, languages))
self.init_cache() def query(self, filepath, languages, keywords, series, season, episode):
sid = self.get_likely_series_id(series.lower()) logger.debug(u'Getting subtitles for %s season %d episode %d with languages %r' % (series, season, episode, languages))
try: self.init_cache()
ep_id = self.get_episode_id(sid, season, episode) sid = self.get_likely_series_id(series.lower())
except KeyError: try:
logger.debug(u'Could not find episode id for %s season %d episode %d' % (series, season, episode)) ep_id = self.get_episode_id(sid, season, episode)
return [] except KeyError:
subids = self.get_sub_ids(ep_id) logger.debug(u'Could not find episode id for %s season %d episode %d' % (series, season, episode))
# filter the subtitles with our queried languages return []
subtitles = [] subids = self.get_sub_ids(ep_id)
for subid in subids: # filter the subtitles with our queried languages
language = subid['language'] subtitles = []
if language not in languages: for subid in subids:
continue language = subid['language']
path = get_subtitle_path(filepath, language, self.config.multi) if language not in languages:
subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), '%s/download-%d.html' % (self.server_url, subid['subid']), continue
keywords=[subid['rip'], subid['release']]) path = get_subtitle_path(filepath, language, self.config.multi)
subtitles.append(subtitle) subtitle = ResultSubtitle(path, language, self.__class__.__name__.lower(), '%s/download-%d.html' % (self.server_url, subid['subid']),
return subtitles keywords=[subid['rip'], subid['release']])
subtitles.append(subtitle)
def download(self, subtitle): return subtitles
self.download_zip_file(subtitle.link, subtitle.path)
return subtitle def download(self, subtitle):
self.download_zip_file(subtitle.link, subtitle.path)
return subtitle
Service = TvSubtitles
Service = TvSubtitles

View file

@ -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"])

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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

View file

@ -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