mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-28 13:41:42 +00:00
Replace nginx with flask server #49
This commit is contained in:
commit
e05c4602b0
@ -44,6 +44,9 @@ def get_album_tracks():
|
||||
index = albumslib.find_album(album, artist)
|
||||
album = api.ALBUMS[index]
|
||||
|
||||
album.count = len(songs)
|
||||
album.duration = albumslib.get_album_duration(songs)
|
||||
|
||||
return {"songs": songs, "info": album}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import os
|
||||
from os import path
|
||||
from typing import Tuple
|
||||
|
||||
from flask import Flask
|
||||
@ -8,14 +8,15 @@ app = Flask(__name__)
|
||||
|
||||
|
||||
def join(*args: Tuple[str]) -> str:
|
||||
return os.path.join(*args)
|
||||
return path.join(*args)
|
||||
|
||||
|
||||
HOME = os.path.expanduser("~")
|
||||
ROOT_PATH = os.path.join(HOME, ".alice", "images")
|
||||
HOME = path.expanduser("~")
|
||||
ROOT_PATH = path.join(HOME, ".alice", "images")
|
||||
|
||||
THUMB_PATH = join(ROOT_PATH, "thumbnails")
|
||||
ARTIST_PATH = join(ROOT_PATH, "artists")
|
||||
PLAYLIST_PATH = join(ROOT_PATH, "playlists")
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@ -23,28 +24,42 @@ def hello():
|
||||
return "Hello mf"
|
||||
|
||||
|
||||
@app.route("/thumb/<path>")
|
||||
def send_thumbnail(path: str):
|
||||
fpath = join(THUMB_PATH, path)
|
||||
exists = os.path.exists(fpath)
|
||||
@app.route("/t/<imgpath>")
|
||||
def send_thumbnail(imgpath: str):
|
||||
fpath = join(THUMB_PATH, imgpath)
|
||||
exists = path.exists(fpath)
|
||||
|
||||
if exists:
|
||||
return send_from_directory(THUMB_PATH, path)
|
||||
return send_from_directory(THUMB_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
|
||||
|
||||
@app.route("/artist/<path>")
|
||||
def send_artist_image(path: str):
|
||||
@app.route("/a/<imgpath>")
|
||||
def send_artist_image(imgpath: str):
|
||||
print(ARTIST_PATH)
|
||||
fpath = join(ARTIST_PATH, path)
|
||||
exists = os.path.exists(fpath)
|
||||
fpath = join(ARTIST_PATH, imgpath)
|
||||
exists = path.exists(fpath)
|
||||
|
||||
if exists:
|
||||
return send_from_directory(ARTIST_PATH, path)
|
||||
return send_from_directory(ARTIST_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
|
||||
|
||||
@app.route("/p/<imgpath>")
|
||||
def send_playlist_image(imgpath: str):
|
||||
fpath = join(PLAYLIST_PATH, imgpath)
|
||||
exists = path.exists(fpath)
|
||||
|
||||
if exists:
|
||||
return send_from_directory(PLAYLIST_PATH, imgpath)
|
||||
|
||||
return {"msg": "Not found"}, 404
|
||||
|
||||
|
||||
# TODO
|
||||
# Return Fallback images instead of JSON
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(threaded=True, port=9877)
|
||||
|
@ -77,7 +77,7 @@ def find_album(albumtitle: str, artist: str) -> int or None:
|
||||
return None
|
||||
|
||||
|
||||
def get_album_duration(album: list) -> int:
|
||||
def get_album_duration(album: List[models.Track]) -> int:
|
||||
"""
|
||||
Gets the duration of an album.
|
||||
"""
|
||||
@ -85,7 +85,7 @@ def get_album_duration(album: list) -> int:
|
||||
album_duration = 0
|
||||
|
||||
for track in album:
|
||||
album_duration += track["length"]
|
||||
album_duration += track.length
|
||||
|
||||
return album_duration
|
||||
|
||||
@ -150,8 +150,6 @@ def create_album(track) -> models.Album:
|
||||
|
||||
album_tracks = get_album_tracks(album["album"], album["artist"])
|
||||
|
||||
album["count"] = len(album_tracks)
|
||||
album["duration"] = get_album_duration(album_tracks)
|
||||
album["date"] = album_tracks[0]["date"]
|
||||
|
||||
album["artistimage"] = urllib.parse.quote_plus(
|
||||
|
@ -56,17 +56,15 @@ class Album:
|
||||
|
||||
title: str
|
||||
artist: str
|
||||
count: int
|
||||
duration: int
|
||||
date: int
|
||||
artistimage: str
|
||||
image: str
|
||||
count: int = 0
|
||||
duration: int = 0
|
||||
|
||||
def __init__(self, tags):
|
||||
self.title = tags["album"]
|
||||
self.artist = tags["artist"]
|
||||
self.count = tags["count"]
|
||||
self.duration = tags["duration"]
|
||||
self.date = tags["date"]
|
||||
self.artistimage = tags["artistimage"]
|
||||
self.image = tags["image"]
|
||||
@ -128,9 +126,9 @@ class Playlist:
|
||||
|
||||
def create_img_link(self, image: str):
|
||||
if image:
|
||||
return settings.IMG_PLAYLIST_URI + image
|
||||
return image
|
||||
|
||||
return settings.IMG_PLAYLIST_URI + "default.webp"
|
||||
return "default.webp"
|
||||
|
||||
def update_count(self):
|
||||
self.count = len(self._pre_tracks)
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div
|
||||
class="image shadow-lg"
|
||||
:style="{
|
||||
backgroundImage: `url("${props.album.image}")`,
|
||||
backgroundImage: `url("${imguri + props.album.image}")`,
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
@ -32,7 +32,9 @@ import perks from "../../composables/perks.js";
|
||||
import { AlbumInfo } from "../../interfaces.js";
|
||||
import PlayBtnRect from "../shared/PlayBtnRect.vue";
|
||||
import { playSources } from "../../composables/enums";
|
||||
import { paths } from "../../config";
|
||||
|
||||
const imguri = paths.images.thumb
|
||||
const props = defineProps<{
|
||||
album: AlbumInfo;
|
||||
}>();
|
||||
|
@ -6,7 +6,7 @@
|
||||
<div
|
||||
class="l-image image rounded"
|
||||
:style="{
|
||||
backgroundImage: `url("${track.image}")`,
|
||||
backgroundImage: `url("${imguri + track.image}")`,
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
@ -36,6 +36,9 @@
|
||||
<script setup lang="ts">
|
||||
import perks from "../../composables/perks";
|
||||
import { Track } from "../../interfaces";
|
||||
import { paths } from "../../config";
|
||||
const imguri = paths.images.thumb
|
||||
|
||||
const putCommas = perks.putCommas;
|
||||
|
||||
const props = defineProps<{
|
||||
|
@ -3,7 +3,7 @@
|
||||
class="p-header image"
|
||||
:style="[
|
||||
{
|
||||
backgroundImage: `url(${props.info.image})`,
|
||||
backgroundImage: `url(${imguri + props.info.image})`,
|
||||
},
|
||||
]"
|
||||
>
|
||||
@ -45,7 +45,9 @@ import useModalStore from "../../stores/modal";
|
||||
import Option from "../shared/Option.vue";
|
||||
import pContext from "../../contexts/playlist";
|
||||
import useContextStore from "../../stores/context";
|
||||
import { paths } from "../../config";
|
||||
|
||||
const imguri = paths.images.playlist
|
||||
const context = useContextStore();
|
||||
const modal = useModalStore();
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="main-item border" @click="playNext">
|
||||
<div class="h">Up Next</div>
|
||||
<div class="itemx shadow">
|
||||
<div class="itemx shadow">
|
||||
<div
|
||||
class="album-art image"
|
||||
:style="{
|
||||
backgroundImage: `url("${next.image}")`,
|
||||
backgroundImage: `url("${imguri + next.image}")`,
|
||||
}"
|
||||
></div>
|
||||
<div class="tags">
|
||||
@ -24,6 +24,8 @@
|
||||
<script setup lang="ts">
|
||||
import { Track } from "../../../interfaces";
|
||||
import perks from "../../../composables/perks";
|
||||
import { paths } from "../../../config";
|
||||
const imguri = paths.images.thumb;
|
||||
|
||||
const props = defineProps<{
|
||||
next: Track;
|
||||
@ -38,7 +40,7 @@ const props = defineProps<{
|
||||
|
||||
&:hover {
|
||||
background-color: $accent;
|
||||
border: 1px solid transparent;
|
||||
border: 1px solid transparent;
|
||||
|
||||
.h {
|
||||
background-color: $black;
|
||||
|
@ -10,7 +10,7 @@
|
||||
<div
|
||||
class="image p-image rounded shadow-sm"
|
||||
:style="{
|
||||
backgroundImage: `url(${props.playlist.thumb})`,
|
||||
backgroundImage: `url(${imguri + props.playlist.thumb})`,
|
||||
}"
|
||||
></div>
|
||||
<div class="pbtn">
|
||||
@ -33,6 +33,10 @@
|
||||
import { Playlist } from "../../interfaces";
|
||||
import PlayBtn from "../shared/PlayBtn.vue";
|
||||
import Option from "../shared/Option.vue";
|
||||
import { paths } from "../../config";
|
||||
|
||||
const imguri = paths.images.playlist
|
||||
|
||||
|
||||
const props = defineProps<{
|
||||
playlist: Playlist;
|
||||
|
@ -9,7 +9,11 @@
|
||||
<div class="flex">
|
||||
<div
|
||||
class="album-art image rounded"
|
||||
:style="{ backgroundImage: `url("${props.song.image}"` }"
|
||||
:style="{
|
||||
backgroundImage: `url("${
|
||||
imguri + props.song.image
|
||||
}"`,
|
||||
}"
|
||||
@click="emitUpdate(props.song)"
|
||||
>
|
||||
<div
|
||||
@ -64,10 +68,12 @@ import { ContextSrc } from "../../composables/enums";
|
||||
import { ref } from "vue";
|
||||
import trackContext from "../../contexts/track_context";
|
||||
import { Track } from "../../interfaces.js";
|
||||
import { paths } from "../../config";
|
||||
|
||||
const contextStore = useContextStore();
|
||||
const modalStore = useModalStore();
|
||||
const context_on = ref(false);
|
||||
const imguri = paths.images.thumb
|
||||
|
||||
const showContextMenu = (e: Event) => {
|
||||
e.preventDefault();
|
||||
@ -118,6 +124,7 @@ function emitUpdate(track: Track) {
|
||||
width: 45px;
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
@include tablet-landscape {
|
||||
grid-template-columns: 1.5rem 1.5fr 1fr 1.5fr;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<div
|
||||
class="album-art image rounded"
|
||||
:style="{
|
||||
backgroundImage: `url("${props.track.image}")`,
|
||||
backgroundImage: `url("${imguri + props.track.image}")`,
|
||||
}"
|
||||
>
|
||||
<div
|
||||
@ -43,9 +43,12 @@ import { ContextSrc } from "../../composables/enums";
|
||||
|
||||
import useContextStore from "../../stores/context";
|
||||
import useModalStore from "../../stores/modal";
|
||||
import { paths } from "../../config";
|
||||
|
||||
|
||||
const contextStore = useContextStore();
|
||||
const modalStore = useModalStore();
|
||||
const imguri = paths.images.thumb
|
||||
|
||||
const props = defineProps<{
|
||||
track: Track;
|
||||
|
10
src/config.ts
Normal file
10
src/config.ts
Normal file
@ -0,0 +1,10 @@
|
||||
const paths = {
|
||||
api: "",
|
||||
images: {
|
||||
thumb: "http://0.0.0.0:9877/t/",
|
||||
artist: "http://0.0.0.0:9877/a/",
|
||||
playlist: "http://0.0.0.0:9877/p/"
|
||||
},
|
||||
};
|
||||
|
||||
export { paths };
|
Loading…
x
Reference in New Issue
Block a user