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