Example #1
0
def getShowid(ShowName, UseAddic):
    AddicId = ImdbId = TvdbId = AddicIdMapping = ImdbNameMappingId = TvdbShowName = AddicNameMappingId = None
    UpdateCache = False
    log.debug('getShowid: Trying to get info for %s' %ShowName)

    # First we try the User Namemapping and the System Namemapping
    if ShowName.upper() in autosub.USERNAMEMAPPINGUPPER.keys():
        ImdbNameMappingId = autosub.USERNAMEMAPPINGUPPER[ShowName.upper()]
        if ImdbNameMappingId:
             AddicId, TvdbId, TvdbShowName = idCache().getInfo(ImdbNameMappingId)
             if not TvdbShowName and checkAPICallsTvdb():
                TvdbShowName, TvdbId = Tvdb.getShowName(ImdbNameMappingId)
    elif ShowName.upper() in autosub.NAMEMAPPINGUPPER.keys():
        ImdbId = autosub.NAMEMAPPINGUPPER[ShowName.upper()]
        # If found, we try to add info from the cache
        if ImdbId:
            AddicId, TvdbId, TvdbShowName = idCache().getInfo(ImdbId)
            # No info in the cache we try Tvdb
            if not TvdbShowName and checkAPICallsTvdb():
                TvdbShowName, TvdbId = Tvdb.getShowName(ImdbId)
                if TvdbShowName:
                    UpdateCache = True

    # Namemapping prevails over the cache info

    if not (ImdbId or ImdbNameMappingId):
        ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(ShowName.upper())
            # still no ImdbId then we try Tvdb
        if not ImdbId and checkAPICallsTvdb():
            ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
        if ImdbId:
            #Found a ImdbId on Tvdb try the cache for the other info.
            AddicId,CacheTvdbId, CacheName = idCache().getInfo(ImdbId)
            if not CacheName:
                UpdateCache = True
        else:
            log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
            return None, None, None, ShowName

    if UseAddic and not AddicId:
        if ImdbNameMappingId:
            AddicNameMappingId = Addic7edMapping(ImdbNameMappingId)
        else:
            AddicNameMappingId = Addic7edMapping(ImdbId)
        if AddicNameMappingId:
            log.debug('getShowid: Addic7ed ID found in Namemapping: %s' %AddicNameMappingId)
        else:
            #Try to find the Addice7ed Id on the show page of the Addic7ed website
            AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            if AddicId:
                log.debug('getShowid: Addic7ed ID found on Website: %s' %AddicId)
                UpdateCache = True

    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if AddicNameMappingId: AddicId = AddicNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
def getShowid(ShowName):
    ImdbId = AddicId = AddicUserId= TvdbId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList =[]
    if Suffix:
        SearchList.append(SearchName +  ' (' + Suffix +')' )
        SearchList.append(SearchName +  ' ' + Suffix )
    SearchList.append(SearchName)
    log.debug('getShowid: Trying to get info for %s' %ShowName)
    for Name in SearchList:
        # First we try the User Namemapping
        if Name.upper() in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId,TvdbShowName = autosub.NAMEMAPPING[Name.upper()]
            if ImdbNameMappingId:
                # Now look for info in the cache
                AddicId, TvdbId, TvdbCacheName = idCache().getInfo(ImdbNameMappingId)
                # no Tvdb name, then it is a user mappen and we missing the formal tvdb name
                if not TvdbShowName:
                    # if name in cache we add to the user mapping
                    if TvdbCacheName:
                        TvdbShowName = TvdbCacheName
                    elif checkAPICallsTvdb():
                        # still no tvdb name we fetch it form the tvdb website
                        TvdbShowName,TvdbId = Tvdb.getShowName(ImdbNameMappingId)
                        if TvdbShowName:
                            autosub.NAMEMAPPING[Name.upper()][1] = TvdbShowName
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(Name.upper())
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(Name)  
                if ImdbId:
                    UpdateCache = True
        if (ImdbNameMappingId or ImdbId):
            if not AddicId:
                Id = ImdbNameMappingId if ImdbNameMappingId else ImdbId
                if Id:
                    if Id in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[Id]
                    elif Id in autosub.USERADDIC7EDMAPPING.keys():
                        AddicUserId = autosub.USERADDIC7EDMAPPING[Id]
                    elif autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(ShowName, TvdbShowName)
                        if AddicId and ImdbId:
                            UpdateCache = True
            break
    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    if AddicUserId: AddicId = AddicUserId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName
