示例#1
0
def update_trakt(release_key):
    """

    :param release_key:
    :type release_key: BaseReleaseKey|TVReleaseKey|TVDailyReleaseKey|MovieReleaseKey
    """
    session = Session()
    media_info = None

    try:
        if release_key.media_type == constants.MEDIA_TV:
            if release_key.daily:
                info = trakt.show_episode_summary_daily(
                    release_key.name, release_key.day, release_key.month, release_key.year
                )
            else:
                info = trakt.show_episode_summary(release_key.name, release_key.season, release_key.episode)
            raise_unless(info, exceptions.ApiError, "Failed to fetch metadata for: {}".format(release_key))
            media_info = _update_trakt_tv(session, info)
        elif release_key.media_type == constants.MEDIA_MOVIE:
            info = trakt.movie_summary(release_key.name)
            raise_unless(info, exceptions.ApiError, "Failed to fetch metadata for: {}".format(release_key))
            media_info = _update_trakt_movie(session, info)
        else:
            return None
        session.commit()
    except DBAPIError as e:
        log.exception("Error querying media info")
        session.rollback()
    except exceptions.ApiError as e:
        log.warn(e.message)
    except Exception as e:
        log.exception("Could not update trakt info")
    return media_info
示例#2
0
def update_imdb(media_info=None, release_key=None):
    session = Session()
    try:
        if media_info.imdb_id:
            movie_info = imdb.get_movie(media_info.imdb_id)
            if movie_info:
                media_info.imdb_score = movie_info['rating']
                media_info.imdb_votes = movie_info['votes']
                media_info.cover_url = movie_info['cover_url']
                for director in movie_info.get('director', []):
                    person = get_person_imdb(session, director['person_id'], name=director['name'])
                    if not person in media_info.directors:
                        media_info.directors.append(person)
                for cast_member in movie_info.get('cast', []):
                    person = get_person_imdb(session,
                                             cast_member['person']['person_id'],
                                             name=cast_member['person']['name'])
                    if not person in media_info.cast:
                        media_info.cast.append(person)
        session.commit()
    except DBAPIError:
        session.rollback()
    except exceptions.ApiError as e:
        log.warn(e.message)
    return media_info
示例#3
0
def update_trakt(release_key):
    """

    :param release_key:
    :type release_key: BaseReleaseKey|TVReleaseKey|TVDailyReleaseKey|MovieReleaseKey
    """
    session = Session()
    media_info = None

    try:
        if release_key.media_type == constants.MEDIA_TV:
            if release_key.daily:
                info = trakt.show_episode_summary_daily(
                    release_key.name, release_key.day, release_key.month, release_key.year
                )
            else:
                info = trakt.show_episode_summary(release_key.name, release_key.season, release_key.episode)
            raise_unless(info, exceptions.ApiError, "Failed to fetch metadata for: {}".format(release_key))
            media_info = _update_trakt_tv(session, info)
        elif release_key.media_type == constants.MEDIA_MOVIE:
            info = trakt.movie_summary(release_key.name)
            raise_unless(info, exceptions.ApiError, "Failed to fetch metadata for: {}".format(release_key))
            media_info = _update_trakt_movie(session, info)
        else:
            return None
        session.commit()
    except DBAPIError as e:
        log.exception("Error querying media info")
        session.rollback()
    except exceptions.ApiError as e:
        log.warn(e.message)
    except Exception as e:
        log.exception("Could not update trakt info")
    return media_info
示例#4
0
def update_imdb(media_info=None, release_key=None):
    session = Session()
    try:
        if media_info.imdb_id:
            movie_info = imdb.get_movie(media_info.imdb_id)
            if movie_info:
                media_info.imdb_score = movie_info['rating']
                media_info.imdb_votes = movie_info['votes']
                media_info.cover_url = movie_info['cover_url']
                for director in movie_info.get('director', []):
                    person = get_person_imdb(session, director['person_id'], name=director['name'])
                    if not person in media_info.directors:
                        media_info.directors.append(person)
                for cast_member in movie_info.get('cast', []):
                    person = get_person_imdb(session,
                                             cast_member['person']['person_id'],
                                             name=cast_member['person']['name'])
                    if person not in media_info.cast:
                        media_info.cast.append(person)
        session.commit()
    except DBAPIError:
        session.rollback()
    except exceptions.ApiError as e:
        log.warn(e.message)
    return media_info
示例#5
0
def db_init(username="******", password="******", wipe=False):
    from tranny.app import Base, engine, Session
    Session.configure(bind=engine)
    try:
        if wipe:
            db_drop()
        Base.metadata.create_all(bind=engine)
    except DBAPIError:
        log.exception("Failed to initialize db schema")
    else:
        log.info("Initialized db schema successfully")
        session = Session()
        try:
            admin = User(user_name=username, password=password, role=constants.ROLE_ADMIN)
            session.add(admin)
            session.commit()
        except DBAPIError:
            session.rollback()
        else:
            log.info("Created admin user successfully")
            return True
    return False
示例#6
0
def db_init(username="******", password="******", wipe=False):
    from tranny.app import Base, engine, Session
    Session.configure(bind=engine)
    try:
        if wipe:
            db_drop()
        Base.metadata.create_all(bind=engine)
    except DBAPIError:
        log.exception("Failed to initialize db schema")
    else:
        log.info("Initialized db schema successfully")
        session = Session()
        try:
            admin = User(user_name=username,
                         password=password,
                         role=constants.ROLE_ADMIN)
            session.add(admin)
            session.commit()
        except DBAPIError:
            session.rollback()
        else:
            log.info("Created admin user successfully")
            return True
    return False