From 2155d5205b31333c37edd2b743b6ee2c83bd81d0 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Mon, 19 Mar 2018 13:09:01 +0000 Subject: [PATCH] Add showRSS torrent provider. --- CHANGES.md | 1 + gui/slick/images/providers/showrss.png | Bin 0 -> 252 bytes sickbeard/providers/__init__.py | 3 +- sickbeard/providers/showrss.py | 153 +++++++++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 gui/slick/images/providers/showrss.png create mode 100644 sickbeard/providers/showrss.py diff --git a/CHANGES.md b/CHANGES.md index d4b3fe61..ab23f70f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ### 0.15.0 (2018-xx-xx xx:xx:xx UTC) +* Add showRSS torrent provider * Add choice to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex, instructions at Shows/History/Layout/"Watched" * Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater" diff --git a/gui/slick/images/providers/showrss.png b/gui/slick/images/providers/showrss.png new file mode 100644 index 0000000000000000000000000000000000000000..08357543fc6ec7f9906895fed715c468243ed399 GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85p>My0`@x*DCKV1qx2|ba4!^@Si*3E@y)QPm6KmWQ*o?4<;YA zWjUD2GQDt(*Dbj%Fa6iByL(rE7jz1GU3s(M?3G`|j}BPqZWGD*tNN(HP>uWJ?5I9b zXRibPj~+e$wCC-%;|rf1J)LO(J;2ncfT{3l^D8}vE(T4`K*md)DhwN#OPhEuSu=K7 v>{iQQd~m. + +import re +import traceback + +from . import generic +from sickbeard import logger +from sickbeard.bs4_parser import BS4Parser +from sickbeard.helpers import tryInt, sanitizeSceneName +from lib.unidecode import unidecode +from six.moves.html_parser import HTMLParser + + +class ShowRSSProvider(generic.TorrentProvider): + + def __init__(self): + + generic.TorrentProvider.__init__(self, 'showRSS') + + self.url_base = 'https://showrss.info/' + self.urls = {'config_provider_home_uri': self.url_base, + 'login_action': self.url_base + 'login', + 'browse': self.url_base + 'browse/all', + 'search': self.url_base + 'browse/%s'} + + self.url = self.urls['config_provider_home_uri'] + + self.username, self.password, self.shows = 3 * [None] + + def _authorised(self, **kwargs): + + return super(ShowRSSProvider, self)._authorised(logged_in=(lambda y=None: self.logged_in(y))) + + def logged_in(self, y): + if all([None is y or 'logout' in y, + bool(filter(lambda c: 'remember_web_' in c, self.session.cookies.keys()))]): + if None is not y: + self.shows = dict(re.findall('', y)) + h = HTMLParser() + for k, v in self.shows.items(): + self.shows[k] = sanitizeSceneName(h.unescape(unidecode(v.decode('utf-8')))) + return True + return False + + def _search_provider(self, search_params, **kwargs): + + results = [] + if not self._authorised(): + return results + + items = {'Cache': [], 'Season': [], 'Episode': [], 'Propers': []} + + rc = dict((k, re.compile('(?i)' + v)) for (k, v) in {'get': 'magnet'}.items()) + urls = [] + for mode in search_params.keys(): + for search_string in search_params[mode]: + if 'Cache' == mode: + search_url = self.urls['browse'] + else: + search_string = isinstance(search_string, unicode) and unidecode(search_string) or search_string + show_name = filter(lambda x: x.lower() == re.sub('\s.*', '', search_string.lower()), + self.shows.values()) + if not show_name: + continue + search_url = self.urls['search'] % self.shows.keys()[self.shows.values().index(show_name[0])] + + if search_url in urls: + continue + urls += [search_url] + + html = self.get_url(search_url) + if self.should_skip(): + return results + + cnt = len(items[mode]) + try: + if not html or self._has_no_results(html): + raise generic.HaltParseException + + with BS4Parser(html, features=['html5lib', 'permissive']) as soup: + torrent_rows = soup.select('ul.user-timeline > li') + + if not len(torrent_rows): + raise generic.HaltParseException + + for tr in torrent_rows: + try: + anchor = tr.find('a', href=rc['get']) + title = self.regulate_title(anchor) + download_url = self._link(anchor['href']) + except (AttributeError, TypeError, ValueError): + continue + + if title and download_url: + items[mode].append((title, download_url, None, None)) + + except generic.HaltParseException: + pass + except (StandardError, Exception): + logger.log(u'Failed to parse. Traceback: %s' % traceback.format_exc(), logger.ERROR) + self._log_search(mode, len(items[mode]) - cnt, search_url) + + results = self._sort_seeding(mode, results + items[mode]) + + return results + + @staticmethod + def regulate_title(anchor): + title = '' + t1 = anchor.attrs.get('title').strip() + t2 = anchor.get_text().strip() + diff, x, offset = 0, 0, 0 + for x, c in enumerate(t2): + if c.lower() == t1[x-offset].lower(): + title += t1[x-offset] + diff = 0 + elif ' ' != c and ' ' == t1[x-offset]: + title += c + diff = 0 + if ' ' == t2[x+1]: + offset += 1 + else: + diff += 1 + if 1 < diff: + break + return '%s%s' % (title, re.sub('(?i)(xvid|divx|[hx].?26[45])\s(\w+)$', r'\1-\2', + ''.join(t1[x - (offset + diff)::]).strip())) + + @staticmethod + def ui_string(key): + + return ('showrss_tip' == key + and 'lists are not needed, the SickGear list is used as usual' or '') + + +provider = ShowRSSProvider()