Beispiel #1
0
    def __init__(self, show):

        self.show = show

        self.lastEpInfo = None
        self.nextEpInfo = None

        self._tvrid = 0
        self._tvrname = None

        if self.show.tvrid == 0:

            # if it's the right show then use the tvrage ID that the last lookup found (cached in self._trvid)
            show_is_right = self.confirmShow() or self.checkSync()

            if not show_is_right:
                raise exceptions.TVRageException("Shows aren't the same, aborting")

            if self._tvrid == 0 or self._tvrname == None:
                raise exceptions.TVRageException("We confirmed sync but got invalid data (no ID/name)")

            if show_is_right:

                logger.log(u"Setting TVRage ID for "+show.name+" to "+str(self._tvrid))
                self.show.tvrid = self._tvrid
                self.show.saveToDB()

        if not self.show.tvrname:

            if self._tvrname == None:
                self._getTVRageInfo()

            logger.log(u"Setting TVRage Show Name for "+show.name+" to "+self._tvrname)
            self.show.tvrname = self._tvrname
            self.show.saveToDB()
Beispiel #2
0
    def findLatestEp(self):

        # will use tvrage name if it got set in the constructor, or tvdb name if not
        info = self._getTVRageInfo(full=True)

        if not self.checkSync(info):
            raise exceptions.TVRageException("TVRage info isn't in sync with TVDB, not using data")

        myDB = db.DBConnection()

        # double check that it's not already in there
        sqlResults = myDB.select("SELECT * FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ?", [self.show.tvdbid, self.nextEpInfo['season'], self.nextEpInfo['episode']])

        if len(sqlResults) > 0:
            raise exceptions.TVRageException("Show is already in database, not adding the TVRage info")

        # insert it
        myDB.action("INSERT INTO tv_episodes (showid, tvdbid, name, season, episode, description, airdate, hasnfo, hastbn, status, location) VALUES (?,?,?,?,?,?,?,?,?,?,?)", \
                    [self.show.tvdbid, -1, self.nextEpInfo['name'], self.nextEpInfo['season'], self.nextEpInfo['episode'], '', self.nextEpInfo['airdate'].toordinal(), 0, 0, UNAIRED, ''])

        # once it's in the DB make an object and return it
        ep = None

        try:
            ep = self.show.getEpisode(self.nextEpInfo['season'], self.nextEpInfo['episode'])
        except exceptions.SickBeardException, e:
            logger.log(u"Unable to create episode from tvrage (could be for a variety of reasons): " + e.message.decode(sickbeard.SYS_ENCODING))
Beispiel #3
0
    def _saveLatestInfo(self, info=None):

        if info == None:
            info = self._getTVRageInfo()

        if not info.has_key('Next Episode') or not info.has_key('Latest Episode'):
            raise exceptions.TVRageException("TVRage doesn't have all the required info for this show")

        self.lastEpInfo = self._getEpInfo(info['Latest Episode'])
        self.nextEpInfo = self._getEpInfo(info['Next Episode'])

        if self.lastEpInfo == None or self.nextEpInfo == None:
            raise exceptions.TVRageException("TVRage has malformed data, unable to update the show")
Beispiel #4
0
    def _getTVRageInfo(self, season=None, episode=None, full=False):

        url = "http://services.tvrage.com/tools/quickinfo.php?"

        # if we need full info OR if we don't have a tvrage id, use show name
        if full == True or self.show.tvrid == 0:
            if self.show.tvrname != "" and self.show.tvrname != None:
                showName = self.show.tvrname
            else:
                showName = self.show.name

            urlData = {'show': showName.encode('utf-8')}

        # if we don't need full info and we have a tvrage id, use it
        else:
            urlData = {'sid': self.show.tvrid}

        if season != None and episode != None:
            urlData['ep'] = str(season)+'x'+str(episode)

        # build the URL
        url += urllib.urlencode(urlData)

        logger.log(u"Loading TVRage info from URL: " + url, logger.DEBUG)

        try:
            result = helpers.getURL(url).decode('utf-8')
        except (urllib2.HTTPError, IOError), e:
            logger.log(u"Unable to load TVRage info: " + e.message.decode(sickbeard.SYS_ENCODING))
            raise exceptions.TVRageException("urlopen call to " + url + " failed")