def getShowid(ShowName, UseAddic, UseOs):
    AddicId = ImdbId = OsId = AddicIdMapping = None
    UpdateCache = False
    log.debug("getShowid: Trying to get IMDB, Addic7ed and OpenSubtitles ID for %s" % ShowName)

    # First we try the cache
    ImdbId, AddicId, OsId = idCache().getId(ShowName)
    if ImdbId:
        TvdbShowName = ShowName
    else:
        # Now we try Tvdb
        log.debug("getShowid: Trying TvdbID to find info")
        ImdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
        if ImdbId:
            UpdateCache = True
        else:
            # Last resort the name mapping from the config page
            ImdbNameMappingId = nameMapping(ShowName)
            if ImdbNameMappingId:
                # Check whether the Namemapping is an existing Imdb Id and if so find the official showname
                TvdbShowName = Tvdb.getShowName(ImdbNameMappingId)
                if TvdbShowName:
                    ImdbId = ImdbNameMappingId
                    UpdateCache = True
            else:
                return None, None, None

    if UseAddic and not AddicId:
        # Try to find the Addice7ed Id on the show page of the Addic7ed website
        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
        if AddicId:
            log.debug("getShowid: Addic7ed ID found on website: %s" % AddicId)
            UpdateCache = True
        else:
            # Try the Addic7ed ID mapping from the config
            AddicIdMapping = Addic7edMapping(ImdbId)
            # if Addic7edIdMapping:
            #    Addic7edId = Addic7edIdMapping

    if UseOs and not OsId:
        # Try to find the OpenSubtitles ID on the OpenSubtitles website
        OsId = GetOpensubtitlesId(ImdbId, TvdbShowName)
        if OsId:
            UpdateCache = True

    if UpdateCache:
        idCache().setId(ImdbId, AddicId, OsId, TvdbShowName)
    AddicId = AddicIdMapping if AddicIdMapping else AddicId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, OpenSubtitles: %s" % (ImdbId, AddicId, OsId))
    return ImdbId, AddicId, OsId
Example #4
0
def getShowid(ShowName, UseAddic, UseOs):
    if not ShowName:
        return None,None,None
    AddicId = ImdbId = OsId = AddicIdMapping = None
    UpdateCache = False
    log.debug('getShowid: Trying to get IMDB, Addic7ed and OpenSubtitles ID for %s' %ShowName)

    ImdbNameMappingId = nameMapping(ShowName)
    if ImdbNameMappingId:
        # Check whether the Namemapping is an existing Imdb Id and if so find the official showname
        TvdbShowName = Tvdb.getShowName(ImdbNameMappingId)
        if TvdbShowName:
            ImdbId = ImdbNameMappingId
            UpdateCache = True
    else:
        # No mapping we try the cache
        ImdbId, AddicId, OsId = idCache().getId(ShowName)
        if ImdbId:
            TvdbShowName = ShowName
        else:
            # No chache hit we try the Tvdb website
            log.debug('getShowid: Trying TvdbID to find info')
            ImdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
            if ImdbId and TvdbShowName:
                UpdateCache = True

    if UseAddic and not AddicId:
        #First we try the namemapping from the config
        AddicIdMapping = Addic7edMapping(ImdbId)
        if not AddicIdMapping:
            #No mapping en no cache hit then try to find the Addice7ed Id on the show page of the Addic7ed website
            AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            if AddicId:
                UpdateCache = True

    if UseOs and not OsId:
        #Try to find the OpenSubtitles ID on the OpenSubtitles website
        OsId = GetOpensubtitlesId(ImdbId,TvdbShowName)
        if OsId:
            UpdateCache = True

    if UpdateCache and ImdbId and TvdbShowName:
        idCache().setId(ImdbId, AddicId, OsId, TvdbShowName)
    AddicId = AddicIdMapping    if AddicIdMapping    else AddicId
    ImdbId  = ImdbNameMappingId if ImdbNameMappingId else ImdbId
    log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, OpenSubtitles: %s" %(ImdbId,AddicId,OsId))
    return ImdbId, AddicId, OsId
