Spaces:
Sleeping
Sleeping
File size: 1,423 Bytes
7a11778 b1e3e0a 7a11778 b1e3e0a 7a11778 b1e3e0a 7a11778 b1e3e0a 7a11778 b1e3e0a 7a11778 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from flask import Flask, jsonify
from flask_cors import CORS
import os, sys
# Prefer vendored ytmusicapi over site-packages
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "ytmusicapi"))
from ytmusicapi import YTMusic
from routes import bp as api_bp
from routes_entities import bp_entities
from routes_explore import bp_explore
from routes_youtube import bp_youtube
from routes_jiosaavn import bp_jiosaavn
from swagger import init_swagger
def create_app() -> Flask:
app = Flask(__name__)
# Enable CORS for all domains
CORS(app, origins="*")
# Unauthenticated client (no OAuth or cookies)
# See: https://ytmusicapi.readthedocs.io/en/stable/
ytmusic = YTMusic()
@app.get("/health")
def health() -> tuple:
return jsonify({"status": "ok"}), 200
# Expose ytmusic instance via app context for use in other routes
app.config["YTMUSIC_CLIENT"] = ytmusic
# Docs
init_swagger(app)
# Register API blueprints under /api
app.register_blueprint(api_bp, url_prefix="/api")
app.register_blueprint(bp_entities, url_prefix="/api")
app.register_blueprint(bp_explore, url_prefix="/api")
app.register_blueprint(bp_youtube, url_prefix="/api")
app.register_blueprint(bp_jiosaavn, url_prefix="/api")
return app
# Module-level app for WSGI servers
app = create_app()
if __name__ == "__main__":
# Local dev server
port = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=port, debug=True)
|