def _get_ep_obj(self, show, season, episodes): """ Retrieve the TVEpisode object requested. show: The show object belonging to the show we want to process season: The season of the episode (int) episodes: A list of episodes to find (list of ints) If the episode(s) can be found then a TVEpisode object with the correct related eps will be instantiated and returned. If the episode can't be found then None will be returned. """ root_ep = None for cur_episode in episodes: self._log( u"Retrieving episode object for " + str(season) + "x" + str(cur_episode), logger.DEBUG) # now that we've figured out which episode this file is just load it manually try: curEp = show.getEpisode(season, cur_episode) if not curEp: raise exceptions.EpisodeNotFoundException() except exceptions.EpisodeNotFoundException, e: self._log(u"Unable to create episode: " + ex(e), logger.DEBUG) raise exceptions.PostProcessingFailed() # associate all the episodes together under a single root episode if root_ep == None: root_ep = curEp root_ep.relatedEps = [] elif curEp not in root_ep.relatedEps: root_ep.relatedEps.append(curEp)
def checkSync(self, info=None): logger.log(u"Checking the last aired episode to see if the dates match between TVDB and TVRage") if self.lastEpInfo == None or self.nextEpInfo == None: self._saveLatestInfo(info) if self.nextEpInfo['season'] == 0 or self.nextEpInfo['episode'] == 0: return None try: airdate = None tvdb_lang = self.show.lang # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy() if tvdb_lang and not tvdb_lang == 'en': ltvdb_api_parms['language'] = tvdb_lang # make sure the last TVDB episode matches our last episode try: t = tvdb_api.Tvdb(**ltvdb_api_parms) ep = t[self.show.tvdbid][self.lastEpInfo['season']][self.lastEpInfo['episode']] if ep["firstaired"] == "" or ep["firstaired"] == None: return None rawAirdate = [int(x) for x in ep["firstaired"].split("-")] airdate = datetime.date(rawAirdate[0], rawAirdate[1], rawAirdate[2]) except tvdb_exceptions.tvdb_exception, e: logger.log(u"Unable to check TVRage info against TVDB: "+ex(e)) logger.log(u"Trying against DB instead", logger.DEBUG) myDB = db.DBConnection() sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? and episode = ?", [self.show.tvdbid, self.lastEpInfo['season'], self.lastEpInfo['episode']]) if len(sqlResults) == 0: raise exceptions.EpisodeNotFoundException("Unable to find episode in DB") else: airdate = datetime.date.fromordinal(int(sqlResults[0]["airdate"])) logger.log(u"Date from TVDB for episode " + str(self.lastEpInfo['season']) + "x" + str(self.lastEpInfo['episode']) + ": " + str(airdate), logger.DEBUG) logger.log(u"Date from TVRage for episode " + str(self.lastEpInfo['season']) + "x" + str(self.lastEpInfo['episode']) + ": " + str(self.lastEpInfo['airdate']), logger.DEBUG) if self.lastEpInfo['airdate'] == airdate: return True
def confirmShow(self, force=False): if self.show.tvrid != 0 and not force: logger.log(u"We already have a TVRage ID, skipping confirmation", logger.DEBUG) return True logger.log( u"Checking the first episode of each season to see if the air dates match between TVDB and TVRage" ) tvdb_lang = self.show.lang try: try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere ltvdb_api_parms = sickbeard.TVDB_API_PARMS.copy() if tvdb_lang and not tvdb_lang == 'en': ltvdb_api_parms['language'] = tvdb_lang t = tvdb_api.Tvdb(**ltvdb_api_parms) except tvdb_exceptions.tvdb_exception, e: logger.log( u"Currently this doesn't work with TVDB down but with some DB magic it can be added", logger.DEBUG) return None # check the first episode of every season for curSeason in t[self.show.tvdbid]: logger.log( u"Checking TVDB and TVRage sync for season " + str(curSeason), logger.DEBUG) airdate = None try: # don't do specials and don't do seasons with no episode 1 if curSeason == 0 or 1 not in t[self.show.tvdbid]: continue # get the episode info from TVDB ep = t[self.show.tvdbid][curSeason][1] # make sure we have a date to compare with if ep["firstaired"] == "" or ep["firstaired"] == None or ep[ "firstaired"] == "0000-00-00": continue # get a datetime object rawAirdate = [int(x) for x in ep["firstaired"].split("-")] airdate = datetime.date(rawAirdate[0], rawAirdate[1], rawAirdate[2]) # get the episode info from TVRage info = self._getTVRageInfo(curSeason, 1) # make sure we have enough info if info == None or not info.has_key('Episode Info'): logger.log( u"TVRage doesn't have the episode info, skipping it", logger.DEBUG) continue # parse the episode info curEpInfo = self._getEpInfo(info['Episode Info']) # make sure we got some info back if curEpInfo == None: continue # if we couldn't compare with TVDB try comparing it with the local database except tvdb_exceptions.tvdb_exception, e: logger.log(u"Unable to check TVRage info against TVDB: " + ex(e)) logger.log(u"Trying against DB instead", logger.DEBUG) myDB = db.DBConnection() sqlResults = myDB.select( "SELECT * FROM tv_episodes WHERE showid = ? AND season = ? and episode = ?", [ self.show.tvdbid, self.lastEpInfo['season'], self.lastEpInfo['episode'] ]) if len(sqlResults) == 0: raise exceptions.EpisodeNotFoundException( "Unable to find episode in DB") else: airdate = datetime.date.fromordinal( int(sqlResults[0]["airdate"])) # check if TVRage and TVDB have the same airdate for this episode if curEpInfo['airdate'] == airdate: logger.log( u"Successful match for TVRage and TVDB data for episode " + str(curSeason) + "x1)", logger.DEBUG) return True logger.log( u"Date from TVDB for episode " + str(curSeason) + "x1: " + str(airdate), logger.DEBUG) logger.log( u"Date from TVRage for episode " + str(curSeason) + "x1: " + str(curEpInfo['airdate']), logger.DEBUG)