def get_playlist(args): """Get all information about the playlist and download it's videos.""" playlist_id = args['id'] session = get_session() playlist = session.query(Playlist).get(playlist_id) if playlist is None: info = get_playlist_info(playlist_id) playlist = Playlist.get_or_create(session, playlist_id, info['name']) download_playlist_videos(session, playlist) playlist.last_scan = datetime.now() session.commit()
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()
def get_playlist(args): """Get all information about the playlist and download it's videos.""" playlist_id = args["id"] session = get_session() playlist = session.query(Playlist).get(playlist_id) if playlist is None: info = get_playlist_info(playlist_id) playlist = Playlist.get_or_create(session, playlist_id, info["name"]) # Only set the last scan date, if everything could be downloaded if download_playlist_videos(session, playlist): playlist.last_scan = datetime.now() session.commit()
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()