Пример #1
0
def _tryFromCache(fromType, toType, id):
    #Return a tuple of a boolean which indicates if a cache entry was found and the cache entry or None
    #This way we will know if a cache entry exists or the cached value is None
    try:
        if fromType == "tvrage":
            id = TvIdCache.get(TvIdCache.tvrage == id)
        elif fromType == "tvdb":
            id = TvIdCache.get(TvIdCache.tvdb == id)
        elif fromType == "tvmaze":
            id = TvIdCache.get(TvIdCache.tvmaze == id)
        elif fromType == "imdb":
            id = MovieIdCache.get(MovieIdCache.imdb == id)
        elif fromType == "tmdb":
            id = MovieIdCache.get(MovieIdCache.tmdb == id)
        else:
            return False, None
    except (TvIdCache.DoesNotExist, MovieIdCache.DoesNotExist):
        return False, None
    if toType == "tvdb":
        return True, id.tvdb
    elif toType == "tvrage":
        return True, id.tvrage
    elif toType == "tvmaze":
        return True, id.tvmaze
    elif toType == "imdb":
        return True, id.imdb
    elif toType == "tmdb":
        return True, id.tmdb
    else:
        return False, None
Пример #2
0
def _tryFromCache(fromType, toType, id):
    #Return a tuple of a boolean which indicates if a cache entry was found and the cache entry or None
    #This way we will know if a cache entry exists or the cached value is None 
    try:
        if fromType == "tvrage":
            id = TvIdCache.get(TvIdCache.tvrage == id)
        elif fromType == "tvdb":
            id = TvIdCache.get(TvIdCache.tvdb == id)
        elif fromType == "tvmaze":
            id = TvIdCache.get(TvIdCache.tvmaze == id)
        elif fromType == "imdb":
            id = MovieIdCache.get(MovieIdCache.imdb == id)
        elif fromType == "tmdb":
            id = MovieIdCache.get(MovieIdCache.tmdb == id)
        else:
            return False, None
    except (TvIdCache.DoesNotExist, MovieIdCache.DoesNotExist):
        return False, None
    if toType == "tvdb":
        return True, id.tvdb
    elif toType == "tvrage":
        return True, id.tvrage
    elif toType == "tvmaze":
        return True, id.tvmaze
    elif toType == "imdb":
        return True, id.imdb
    elif toType == "tmdb":
        return True, id.tmdb
    else:
        return False, None
Пример #3
0
    def testConvertMovie(self):
        MovieIdCache.delete().execute()
        id = infos.convertId("imdb", "tmdb", "0169547")
        self.assertEqual("14", id)
        #This time from cache
        id = infos.convertId("imdb", "tmdb", "0169547")
        self.assertEqual("14", id)

        MovieIdCache.delete().execute()
        id = infos.convertId("tmdb", "imdb", "14")
        self.assertEqual("0169547", id)
Пример #4
0
 def testConvertMovie(self):
     MovieIdCache.delete().execute()
     id = infos.convertId("imdb", "tmdb", "0169547")
     self.assertEqual("14", id)
     #This time from cache
     id = infos.convertId("imdb", "tmdb", "0169547")
     self.assertEqual("14", id)
     
     MovieIdCache.delete().execute()
     id = infos.convertId("tmdb", "imdb", "14")
     self.assertEqual("0169547", id)
Пример #5
0
    def testGetMovieTitle(self):
        MovieIdCache.delete().execute()
        title = infos.convertId("imdb", "title", "0169547")
        self.assertEqual("American Beauty", title)
        # This time from cache
        title = infos.convertId("imdb", "title", "0169547")
        self.assertEqual("American Beauty", title)

        MovieIdCache.delete().execute()
        title = infos.convertId("tmdb", "title", "14")
        self.assertEqual("American Beauty", title)
        # This time from cache
        title = infos.convertId("tmdb", "title", "14")
        self.assertEqual("American Beauty", title)
Пример #6
0
    def testGetMovieTitle(self):
        MovieIdCache.delete().execute()
        title = infos.convertId("imdb", "title", "0169547")
        self.assertEqual("American Beauty", title)
        # This time from cache
        title = infos.convertId("imdb", "title", "0169547")
        self.assertEqual("American Beauty", title)

        MovieIdCache.delete().execute()
        title = infos.convertId("tmdb", "title", "14")
        self.assertEqual("American Beauty", title)
        # This time from cache
        title = infos.convertId("tmdb", "title", "14")
        self.assertEqual("American Beauty", title)
