From efc02f66f59e90c60de16be2b81aa7eb20323ca5 Mon Sep 17 00:00:00 2001 From: Dean Gardiner Date: Sun, 1 Dec 2013 20:20:19 +1300 Subject: [PATCH] Changed the IPTorrents show provider into a new season and episode provider, removed grouped cat_ids --- couchpotato/core/providers/base.py | 29 +-------------- couchpotato/core/providers/info/base.py | 10 ++++- .../core/providers/torrent/iptorrents/main.py | 37 +++++++++---------- 3 files changed, 29 insertions(+), 47 deletions(-) diff --git a/couchpotato/core/providers/base.py b/couchpotato/core/providers/base.py index 3cbd382d..4e6cf92a 100644 --- a/couchpotato/core/providers/base.py +++ b/couchpotato/core/providers/base.py @@ -105,7 +105,6 @@ class YarrProvider(Provider): type = 'movie' cat_ids = {} - cat_ids_structure = None cat_backup_id = None sizeGb = ['gb', 'gib'] @@ -250,33 +249,9 @@ class YarrProvider(Provider): return 0 - def _discoverCatIdStructure(self): - # Discover cat_ids structure (single or groups) - for group_name, group_cat_ids in self.cat_ids: - if len(group_cat_ids) > 0: - if type(group_cat_ids[0]) is tuple: - self.cat_ids_structure = 'group' - if type(group_cat_ids[0]) is str: - self.cat_ids_structure = 'single' + def getCatId(self, identifier): - def getCatId(self, identifier, group = None): - - cat_ids = self.cat_ids - - if not self.cat_ids_structure: - self._discoverCatIdStructure() - - # If cat_ids is in a 'groups' structure, locate the media group - if self.cat_ids_structure == 'group': - if not group: - raise ValueError("group is required on group cat_ids structure") - - for group_type, group_cat_ids in cat_ids: - if group in toIterable(group_type): - cat_ids = group_cat_ids - - for cats in cat_ids: - ids, qualities = cats + for ids, qualities in self.cat_ids: if identifier in qualities: return ids diff --git a/couchpotato/core/providers/info/base.py b/couchpotato/core/providers/info/base.py index 8d06c322..47b7c000 100644 --- a/couchpotato/core/providers/info/base.py +++ b/couchpotato/core/providers/info/base.py @@ -6,4 +6,12 @@ class MovieProvider(Provider): class ShowProvider(Provider): - type = ['season', 'episode'] + type = 'show' + + +class SeasonProvider(Provider): + type = 'season' + + +class EpisodeProvider(Provider): + type = 'episode' diff --git a/couchpotato/core/providers/torrent/iptorrents/main.py b/couchpotato/core/providers/torrent/iptorrents/main.py index 55fa815f..f030a7e3 100644 --- a/couchpotato/core/providers/torrent/iptorrents/main.py +++ b/couchpotato/core/providers/torrent/iptorrents/main.py @@ -3,7 +3,7 @@ from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.variable import tryInt from couchpotato.core.logger import CPLog from couchpotato.core.providers.base import MultiProvider -from couchpotato.core.providers.info.base import MovieProvider, ShowProvider +from couchpotato.core.providers.info.base import MovieProvider, SeasonProvider, EpisodeProvider from couchpotato.core.providers.torrent.base import TorrentProvider import traceback @@ -13,7 +13,7 @@ log = CPLog(__name__) class IPTorrents(MultiProvider): def getTypes(self): - return [Movie, Show] + return [Movie, Season, Episode] class Base(TorrentProvider): @@ -29,13 +29,16 @@ class Base(TorrentProvider): http_time_between_calls = 1 #seconds cat_backup_id = None - def _buildUrl(self, query, quality_identifier, cat_ids_group = None): + def buildUrl(self, title, media, quality): + return self._buildUrl(title.replace(':', ''), quality['identifier']) - cat_ids = self.getCatId(quality_identifier, cat_ids_group) + def _buildUrl(self, query, quality_identifier): - if not cat_ids or not len(cat_ids): - log.warning('Unable to find category for quality %s', quality_identifier) - return + cat_ids = self.getCatId(quality_identifier) + + if not cat_ids: + log.warning('Unable to find category ids for identifier "%s"', quality_identifier) + return None return self.urls['search'] % ("&".join(("l%d=" % x) for x in cat_ids), tryUrlencode(query).replace('%', '%%')) @@ -133,20 +136,16 @@ class Movie(MovieProvider, Base): return self._buildUrl(query, quality['identifier']) -class Show(ShowProvider, Base): +class Season(SeasonProvider, Base): cat_ids = [ - ('season', [ - ([65], ['hdtv_sd', 'hdtv_720p', 'webdl_720p', 'webdl_1080p']), - ]), - ('episode', [ - ([5], ['hdtv_720p', 'webdl_720p', 'webdl_1080p']), - ([4, 78, 79], ['hdtv_sd']) - ]) + ([65], ['hdtv_sd', 'hdtv_720p', 'webdl_720p', 'webdl_1080p']), ] - def buildUrl(self, title, media, quality): - if media['type'] not in ['season', 'episode']: - return - return self._buildUrl(title.replace(':', ''), quality['identifier'], media['type']) \ No newline at end of file +class Episode(EpisodeProvider, Base): + + cat_ids = [ + ([5], ['hdtv_720p', 'webdl_720p', 'webdl_1080p']), + ([4, 78, 79], ['hdtv_sd']) + ]