Ejemplo n.º 1
0
def update(args):
    """Get all information about a user and download their videos."""
    session = get_session()
    users = session.query(User).all()
    playlists = session.query(Playlist).all()

    for user in users:
        download_user_videos(session, user)
        user.last_scan = datetime.now()
        session.commit()

    for playlist in playlists:
        download_playlist_videos(session, playlist)
        user.last_scan = datetime.now()
        session.commit()
Ejemplo n.º 2
0
def get_user(args):
    """Get all information about a user and download their videos."""
    key = args['key']
    session = get_session()

    user = session.query(User).get(key)
    if user is None:
        info = get_user_info(key)
        user = User.get_or_create(session, key, info['name'], info['type'])

    user.subscribed = True
    session.commit()

    download_user_videos(session, user)
    session.last_scan = datetime.now()
    session.commit()
Ejemplo n.º 3
0
def update(args):
    """Get all information about a user and download their videos."""
    session = get_session()

    threshold = datetime.now() - timedelta(hours=8)

    # Go through all users
    users = (session.query(User).filter(User.last_scan <= threshold).order_by(
        User.key).all())
    for user in users:
        # Re query the user type, since this can change over time
        print(user.key)
        info = get_user_info(user.key)
        user.user_type = info["type"]

        logger.info(f"\nStart downloading user: {user.name}")
        if download_user_videos(session, user):
            user.last_scan = datetime.now()
        session.commit()

    # Go through all playlists
    playlists = (session.query(Playlist).filter(
        Playlist.last_scan <= threshold).order_by(Playlist.name).all())
    for playlist in playlists:
        logger.info(f"\nStart downloading playlist: {playlist.name}")
        if download_playlist_videos(session, playlist):
            user.last_scan = datetime.now()
        session.commit()

    # Go through all channels
    channels = (session.query(Channel).filter(
        Channel.last_scan <= threshold).order_by(Channel.name).all())
    for channel in channels:
        logger.info(f"\nStart downloading channel: {channel.name}")
        if download_channel_videos(session, channel):
            user.last_scan = datetime.now()
        session.commit()

    clips = (session.query(Clip).filter(Clip.completed.is_(False)).filter(
        Clip.location.isnot(None)).all())

    for clip in clips:
        download_video(clip.viewkey, name=os.path.dirname(clip.location))
        clip.completed = True
        session.commit()
Ejemplo n.º 4
0
def get_user(args):
    """Get all information about a user and download their videos."""
    key = args["key"]
    session = get_session()

    user = session.query(User).get(key)
    info = get_user_info(key)
    if user is None:
        user = User.get_or_create(session, key, info["name"], info["type"])
    else:
        user.user_type = info["type"]

    user.subscribed = True
    session.commit()

    # Only set the last scan date, if everything could be downloaded
    if download_user_videos(session, user):
        session.last_scan = datetime.now()
    session.commit()