def _notActiveShows(self, _list, source): _check_order = ['Match', 'Country', 'Year', None] for key in sorted(_list, reverse=True): for _check in _check_order: for _series in _list[key].itervalues(): if _check == 'Match': if _series.titleType == self.series.titleType: if matching(_series.title, self.series.title, factor=98): self.series.update(_series) self.series.source = source if source == 'tvdb': self.series.tvdb_info = _series elif source == 'tvrage': self.series.tvrage_info = _series return True elif _series.titleType == _check: if matching(_series.titleBase, self.series.titleBase, factor=98): self.series.update(_series) self.series.source = source if source == 'tvdb': self.series.tvdb_info = _series elif source == 'tvrage': self.series.tvrage_info = _series return True return False
def _notActiveShows(self, _list, source): _check_order = ["Match", "Country", "Year", None] for key in sorted(_list, reverse=True): for _check in _check_order: for _series in _list[key].itervalues(): if _check == "Match": if _series.titleType == self.series.titleType: if matching(_series.title, self.series.title, factor=98): self.series.update(_series) self.series.source = source if source == "tvdb": self.series.tvdb_info = _series elif source == "tvrage": self.series.tvrage_info = _series return True elif _series.titleType == _check: if matching(_series.titleBase, self.series.titleBase, factor=98): self.series.update(_series) self.series.source = source if source == "tvdb": self.series.tvdb_info = _series elif source == "tvrage": self.series.tvrage_info = _series return True return False
def _tvrageGetInfo(self): _shows = feeds.search(self.series.titleBase) if not _shows: raise SeriesNotFound if len(_shows) == 1: _series = Series(tvrage=etree_to_dict(_shows[0])["show"]) if matching(self.series.title.lower(), _series.title.lower(), factor=85): _series = Series(tvrage=_shows[0]) self.series.update(_series) self.series.source = "tvrage" self.series.tvrage_info = _series return else: raise SeriesNotFound _rankings = {} for _show in _shows: _series = Series(tvrage=etree_to_dict(_show)["show"]) _score = matching(self.series.title.lower(), self.decode(_series.titleBase.lower())) if _score < 85: continue if _score in _rankings[_series.status]: _rankings[_series.status][_score][_series.title] = _series else: _rankings[_series.status][_score] = {_series.title: _series} if not _rankings: raise SeriesNotFound self._reviewShowData(_rankings, "tvrage") return
def review_entries(self, tmdb_results): """ :param tmdb_results: :param chkyear: :return: :raise MovieNotFound: """ try: for _movie in tmdb_results: _title = decode(_movie.title) if self.year: if matching(" ".join([_title.lower(), str(_movie.releasedate.year)]), " ".join([self.title.lower(), str(self.year)])): self.title = _title raise GetOutOfLoop(_movie) if matching(_title.lower(), self.title.lower()): self.title = _title raise GetOutOfLoop(_movie) else: # Check Alternate Titles: list(AlternateTitle) alternate_titles for _alternate_title in _movie.alternate_titles: log.trace('Check Alternate Titles: {}'.format(_alternate_title)) _alternate_title = decode(_alternate_title) if matching(_alternate_title, self.title): _movie.alternate_titles.append(_title) self.title = _alternate_title self.alternate_title = _movie.alternate_titles raise GetOutOfLoop(_movie) log.warn("Movie Not Found in TMDb: {}".format(self.title)) raise MovieNotFound("Movie Not Found in TMDb: {}".format(self.title)) except GetOutOfLoop, e: _movie = e.message if _movie.releasedate: if self.year: if (-2 < (self.year - _movie.releasedate.year) < 2): self.year = _movie.releasedate.year else: msg = "Movie name found, Years too far apart: {} - {}/{}".format(self.title, self.year, _movie.releasedate.year) log.warning(msg) raise MovieNotFound(msg) else: self.year = _movie.releasedate.year log.trace("Movie Located in TMDB") self.tmdb_id = _movie.id self.imdb_id = _movie.imdb self.slug = self.title self.cast = _movie.cast if hasattr(_movie, "alternate_titles"): self.alternate_title = _movie.alternate_titles
def _tvdbGetInfo(self): try: _shows = self.db.search(self.series.titleBase, "en") except (TVDBAttributeError, TVDBIndexError, TVDBValueError, error.BadData): _an_error = traceback.format_exc() log.debug( traceback.format_exception_only(type(_an_error), _an_error)[-1]) raise SeriesNotFound if len(_shows) == 0: raise SeriesNotFound if len(_shows) == 1: if matching(self.series.title.lower(), self.decode(_shows[0].SeriesName).lower(), factor=85): _shows[0].update() _series = Series(tvdb=_shows[0]) self.series.update(_series) self.series.source = 'tvdb' self.series.tvdb_info = _series return else: raise SeriesNotFound _rankings = {'Continuing': {}, 'Ended': {}, 'Other': {}} for _show in _shows: _title_suffix = self._check_suffix.match( self.decode(_show.SeriesName)) if _title_suffix: _score = matching(self.series.titleBase.lower(), _title_suffix.group('SeriesName').lower()) else: _score = matching(self.series.titleBase.lower(), self.decode(_show.SeriesName).lower()) if _score < 90: continue _show.update() _series = Series(tvdb=_show) if _score in _rankings[_series.status]: _rankings[_series.status][_score][_series.title] = _series else: _rankings[_series.status][_score] = {_series.title: _series} if not _rankings: raise SeriesNotFound self._reviewShowData(_rankings, 'tvdb') return
def _activeShows(self, _list, source): _check_order = ['Country', 'Year', None] for key in sorted(_list, reverse=True): for _check in _check_order: for _series in _list[key].itervalues(): if _series.titleType != _check: continue if _check == 'Country': if self.series.titleType == 'Country': if self.series.country != _series.country: continue elif _series.country != 'US': continue if _check == 'Year': if self.series.titleType == 'Year': if self.series.titleSuffix != _series.titleSuffix: continue if matching(_series.titleBase, self.series.titleBase, factor=98): self.series.update(_series) self.series.source = source if source == 'tvdb': self.series.tvdb_info = _series elif source == 'tvrage': self.series.tvrage_info = _series return True return False
def _activeShows(self, _list, source): _check_order = ["Country", "Year", None] for key in sorted(_list, reverse=True): for _check in _check_order: for _series in _list[key].itervalues(): if _series.titleType != _check: continue if _check == "Country": if self.series.titleType == "Country": if self.series.country != _series.country: continue elif _series.country != "US": continue if _check == "Year": if self.series.titleType == "Year": if self.series.titleSuffix != _series.titleSuffix: continue if matching(_series.titleBase, self.series.titleBase, factor=98): self.series.update(_series) self.series.source = source if source == "tvdb": self.series.tvdb_info = _series elif source == "tvrage": self.series.tvrage_info = _series return True return False
def _tvdbGetInfo(self): try: _shows = self.db.search(self.series.titleBase, "en") except (TVDBAttributeError, TVDBIndexError, TVDBValueError, error.BadData): _an_error = traceback.format_exc() log.debug(traceback.format_exception_only(type(_an_error), _an_error)[-1]) raise SeriesNotFound if len(_shows) == 0: raise SeriesNotFound if len(_shows) == 1: if matching(self.series.title.lower(), self.decode(_shows[0].SeriesName).lower(), factor=85): _shows[0].update() _series = Series(tvdb=_shows[0]) self.series.update(_series) self.series.source = "tvdb" self.series.tvdb_info = _series return else: raise SeriesNotFound _rankings = {"Continuing": {}, "Ended": {}, "Other": {}} for _show in _shows: _title_suffix = self._check_suffix.match(self.decode(_show.SeriesName)) if _title_suffix: _score = matching(self.series.titleBase.lower(), _title_suffix.group("SeriesName").lower()) else: _score = matching(self.series.titleBase.lower(), self.decode(_show.SeriesName).lower()) if _score < 90: continue _show.update() _series = Series(tvdb=_show) if _score in _rankings[_series.status]: _rankings[_series.status][_score][_series.title] = _series else: _rankings[_series.status][_score] = {_series.title: _series} if not _rankings: raise SeriesNotFound self._reviewShowData(_rankings, "tvdb") return
def _tvrageGetInfo(self): _shows = feeds.search(self.series.titleBase) if not _shows: raise SeriesNotFound if len(_shows) == 1: _series = Series(tvrage=etree_to_dict(_shows[0])['show']) if matching(self.series.title.lower(), _series.title.lower(), factor=85): _series = Series(tvrage=_shows[0]) self.series.update(_series) self.series.source = 'tvrage' self.series.tvrage_info = _series return else: raise SeriesNotFound _rankings = {} for _show in _shows: _series = Series(tvrage=etree_to_dict(_show)['show']) _score = matching(self.series.title.lower(), self.decode(_series.titleBase.lower())) if _score < 85: continue if _score in _rankings[_series.status]: _rankings[_series.status][_score][_series.title] = _series else: _rankings[_series.status][_score] = {_series.title: _series} if not _rankings: raise SeriesNotFound self._reviewShowData(_rankings, 'tvrage') return
def _traktGetInfo(self): try: if not self.trakt_user: MyTrakt.api_key = self.settings.TraktAPIKey MyTrakt.authenticate(self.settings.TraktUserID, self.settings.TraktPassWord) self.trakt_user = User(self.settings.TraktUserID) except: raise SeriesNotFound( 'MyTrakt: Unable to connect to MyTrakt service: {}'.format( self.settings.TraktUserID)) show = TVShow(self.series.title) if not show.tvdb_id: raise SeriesNotFound('MyTrakt: Unable to locate series: {}'.format( self.series.title)) _title = self.decode(show.title) if not matching(self.series.title.lower(), _title.lower(), factor=85): raise SeriesNotFound('MyTrakt: Unable to locate series: {}'.format( self.series.title)) if not self.series.source: self.series.source = 'MyTrakt' self.series.title = show.title if show.tvdb_id and self.series.tvdb_id is None: self.series.tvdb_id = show.tvdb_id if hasattr(show, 'tvrage_id') and show.tvrage_id: if self.series.tvrage_id is None: self.series.tvrage_id = show.tvrage_id if hasattr(show, 'imdb_id') and show.imdb_id: if self.series.imdb_id is None: self.series.imdb_id = self.decode(show.imdb_id) # if show.status and 'status' not in results: # results['status'] = series.status return
def _traktGetInfo(self): try: if not self.trakt_user: MyTrakt.api_key = self.settings.TraktAPIKey MyTrakt.authenticate(self.settings.TraktUserID, self.settings.TraktPassWord) self.trakt_user = User(self.settings.TraktUserID) except: raise SeriesNotFound("MyTrakt: Unable to connect to MyTrakt service: {}".format(self.settings.TraktUserID)) show = TVShow(self.series.title) if not show.tvdb_id: raise SeriesNotFound("MyTrakt: Unable to locate series: {}".format(self.series.title)) _title = self.decode(show.title) if not matching(self.series.title.lower(), _title.lower(), factor=85): raise SeriesNotFound("MyTrakt: Unable to locate series: {}".format(self.series.title)) if not self.series.source: self.series.source = "MyTrakt" self.series.title = show.title if show.tvdb_id and self.series.tvdb_id is None: self.series.tvdb_id = show.tvdb_id if hasattr(show, "tvrage_id") and show.tvrage_id: if self.series.tvrage_id is None: self.series.tvrage_id = show.tvrage_id if hasattr(show, "imdb_id") and show.imdb_id: if self.series.imdb_id is None: self.series.imdb_id = self.decode(show.imdb_id) # if show.status and 'status' not in results: # results['status'] = series.status return
def _flt_match(self, x): return matching(x.title, self.title) \ == max([max(matching(x.title, self.title) for x in self._list), 60]) def __str__(self):
def trakt_info(self, title=None, year=None, country=None): from urllib2 import HTTPError _filterOrder = ['tz', 'status', 'rating', 'scores', 'newest'] _filter_options = {'scores': self._flt_scores, 'tz': self._flt_tz, 'match': self._flt_match, 'rating': self._flt_rating, 'status': self._flt_status, 'newest': self._flt_newest} if self.trakt_id is not None: if None in [self.status]: try: _kwargs = getShow(show=self.trakt_id, rtn=str) except HTTPError: return self.load_attr(_kwargs) return try: if not title is None: self.title = title if self.year: self._list = searchShow(show=self.title, year=self.year, rtn=list) for _entry in self._list: if _entry.year == self.year: continue _entry.title = 'SKIP' self._list = filter(_filter_options['match'], self._list) if type(self._list) is HTTPError or not len(self._list) > 0: self._list = searchShow(show=self.title, rtn=list) elif self.country: self._list = searchShow(show=self.title, rtn=list) if type(self._list) is HTTPError or not len(self._list) > 0: raise SeriesNotFound for _entry in self._list: if _entry.country: if _entry.country.upper() == self.country: continue _entry.title = 'SKIP' else: self._list = searchShow(show=self.title, rtn=list) except: _an_error = traceback.format_exc() raise SeriesNotFound if type(self._list) is HTTPError or not len(self._list) > 0: raise SeriesNotFound _new_list = filter(_filter_options['match'], self._list) if len(_new_list) > 0: self._list = _new_list if type(self._list) is HTTPError: raise SeriesNotFound('SeasonNotFound: {}'.format(self.title)) elif rtn is list or len(self._list) < 2: pass else: for _filter in _filterOrder: try: _newlist = filter(_filter_options[_filter], self._list) if len(_newlist) == 1: self._list = _newlist break elif len(_newlist) == 0: if _filter in ['match', 'tz']: continue else: break else: self._list = _newlist except: _an_error = traceback.format_exc() #log.debug(traceback.format_exception_only(type(_an_error), _an_error)[-1]) continue if not matching(self.title, self._list[0].title, 70): raise SeriesNotFound('SeasonNotFound: {}'.format(self.title)) if hasattr(self, 'fileDetails'): for _entry in self._list: setattr(_entry, 'fileDetails', self.fileDetails) if _entry.titleTVDB: _entry.fileDetails.seriesTitle = _entry.titleTVDB else: _entry.fileDetails.seriesTitle = _entry.title if type(self._list) is HTTPError: raise elif len(self._list) == 0: raise SeriesNotFound('SeriesNotFound: {}'.format(self.title)) elif rtn is list: for _entry in self._list: delattr(_entry, 'score') return self._list elif rtn is object: _entry = self._list[0] delattr(_entry, 'score') return _entry
def trakt_info(self, title=None, year=None, country=None): from urllib2 import HTTPError _filterOrder = ['tz', 'status', 'rating', 'scores', 'newest'] _filter_options = { 'scores': self._flt_scores, 'tz': self._flt_tz, 'match': self._flt_match, 'rating': self._flt_rating, 'status': self._flt_status, 'newest': self._flt_newest } if self.trakt_id is not None: if None in [self.status]: try: _kwargs = getShow(show=self.trakt_id, rtn=str) except HTTPError: return self.load_attr(_kwargs) return try: if not title is None: self.title = title if self.year: self._list = searchShow(show=self.title, year=self.year, rtn=list) for _entry in self._list: if _entry.year == self.year: continue _entry.title = 'SKIP' self._list = filter(_filter_options['match'], self._list) if type(self._list) is HTTPError or not len(self._list) > 0: self._list = searchShow(show=self.title, rtn=list) elif self.country: self._list = searchShow(show=self.title, rtn=list) if type(self._list) is HTTPError or not len(self._list) > 0: raise SeriesNotFound for _entry in self._list: if _entry.country: if _entry.country.upper() == self.country: continue _entry.title = 'SKIP' else: self._list = searchShow(show=self.title, rtn=list) except: _an_error = traceback.format_exc() raise SeriesNotFound if type(self._list) is HTTPError or not len(self._list) > 0: raise SeriesNotFound _new_list = filter(_filter_options['match'], self._list) if len(_new_list) > 0: self._list = _new_list if type(self._list) is HTTPError: raise SeriesNotFound('SeasonNotFound: {}'.format(self.title)) elif rtn is list or len(self._list) < 2: pass else: for _filter in _filterOrder: try: _newlist = filter(_filter_options[_filter], self._list) if len(_newlist) == 1: self._list = _newlist break elif len(_newlist) == 0: if _filter in ['match', 'tz']: continue else: break else: self._list = _newlist except: _an_error = traceback.format_exc() #log.debug(traceback.format_exception_only(type(_an_error), _an_error)[-1]) continue if not matching(self.title, self._list[0].title, 70): raise SeriesNotFound('SeasonNotFound: {}'.format(self.title)) if hasattr(self, 'fileDetails'): for _entry in self._list: setattr(_entry, 'fileDetails', self.fileDetails) if _entry.titleTVDB: _entry.fileDetails.seriesTitle = _entry.titleTVDB else: _entry.fileDetails.seriesTitle = _entry.title if type(self._list) is HTTPError: raise elif len(self._list) == 0: raise SeriesNotFound('SeriesNotFound: {}'.format(self.title)) elif rtn is list: for _entry in self._list: delattr(_entry, 'score') return self._list elif rtn is object: _entry = self._list[0] delattr(_entry, 'score') return _entry