def getShowid(ShowName):
    ImdbId = AddicId = TvdbId = AddicMappingId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList =[]
    if Suffix:
        SearchList.append(SearchName +  ' (' + Suffix +')' )
        SearchList.append(SearchName +  ' ' + Suffix )
    SearchList.append(SearchName)
    for ShowName in SearchList:
        ShowNameUpper = ShowName.upper()
        log.debug('getShowid: Trying to get info for %s' %ShowName)

        # First we try the User Namemapping
        if ShowNameUpper in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId = autosub.NAMEMAPPING[ShowNameUpper]
            if ImdbNameMappingId:
                # Try to find the addicId in the cache
                if ImdbNameMappingId in autosub.ADDIC7EDMAPPING.keys():
                    AddicMappingId = autosub.ADDIC7EDMAPPING[ImdbNameMappingId]
                if not AddicMappingId:
                    ImdbId, AddicMappingId, TvdbId, TvdbShowName = idCache().getId(ShowNameUpper)
                    if not AddicMappingId and autosub.ADDIC7EDLOGGED_IN:
                        AddicMappingId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(ShowNameUpper)
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(ShowName)
                if ImdbId:
                    UpdateCache = True
                    if ImdbId in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[ImdbId]
                    if not AddicId and autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
            else:
                if not AddicId:           
                    if ImdbId in autosub.ADDIC7EDMAPPING.keys():
                        AddicMappingId = autosub.ADDIC7EDMAPPING[ImdbId]
                    if not AddicMappingId and autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(TvdbShowName, ShowName)
                        UpdateCache = True
        if ImdbId or ImdbNameMappingId:
            if UpdateCache:
                idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId, TvdbShowName)
            if ImdbNameMappingId: ImdbId = ImdbNameMappingId
            if AddicMappingId: AddicId = AddicMappingId
            if not TvdbShowName: TvdbShowName = ShowName
            log.debug("getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %(ImdbId,AddicId,TvdbShowName))
            return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName
def getShowid(ShowName):
    ImdbId = AddicId = AddicUserId = TvdbId = ImdbNameMappingId = TvdbShowName = None
    UpdateCache = False
    SearchName, Suffix = _getShow(ShowName)
    SearchList = []
    if Suffix:
        SearchList.append(SearchName + ' (' + Suffix + ')')
        SearchList.append(SearchName + ' ' + Suffix)
    SearchList.append(SearchName)
    log.debug('getShowid: Trying to get info for %s' % ShowName)
    for Name in SearchList:
        # First we try the User Namemapping
        if Name.upper() in autosub.NAMEMAPPING.keys():
            ImdbNameMappingId, TvdbShowName = autosub.NAMEMAPPING[Name.upper()]
            if ImdbNameMappingId:
                # Now look for info in the cache
                AddicId, TvdbId, TvdbCacheName = idCache().getInfo(
                    ImdbNameMappingId)
                # no Tvdb name, then it is a user mappen and we missing the formal tvdb name
                if not TvdbShowName:
                    # if name in cache we add to the user mapping
                    if TvdbCacheName:
                        TvdbShowName = TvdbCacheName
                    elif checkAPICallsTvdb():
                        # still no tvdb name we fetch it form the tvdb website
                        TvdbShowName, TvdbId = Tvdb.getShowName(
                            ImdbNameMappingId)
                        if TvdbShowName:
                            autosub.NAMEMAPPING[Name.upper()][1] = TvdbShowName
        else:
            # Not found in NameMapping so check the cache
            ImdbId, AddicId, TvdbId, TvdbShowName = idCache().getId(
                Name.upper())
            # No info in the cache we try Tvdb
            if not ImdbId and checkAPICallsTvdb():
                ImdbId, TvdbId, TvdbShowName = Tvdb.getShowidApi(Name)
                if ImdbId:
                    UpdateCache = True
        if (ImdbNameMappingId or ImdbId):
            if not AddicId:
                Id = ImdbNameMappingId if ImdbNameMappingId else ImdbId
                if Id:
                    if Id in autosub.ADDIC7EDMAPPING.keys():
                        AddicId = autosub.ADDIC7EDMAPPING[Id]
                    elif Id in autosub.USERADDIC7EDMAPPING.keys():
                        AddicUserId = autosub.USERADDIC7EDMAPPING[Id]
                    elif autosub.ADDIC7EDLOGGED_IN:
                        AddicId = Addic7edAPI().geta7ID(ShowName, TvdbShowName)
                        if AddicId and ImdbId:
                            UpdateCache = True
            break
    if UpdateCache:
        idCache().setId(TvdbShowName.upper(), ImdbId, AddicId, TvdbId,
                        TvdbShowName)
    if ImdbNameMappingId: ImdbId = ImdbNameMappingId
    if not TvdbShowName: TvdbShowName = ShowName
    if AddicUserId: AddicId = AddicUserId
    log.debug(
        "getShowid: Returned ID's - IMDB: %s, Addic7ed: %s, ShowName: %s" %
        (ImdbId, AddicId, TvdbShowName))
    return ImdbId, AddicId, TvdbId, TvdbShowName
    # no ImdbId found for this showname
    log.debug('getShowid: No ImdbId found on Tvdb for %s.' % ShowName)
    return None, None, None, ShowName