Пример #7
0
def convertId(fromType, toType, id):
    logger.info("Converting %s value %s from %s " % (toType, id, fromType))
    #Clean up names
    fromType = fromType.replace("rid", "tvrage").replace("id", "")
    toType = toType.replace("rid", "tvrage").replace("id", "")

    if fromType.replace("rid", "tvrage").replace("id", "") == toType.replace(
            "rid", "tvrage").replace("id", ""):
        return id

    if not canConvertId(fromType, toType):
        logger.error("Unable to convert from %s to %s" % (fromType, toType))
        return None

    hasCacheEntry, fromCache = _tryFromCache(fromType, toType, id)
    if hasCacheEntry:
        logger.debug("Returning %s value %s from %s from cache" %
                     (toType, id, fromType))
        return fromCache

    if fromType == "imdb":
        result = imdbid_to_tmdbid(id)
        MovieIdCache(tmdb=result, imdb=id).save()
        return result

    if fromType == "tmdb":
        result = tmdbid_to_imdbid(id)
        MovieIdCache(imdb=result, tmdb=id).save()
        return result

    if fromType in ("tvrage", "tvdb", "tvmaze"):
        fromType = fromType.replace("tvdb",
                                    "thetvdb")  #TVMaze uses "thetvdb"...
        result = TvMaze.byId(fromType, id)
        if result is None:
            return None
        _cacheTvMazeIds(result)
        if toType == "tvdb":
            return str(result.tvdbid)
        if toType == "tvmaze":
            return str(result.tvmazeid)
        if toType == "tvrage":
            return str(result.rageid)

    return None
Пример #8
0
def convertId(fromType, toType, id):
    logger.info("Converting from %s value %s to %s " % (fromType, id, toType))
    #Clean up names
    fromType = fromType.replace("rid", "tvrage").replace("id", "")
    toType = toType.replace("rid", "tvrage").replace("id", "")
    if fromType.replace("rid", "tvrage").replace("id", "") == toType.replace(
            "rid", "tvrage").replace("id", ""):
        return id

    if toType != "title" and not canConvertId(fromType, toType):
        logger.error("Unable to convert from %s to %s" % (fromType, toType))
        return None

    hasCacheEntry, result = _tryFromCache(fromType, toType, id)
    if hasCacheEntry:
        logger.debug("Found conversion from %s value %s to %s in cache" %
                     (fromType, id, toType))

    elif fromType == "imdb":
        convertedId, title = imdbid_to_tmdbid(id)
        if convertedId is None:
            return None
        result = MovieIdCache(tmdb=convertedId, imdb=id, title=title)
        result.save()

    elif fromType == "tmdb":
        convertedId, title = tmdbid_to_imdbid(id)
        if convertedId is None:
            return None
        result = MovieIdCache(imdb=convertedId, tmdb=id, title=title)
        result.save()

    elif fromType in ("tvrage", "tvdb", "tvmaze"):
        fromType = fromType.replace("tvdb",
                                    "thetvdb")  #TVMaze uses "thetvdb"...
        result = TvMaze.byId(fromType, id)
        if result is None:
            return None
        result = _cacheTvMazeIds(result)

    if result is None:
        return None
    wantedType = getattr(result, toType)
    if wantedType is None:
        return None

    logger.info("Successfully converted from %s value %s to %s " %
                (fromType, id, toType))
    if isinstance(wantedType, int):
        return str(wantedType)
    return wantedType
Пример #9
0
def convertId(fromType, toType, id):
    logger.info("Converting from %s value %s to %s " % (fromType, id, toType))
    #Clean up names
    fromType = fromType.replace("rid", "tvrage").replace("id", "")
    toType = toType.replace("rid", "tvrage").replace("id", "")
    if fromType.replace("rid", "tvrage").replace("id", "") == toType.replace("rid", "tvrage").replace("id", ""):
        return id
    
    if toType != "title" and not canConvertId(fromType, toType):
        logger.error("Unable to convert from %s to %s" % (fromType, toType))
        return None
    
    hasCacheEntry, result = _tryFromCache(fromType, toType, id)
    if hasCacheEntry:
        logger.debug("Found conversion from %s value %s to %s in cache" % (fromType, id, toType))
    
    elif fromType == "imdb":
        convertedId, title = imdbid_to_tmdbid(id)
        if convertedId is None:
            return None
        result = MovieIdCache(tmdb=convertedId, imdb=id, title=title) 
        result.save()
        
    elif fromType == "tmdb":
        convertedId, title = tmdbid_to_imdbid(id)
        if convertedId is None:
            return None
        result = MovieIdCache(imdb=convertedId, tmdb=id, title=title)
        result.save()
    
    elif fromType in ("tvrage", "tvdb", "tvmaze"):
        fromType = fromType.replace("tvdb", "thetvdb") #TVMaze uses "thetvdb"...
        result = TvMaze.byId(fromType, id)
        if result is None:
            return None
        result = _cacheTvMazeIds(result)

    if result is None:
        return None
    wantedType = getattr(result, toType)
    if wantedType is None:
        return None
    
    logger.info("Successfully converted from %s value %s to %s " % (fromType, id, toType))
    if isinstance(wantedType, int):
        return str(wantedType)
    return wantedType
Пример #10
0
 def testGetMovieTitleDoesNotExist(self):
     MovieIdCache.delete().execute()
     title = infos.convertId("imdb", "title", "016954739339")
     self.assertIsNone(title)
Пример #11
0
 def testGetMovieTitleDoesNotExist(self):
     MovieIdCache.delete().execute()
     title = infos.convertId("imdb", "title", "016954739339")
     self.assertIsNone(title)