mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03:02 +00:00
add "single" label if album is a single
This commit is contained in:
+10
-2
@@ -36,7 +36,7 @@ def get_albums():
|
|||||||
|
|
||||||
|
|
||||||
@album_bp.route("/album/tracks", methods=["POST"])
|
@album_bp.route("/album/tracks", methods=["POST"])
|
||||||
def get_album_tracks():
|
def get_album():
|
||||||
"""Returns all the tracks in the given album."""
|
"""Returns all the tracks in the given album."""
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|
||||||
@@ -46,11 +46,19 @@ def get_album_tracks():
|
|||||||
songs = trackslib.get_album_tracks(album, artist)
|
songs = trackslib.get_album_tracks(album, artist)
|
||||||
albumhash = helpers.create_album_hash(album, artist)
|
albumhash = helpers.create_album_hash(album, artist)
|
||||||
index = albumslib.find_album(api.ALBUMS, albumhash)
|
index = albumslib.find_album(api.ALBUMS, albumhash)
|
||||||
album = api.ALBUMS[index]
|
album: models.Album = api.ALBUMS[index]
|
||||||
|
|
||||||
album.count = len(songs)
|
album.count = len(songs)
|
||||||
album.duration = albumslib.get_album_duration(songs)
|
album.duration = albumslib.get_album_duration(songs)
|
||||||
|
|
||||||
|
if (
|
||||||
|
album.count == 1
|
||||||
|
and songs[0].title == album.title
|
||||||
|
and songs[0].tracknumber == 1
|
||||||
|
and songs[0].disknumber == 1
|
||||||
|
):
|
||||||
|
album.is_single = True
|
||||||
|
|
||||||
return {"songs": songs, "info": album}
|
return {"songs": songs, "info": album}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+31
-31
@@ -28,7 +28,7 @@ def return_album_art(filepath: str):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def extract_thumb(audio_file_path: str, webp_path: str) -> bool:
|
def extract_thumb(filepath: str, webp_path: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Extracts the thumbnail from an audio file. Returns the path to the thumbnail.
|
Extracts the thumbnail from an audio file. Returns the path to the thumbnail.
|
||||||
"""
|
"""
|
||||||
@@ -37,7 +37,7 @@ def extract_thumb(audio_file_path: str, webp_path: str) -> bool:
|
|||||||
if os.path.exists(img_path):
|
if os.path.exists(img_path):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
album_art = return_album_art(audio_file_path)
|
album_art = return_album_art(filepath)
|
||||||
|
|
||||||
if album_art is not None:
|
if album_art is not None:
|
||||||
img = Image.open(BytesIO(album_art))
|
img = Image.open(BytesIO(album_art))
|
||||||
@@ -58,98 +58,98 @@ def extract_thumb(audio_file_path: str, webp_path: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def parse_artist_tag(audio):
|
def parse_artist_tag(tags):
|
||||||
"""
|
"""
|
||||||
Parses the artist tag from an audio file.
|
Parses the artist tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
artists = audio["artist"][0]
|
artists = tags["artist"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
artists = "Unknown"
|
artists = "Unknown"
|
||||||
|
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
|
|
||||||
def parse_title_tag(audio, full_path: str):
|
def parse_title_tag(tags, full_path: str):
|
||||||
"""
|
"""
|
||||||
Parses the title tag from an audio file.
|
Parses the title tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
title = audio["title"][0]
|
title = tags["title"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
title = full_path.split("/")[-1]
|
title = full_path.split("/")[-1]
|
||||||
|
|
||||||
return title
|
return title
|
||||||
|
|
||||||
|
|
||||||
def parse_album_artist_tag(audio):
|
def parse_album_artist_tag(tags):
|
||||||
"""
|
"""
|
||||||
Parses the album artist tag from an audio file.
|
Parses the album artist tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
albumartist = audio["albumartist"][0]
|
albumartist = tags["albumartist"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
albumartist = "Unknown"
|
albumartist = "Unknown"
|
||||||
|
|
||||||
return albumartist
|
return albumartist
|
||||||
|
|
||||||
|
|
||||||
def parse_album_tag(audio, full_path: str):
|
def parse_album_tag(tags, full_path: str):
|
||||||
"""
|
"""
|
||||||
Parses the album tag from an audio file.
|
Parses the album tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
album = audio["album"][0]
|
album = tags["album"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
album = full_path.split("/")[-1]
|
album = full_path.split("/")[-1]
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
|
||||||
def parse_genre_tag(audio):
|
def parse_genre_tag(tags):
|
||||||
"""
|
"""
|
||||||
Parses the genre tag from an audio file.
|
Parses the genre tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
genre = audio["genre"][0]
|
genre = tags["genre"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
genre = "Unknown"
|
genre = "Unknown"
|
||||||
|
|
||||||
return genre
|
return genre
|
||||||
|
|
||||||
|
|
||||||
def parse_date_tag(audio):
|
def parse_date_tag(tags):
|
||||||
"""
|
"""
|
||||||
Parses the date tag from an audio file.
|
Parses the date tag from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
date = audio["date"][0]
|
date = tags["date"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
date = "Unknown"
|
date = "Unknown"
|
||||||
|
|
||||||
return date
|
return date
|
||||||
|
|
||||||
|
|
||||||
def parse_track_number(audio):
|
def parse_track_number(tags):
|
||||||
"""
|
"""
|
||||||
Parses the track number from an audio file.
|
Parses the track number from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
track_number = audio["tracknumber"][0]
|
track_number = tags["tracknumber"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
track_number = "Unknown"
|
track_number = 1
|
||||||
|
|
||||||
return track_number
|
return track_number
|
||||||
|
|
||||||
|
|
||||||
def parse_disk_number(audio):
|
def parse_disk_number(tags):
|
||||||
"""
|
"""
|
||||||
Parses the disk number from an audio file.
|
Parses the disk number from an audio file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
disk_number = audio["discnumber"][0]
|
disk_number = tags["disknumber"][0]
|
||||||
except (KeyError, IndexError):
|
except (KeyError, IndexError):
|
||||||
disk_number = "Unknown"
|
disk_number = 1
|
||||||
|
|
||||||
return disk_number
|
return disk_number
|
||||||
|
|
||||||
@@ -159,21 +159,21 @@ def get_tags(fullpath: str) -> dict | None:
|
|||||||
Returns a dictionary of tags for a given file.
|
Returns a dictionary of tags for a given file.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
audio = mutagen.File(fullpath, easy=True)
|
tags = mutagen.File(fullpath, easy=True)
|
||||||
except MutagenError:
|
except MutagenError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
tags = {
|
tags = {
|
||||||
"artists": parse_artist_tag(audio),
|
"artists": parse_artist_tag(tags),
|
||||||
"title": parse_title_tag(audio, fullpath),
|
"title": parse_title_tag(tags, fullpath),
|
||||||
"albumartist": parse_album_artist_tag(audio),
|
"albumartist": parse_album_artist_tag(tags),
|
||||||
"album": parse_album_tag(audio, fullpath),
|
"album": parse_album_tag(tags, fullpath),
|
||||||
"genre": parse_genre_tag(audio),
|
"genre": parse_genre_tag(tags),
|
||||||
"date": parse_date_tag(audio)[:4],
|
"date": parse_date_tag(tags)[:4],
|
||||||
"tracknumber": parse_track_number(audio),
|
"tracknumber": parse_track_number(tags),
|
||||||
"discnumber": parse_disk_number(audio),
|
"disknumber": parse_disk_number(tags),
|
||||||
"length": round(audio.info.length),
|
"length": round(tags.info.length),
|
||||||
"bitrate": round(int(audio.info.bitrate) / 1000),
|
"bitrate": round(int(tags.info.bitrate) / 1000),
|
||||||
"filepath": fullpath,
|
"filepath": fullpath,
|
||||||
"folder": os.path.dirname(fullpath),
|
"folder": os.path.dirname(fullpath),
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -1,12 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
Contains all the models for objects generation and typing.
|
Contains all the models for objects generation and typing.
|
||||||
"""
|
"""
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from dataclasses import field
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from app import api
|
from app import api, helpers
|
||||||
from app import helpers
|
|
||||||
from app.exceptions import TrackExistsInPlaylist
|
from app.exceptions import TrackExistsInPlaylist
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ class Track:
|
|||||||
bitrate: int
|
bitrate: int
|
||||||
image: str
|
image: str
|
||||||
tracknumber: int
|
tracknumber: int
|
||||||
discnumber: int
|
disknumber: int
|
||||||
albumhash: str
|
albumhash: str
|
||||||
|
|
||||||
def __init__(self, tags):
|
def __init__(self, tags):
|
||||||
@@ -43,18 +41,21 @@ class Track:
|
|||||||
self.album = tags["album"]
|
self.album = tags["album"]
|
||||||
self.folder = tags["folder"]
|
self.folder = tags["folder"]
|
||||||
self.filepath = tags["filepath"]
|
self.filepath = tags["filepath"]
|
||||||
self.length = tags["length"]
|
|
||||||
self.genre = tags["genre"]
|
self.genre = tags["genre"]
|
||||||
self.bitrate = tags["bitrate"]
|
self.bitrate = int(tags["bitrate"])
|
||||||
|
self.length = int(tags["length"])
|
||||||
|
self.disknumber = int(tags["disknumber"])
|
||||||
|
self.albumhash = tags["albumhash"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.image = tags["image"]
|
self.image = tags["image"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(tags)
|
print(tags)
|
||||||
|
|
||||||
self.tracknumber = tags["tracknumber"]
|
try:
|
||||||
self.discnumber = tags["discnumber"]
|
self.tracknumber = int(tags["tracknumber"])
|
||||||
self.albumhash = tags["albumhash"]
|
except ValueError:
|
||||||
|
self.tracknumber = 1
|
||||||
|
|
||||||
|
|
||||||
@dataclass(slots=True)
|
@dataclass(slots=True)
|
||||||
@@ -88,6 +89,7 @@ class Album:
|
|||||||
duration: int = 0
|
duration: int = 0
|
||||||
is_soundtrack: bool = False
|
is_soundtrack: bool = False
|
||||||
is_compilation: bool = False
|
is_compilation: bool = False
|
||||||
|
is_single: bool = False
|
||||||
|
|
||||||
def __init__(self, tags):
|
def __init__(self, tags):
|
||||||
self.title = tags["title"]
|
self.title = tags["title"]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<div class="h">
|
<div class="h">
|
||||||
<span v-if="album.is_soundtrack">Soundtrack</span>
|
<span v-if="album.is_soundtrack">Soundtrack</span>
|
||||||
<span v-else-if="album.is_compilation">Compilation</span>
|
<span v-else-if="album.is_compilation">Compilation</span>
|
||||||
|
<span v-else-if="album.is_single">Single</span>
|
||||||
<span v-else>Album</span>
|
<span v-else>Album</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="title ellip">{{ album.title }}</div>
|
<div class="title ellip">{{ album.title }}</div>
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,4 @@
|
|||||||
import { FromOptions } from "./composables/enums";
|
import { FromOptions, NotifType } from "./composables/enums";
|
||||||
import { NotifType } from "./composables/enums";
|
|
||||||
|
|
||||||
interface Track {
|
interface Track {
|
||||||
trackid: string;
|
trackid: string;
|
||||||
@@ -14,7 +13,7 @@ interface Track {
|
|||||||
genre?: string;
|
genre?: string;
|
||||||
image: string;
|
image: string;
|
||||||
tracknumber?: number;
|
tracknumber?: number;
|
||||||
discnumber?: number;
|
disknumber?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Folder {
|
interface Folder {
|
||||||
@@ -33,6 +32,7 @@ interface AlbumInfo {
|
|||||||
image: string;
|
image: string;
|
||||||
is_compilation: boolean;
|
is_compilation: boolean;
|
||||||
is_soundtrack: boolean;
|
is_soundtrack: boolean;
|
||||||
|
is_single: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Artist {
|
interface Artist {
|
||||||
|
|||||||
Reference in New Issue
Block a user