Exemplo n.º 1
0
def add_video():
    playlist_id = request.form.get("playlist_id")
    if playlist_id.strip() == "":
        return jsonify({'error': "You must specify a playlist ID for this video."})

    playlist = Playlist.query.get(playlist_id)
    if playlist == None:
        return jsonify({'error': "Playlist not found"})

    slug = request.form.get("slug")
    if slug.strip() == "":
        return jsonify({'error': "You must specify a slug for this video."})

    thumbnail_url = request.form.get("thumbnail_url")
    if thumbnail_url.strip() == "":
        return jsonify({'error': "You must specify a thumbnail for this video."})

    title = request.form.get("title")
    if title.strip() == "":
        return jsonify({'error': "You must specify a title for this video."})

    v = Video(playlist_id, slug, thumbnail_url, title)
    db_session.add(v)
    db_session.commit()    

    # Publish to Redis so that all clients update playlist
    data = {
        "action": "update_playlist",
        "playlist": Playlist.get_videos(playlist_id)
    }

    redis.publish(playlist_id, json.dumps(data))

    return jsonify({"success": True})
Exemplo n.º 2
0
def get_playlist():
    playlist_id = request.args.get("playlist_id")

    # Now get the updated playlist and send it to the client
    videos = Video.query.filter(Video.playlist_id==playlist_id).order_by("rank desc")

    data = {
        "playlist": Playlist.get_videos(playlist_id)
    }

    return jsonify(data)
Exemplo n.º 3
0
def mark_played():
    playlist_id = request.form.get("playlist_id")
    video_slug = request.form.get("video_slug")

    video = Video.query.filter(Video.playlist_id==playlist_id).filter(Video.slug==video_slug).first()

    db_session.delete(video)
    db_session.commit()

    # Publish to Redis so that all clients update playlist
    data = {
        "action": "update_playlist",
        "playlist": Playlist.get_videos(playlist_id)
    }

    redis.publish(playlist_id, json.dumps(data))

    return jsonify({"success": True})
Exemplo n.º 4
0
def vote(up_down):
    video_id = request.form.get("video_id")
    playlist_id = request.form.get("playlist_id")

    video = Video.query.filter(Video.playlist_id==playlist_id).filter(Video.slug==video_id).first()

    if up_down == "up":
        video.rank += 1
    elif up_down == "down":
        video.rank -= 1
    else:
        raise TypeError("Please either upvote or downvote this video.")

    db_session.commit()

    # Publish to Redis so that all clients update playlist
    data = {
        "action": "update_playlist",
        "playlist": Playlist.get_videos(playlist_id)
    }

    redis.publish(playlist_id, json.dumps(data))

    return jsonify({"success": True})