コード例 #1
0
def getTVDBIDFromNFO(dir):

    show_lang = None

    if not ek.ek(os.path.isdir, dir):
        logger.log(u"Show dir doesn't exist, can't load NFO")
        raise exceptions.NoNFOException(
            "The show dir doesn't exist, no NFO could be loaded")

    logger.log(u"Loading show info from NFO")

    xmlFile = ek.ek(os.path.join, dir, "tvshow.nfo")

    try:
        xmlFileObj = ek.ek(open, xmlFile, 'r')
        showXML = etree.ElementTree(file=xmlFileObj)

        if showXML.findtext('title') == None or (
                showXML.findtext('tvdbid') == None
                and showXML.findtext('id') == None):
            raise exceptions.NoNFOException("Invalid info in tvshow.nfo (missing name or id):" \
                + str(showXML.findtext('title')) + " " \
                + str(showXML.findtext('tvdbid')) + " " \
                + str(showXML.findtext('id')))

        name = showXML.findtext('title')
        if showXML.findtext('tvdbid') != None:
            tvdb_id = int(showXML.findtext('tvdbid'))
        elif showXML.findtext('id'):
            tvdb_id = int(showXML.findtext('id'))
        else:
            raise exceptions.NoNFOException(
                "Empty <id> or <tvdbid> field in NFO")

        try:
            t = tvdb_api.Tvdb(search_all_languages=True,
                              **sickbeard.TVDB_API_PARMS)
            s = t[int(tvdb_id)]
            if not s or not s['seriesname']:
                raise exceptions.NoNFOException(
                    "Show has no name on TVDB, probably the wrong language")
        except tvdb_exceptions.tvdb_exception, e:
            raise exceptions.NoNFOException(
                "Unable to look up the show on TVDB, not using the NFO")

    except (exceptions.NoNFOException, SyntaxError, ValueError), e:
        logger.log(
            u"There was an error parsing your existing tvshow.nfo file: " +
            str(e), logger.ERROR)
        logger.log(u"Attempting to rename it to tvshow.nfo.old", logger.DEBUG)

        try:
            xmlFileObj.close()
            ek.ek(os.rename, xmlFile, xmlFile + ".old")
        except Exception, e:
            logger.log(
                u"Failed to rename your tvshow.nfo file - you need to delete it or fix it: "
                + str(e), logger.ERROR)
コード例 #2
0
            s = t[int(tvdb_id)]
            if not s  or not s['seriesname']:
                raise exceptions.NoNFOException("Show has no name on TVDB, probably the wrong language")
        except tvdb_exceptions.tvdb_exception, e:
            raise exceptions.NoNFOException("Unable to look up the show on TVDB, not using the NFO")

    except (exceptions.NoNFOException, SyntaxError, ValueError), e:
        logger.log(u"There was an error parsing your existing tvshow.nfo file: " + ex(e), logger.ERROR)
        logger.log(u"Attempting to rename it to tvshow.nfo.old", logger.DEBUG)

        try:
            xmlFileObj.close()
            ek.ek(os.rename, xmlFile, xmlFile + ".old")
        except Exception, e:
            logger.log(u"Failed to rename your tvshow.nfo file - you need to delete it or fix it: " + ex(e), logger.ERROR)
        raise exceptions.NoNFOException("Invalid info in tvshow.nfo")

    return tvdb_id

def getShowImage(url, imgNum=None):

    image_data = None

    if url == None:
        return None

    # if they provided a fanart number try to use it instead
    if imgNum != None:
        tempURL = url.split('-')[0] + "-" + str(imgNum) + ".jpg"
    else:
        tempURL = url