#!/usr/bin/env python3 """ A music steaming application. """ import random from fastapi import FastAPI, Request from fastapi.templating import Jinja2Templates from fastapi.staticfiles import StaticFiles from fastapi.responses import HTMLResponse #import buckler_fastapi app = FastAPI() #app.add_middleware(buckler_fastapi.BucklerSessionMiddleware) app.mount("/static", StaticFiles(directory="static"), name="static") templates = Jinja2Templates(directory="templates") @app.get("/", response_class=HTMLResponse) async def index(request: Request): context = {"request": request} return templates.TemplateResponse('index.html', context) @app.get("/rand_track/") async def get_rand_track(): """Return a random track.""" tracks = [{ 'title': "Blade Runner", 'artist': "Beast In Black", 'album': "Dark Connection", 'source': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/01%20-%20Blade%20Runner.opus", 'artwork': [{ 'src': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/folder-256x256.jpg", 'sizes': "256x256", 'type': "image/jpeg" }] }, { 'title': "Bella Donna", 'artist': "Beast In Black", 'album': "Dark Connection", 'source': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/02%20-%20Bella%20Donna.opus", 'artwork': [{ 'src': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/folder-256x256.jpg", 'sizes': "256x256", 'type': "image/jpeg" }] }, { 'title': "Highway To Mars", 'artist': "Beast In Black", 'album': "Dark Connection", 'source': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/03%20-%20Highway%20To%20Mars.opus", 'artwork': [{ 'src': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/folder-256x256.jpg", 'sizes': "256x256", 'type': "image/jpeg" }] }, { 'title': "Hardcore", 'artist': "Beast In Black", 'album': "Dark Connection", 'source': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/04%20-%20Hardcore.opus", 'artwork': [{ 'src': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/folder-256x256.jpg", 'sizes': "256x256", 'type': "image/jpeg" }] }, { 'title': "One Night In Tokyo", 'artist': "Beast In Black", 'album': "Dark Connection", 'source': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/05%20-%20One%20Night%20In%20Tokyo.opus", 'artwork': [{ 'src': "https://steelbea.me/scorch_test/library/Beast%20In%20Black/Beast%20In%20Black%20-%20Dark%20Connection%20%282021%29%20%5BFLAC%5D%20%7BNB62072%7D/folder-256x256.jpg", 'sizes': "256x256", 'type': "image/jpeg" }] }] return random.choice(tracks)