2022-11-20 01:00:54 -08:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
import bottle
|
|
|
|
from bottle import HTTPResponse
|
|
|
|
from bottle.ext import sqlite
|
|
|
|
|
2022-11-19 16:06:23 -08:00
|
|
|
from groove.auth import is_authenticated
|
2022-11-20 01:00:54 -08:00
|
|
|
from groove.helper import PlaylistDatabaseHelper
|
|
|
|
|
|
|
|
server = bottle.Bottle()
|
2022-11-19 15:14:12 -08:00
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
|
|
|
|
def initialize():
|
|
|
|
"""
|
|
|
|
Configure the sqlite database.
|
|
|
|
"""
|
|
|
|
server.install(sqlite.Plugin(dbfile=os.environ.get('DATABASE_PATH')))
|
2022-11-19 15:14:12 -08:00
|
|
|
|
|
|
|
|
|
|
|
@server.route('/')
|
|
|
|
def index():
|
|
|
|
return "Groovy."
|
2022-11-19 16:06:23 -08:00
|
|
|
|
|
|
|
|
2022-11-20 01:00:54 -08:00
|
|
|
@server.route('/build')
|
|
|
|
@bottle.auth_basic(is_authenticated)
|
|
|
|
def build():
|
2022-11-19 16:06:23 -08:00
|
|
|
return "Authenticated. Groovy."
|
2022-11-20 01:00:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
@server.route('/playlist/<slug>')
|
|
|
|
def get_playlist(slug, db):
|
|
|
|
"""
|
|
|
|
Retrieve a playlist and its entries by a slug.
|
|
|
|
"""
|
|
|
|
logging.debug(f"Looking up playlist: {slug}...")
|
|
|
|
pldb = PlaylistDatabaseHelper(connection=db)
|
|
|
|
playlist = pldb.playlist(slug)
|
|
|
|
if not playlist:
|
|
|
|
return HTTPResponse(status=404, body="Not found")
|
|
|
|
return pldb.json_response(playlist)
|