Beispiel #5
0
    def _getTVRageInfo(self, season=None, episode=None, full=False):

        url = "http://services.tvrage.com/tools/quickinfo.php?"

        # if we need full info OR if we don't have a tvrage id, use show name
        if full == True or self.show.tvrid == 0:
            if self.show.tvrname != "" and self.show.tvrname != None:
                showName = self.show.tvrname
            else:
                showName = self.show.name

            urlData = {'show': showName.encode('utf-8')}

        # if we don't need full info and we have a tvrage id, use it
        else:
            urlData = {'sid': self.show.tvrid}

        if season != None and episode != None:
            urlData['ep'] = str(season) + 'x' + str(episode)

        # build the URL
        url += urllib.urlencode(urlData)

        logger.log(u"Loading TVRage info from URL: " + url, logger.DEBUG)
        result = helpers.getURL(url)

        if result is None:
            raise exceptions.TVRageException("urlopen call to " + url +
                                             " failed")
        else:
            result = result.decode('utf-8')

        urlData = result.splitlines()
        info = {}

        for x in urlData:
            if x.startswith("No Show Results Were Found"):
                logger.log(u"TVRage returned: " + x.encode('utf-8'),
                           logger.WARNING)
                return info

            if "@" in x:
                key, value = x.split("@")
                if key:
                    key = key.replace('<pre>', '')
                    info[key] = value.strip()
            else:
                logger.log(u"TVRage returned: " + x.encode('utf-8'),
                           logger.WARNING)
                return info

        # save it for later in case somebody is curious
        if 'Show ID' in info:
            self._tvrid = info['Show ID']

        if 'Show Name' in info:
            self._tvrname = info['Show Name']

        return info
Beispiel #6
0
    def _getTVRageInfo(self, season=None, episode=None, full=False):

        url = "http://services.tvrage.com/tools/quickinfo.php?"

        if full or self.show.tvrid == 0:
            # for some reason, the previous code here forced the use of the tvrage slug
            # rather than the tvrage_id when 'full' was True.  I expect there was a
            # reason for this, so best to do the same.
            if self.show.tvrname != "" and self.show.tvrname != None:
                showName = self.show.tvrname
            else:
                showName = self.show.name
            urlData = {'show': showName.encode('utf-8')}

            if not full:  # as per above, only use tvtumbler if not 'full'
                tvtumb = tvtumbler.show_info(self.show.tvdbid)
                if tvtumb and 'tvrage_id' in tvtumb and tvtumb['tvrage_id']:
                    urlData = {'sid': tvtumb['tvrage_id']}

        # if we don't need full info and we have a tvrage id, use it
        else:
            urlData = {'sid': self.show.tvrid}

        if season != None and episode != None:
            urlData['ep'] = str(season) + 'x' + str(episode)

        # build the URL
        url += urllib.urlencode(urlData)

        logger.log(u"Loading TVRage info from URL: " + url, logger.DEBUG)
        result = helpers.getURL(url)

        if result is None:
            raise exceptions.TVRageException("urlopen call to " + url +
                                             " failed")
        else:
            result = result.decode('utf-8')

        urlData = result.splitlines()

        info = {}

        for x in urlData:
            if x.startswith("No Show Results Were Found"):
                logger.log(x.encode('utf-8'), logger.WARNING)
                return info
            key, value = x.split("@")
            key = key.replace('<pre>', '')
            info[key] = value.strip()

        # save it for later in case somebody is curious
        if info.has_key('Show ID'):
            self._tvrid = info['Show ID']

        if info.has_key('Show Name'):
            self._tvrname = info['Show Name']

        return info