CoolFace
Apppublic

PrometheusGroup/voidscape-noir

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
app.py80 linesDownload Raw Back to root
1```python2from flask import Flask, render_template, request, jsonify3 4app = Flask(__name__)5 6# Mock data for demonstration7mock_playlist = [8    {9        "id": 1,10        "title": "Midnight City",11        "artist": "M83",12        "duration": "4:03",13        "thumbnail": "http://static.photos/music/200x200/1",14        "downloaded": True15    },16    {17        "id": 2,18        "title": "Blinding Lights",19        "artist": "The Weeknd",20        "duration": "3:20",21        "thumbnail": "http://static.photos/music/200x200/2",22        "downloaded": True23    }24]25 26mock_search_results = [27    {28        "id": 3,29        "title": "Save Your Tears",30        "artist": "The Weeknd",31        "duration": "3:35",32        "thumbnail": "http://static.photos/music/200x200/3",33        "downloaded": False34    },35    {36        "id": 4,37        "title": "Starboy",38        "artist": "The Weeknd ft. Daft Punk",39        "duration": "3:50",40        "thumbnail": "http://static.photos/music/200x200/4",41        "downloaded": False42    }43]44 45@app.route('/')46def index():47    return render_template('player.html')48 49@app.route('/api/playlist')50def get_playlist():51    return jsonify(mock_playlist)52 53@app.route('/api/search', methods=['POST'])54def search():55    query = request.json.get('query', '')56    # In a real app, you would search your database or API here57    return jsonify(mock_search_results)58 59@app.route('/api/add_to_playlist', methods=['POST'])60def add_to_playlist():61    song_id = request.json.get('id')62    # Find the song in search results and add to playlist63    for song in mock_search_results:64        if song['id'] == song_id:65            new_song = song.copy()66            new_song['downloaded'] = False67            mock_playlist.append(new_song)68            return jsonify({"success": True})69    return jsonify({"success": False}), 40470 71@app.route('/api/remove_from_playlist', methods=['POST'])72def remove_from_playlist():73    song_id = request.json.get('id')74    global mock_playlist75    mock_playlist = [song for song in mock_playlist if song['id'] != song_id]76    return jsonify({"success": True})77 78if __name__ == '__main__':79    app.run(debug=True)80```