From b930fc0ca6a633bef837e14083fa414a4f782930 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Mon, 7 Mar 2022 06:49:56 +0300 Subject: [PATCH] iniitialize project teardown --- server/app/albums.py | 44 ++++++++++ server/app/api.py | 6 +- server/app/functions.py | 13 ++- server/app/helpers.py | 106 +++--------------------- server/app/models.py | 1 + server/app/prep.py | 23 +++++ server/app/settings.py | 2 + server/app/tracks.py | 34 ++++++++ src/assets/css/BottomBar/BottomBar.scss | 31 ++++--- src/assets/icons/album.svg | 4 +- src/assets/icons/artist.svg | 4 +- src/assets/icons/folder.svg | 4 +- src/assets/icons/heart.svg | 4 +- src/assets/icons/home.svg | 4 +- src/assets/icons/next.svg | 5 +- src/assets/icons/no-results.svg | 1 - src/assets/icons/pause.svg | 5 +- src/assets/icons/play.svg | 4 +- src/assets/icons/playlist.svg | 4 +- src/assets/icons/plus.svg | 5 +- src/assets/icons/previous.svg | 5 +- src/assets/icons/queue.svg | 7 +- src/assets/icons/repeat.svg | 4 +- src/assets/icons/search.svg | 6 +- src/assets/icons/settings.svg | 4 +- src/components/BottomBar/BottomBar.vue | 11 ++- src/components/RightSideBar/Tabs.vue | 2 +- src/components/shared/HotKeys.vue | 20 +---- 28 files changed, 184 insertions(+), 179 deletions(-) create mode 100644 server/app/albums.py create mode 100644 server/app/prep.py create mode 100644 server/app/settings.py create mode 100644 server/app/tracks.py delete mode 100644 src/assets/icons/no-results.svg diff --git a/server/app/albums.py b/server/app/albums.py new file mode 100644 index 00000000..d29a333c --- /dev/null +++ b/server/app/albums.py @@ -0,0 +1,44 @@ +from typing import List +from app import models, instances, functions + +all_albums: List[models.Album] = [] + + +def create_all_albums() -> List[models.Album]: + """Creates album objects for all albums""" + albums: list[models.Album] = [] + + for album in instances.album_instance.get_all_albums(): + albums.append(models.Album(album)) + + return albums + + +def get_album_duration(album: List[models.Track]) -> int: + """ + Gets the duration of an album. + """ + + album_duration = 0 + + for track in album: + try: + album_duration += track.length + except AttributeError: + album_duration += track["length"] + + return album_duration + + +def get_album_image(album: list) -> str: + """ + Gets the image of an album. + """ + + for track in album: + img = functions.extract_thumb(track["filepath"]) + + if img is not None: + return img + + return functions.use_defaults() diff --git a/server/app/api.py b/server/app/api.py index 1f72c315..c3d9cb90 100644 --- a/server/app/api.py +++ b/server/app/api.py @@ -11,9 +11,6 @@ bp = Blueprint("api", __name__, url_prefix="") home_dir = helpers.home_dir -all_the_f_albums = helpers.create_all_albums() -all_the_f_music = helpers.create_all_tracks() - def initialize() -> None: """ @@ -26,6 +23,9 @@ def initialize() -> None: initialize() +all_the_f_albums = helpers.create_all_albums() +all_the_f_music = helpers.create_all_tracks() + @bp.route("/") def say_hi(): diff --git a/server/app/functions.py b/server/app/functions.py index 00fdf044..934dfc8b 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -8,6 +8,7 @@ from io import BytesIO import random import datetime import mutagen +import urllib import requests from mutagen.flac import MutagenError @@ -18,9 +19,7 @@ from PIL import Image from app import helpers from app import instances -from app import api -from app import models -import urllib +from app import api, settings def populate(): @@ -166,11 +165,11 @@ def extract_thumb(audio_file_path: str) -> str: """ Extracts the thumbnail from an audio file. Returns the path to the thumbnail. """ - webp_path = urllib.parse.quote_plus(audio_file_path.split("/")[-1] + ".webp") + webp_path = audio_file_path.split("/")[-1] + ".webp" img_path = os.path.join(helpers.app_dir, "images", "thumbnails", webp_path) if os.path.exists(img_path): - return webp_path + return urllib.parse.quote(webp_path) album_art = return_album_art(audio_file_path) @@ -188,7 +187,7 @@ def extract_thumb(audio_file_path: str) -> str: except: return None - return webp_path + return urllib.parse.quote(webp_path) else: return None @@ -321,7 +320,7 @@ def get_album_bio(title: str, albumartist: str): Returns the album bio for a given album. """ last_fm_url = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={}&artist={}&album={}&format=json".format( - helpers.LAST_FM_API_KEY, albumartist, title + settings.LAST_FM_API_KEY, albumartist, title ) try: diff --git a/server/app/helpers.py b/server/app/helpers.py index 7ea82e9b..ed91cc21 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -16,11 +16,10 @@ from PIL import Image from app import instances from app import functions from app import watchdoge -from app import models +from app import models, settings home_dir = os.path.expanduser("~") + "/" app_dir = os.path.join(home_dir, ".musicx") -LAST_FM_API_KEY = "762db7a44a9e6fb5585661f5f2bdf23a" def background(func): @@ -43,7 +42,7 @@ def reindex_tracks(): flag = False while flag is False: - # functions.populate() + functions.populate() functions.get_all_albums() # functions.populate_images() # functions.save_t_colors() @@ -104,14 +103,14 @@ def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]: return tracklist -def save_image(url: str, path: str) -> None: - """ - Saves an image from an url to a path. - """ +# def save_image(url: str, path: str) -> None: +# """ +# Saves an image from an url to a path. +# """ - response = requests.get(url) - img = Image.open(BytesIO(response.content)) - img.save(path, "JPEG") +# response = requests.get(url) +# img = Image.open(BytesIO(response.content)) +# img.save(path, "JPEG") def is_valid_file(filename: str) -> bool: @@ -125,62 +124,7 @@ def is_valid_file(filename: str) -> bool: return False -def create_config_dir() -> None: - """ - Creates the config directory if it doesn't exist. - """ - - _home_dir = os.path.expanduser("~") - config_folder = os.path.join(_home_dir, app_dir) - - dirs = ["", "images", "images/defaults", "images/artists", "images/thumbnails"] - - for _dir in dirs: - path = os.path.join(config_folder, _dir) - - try: - os.makedirs(path) - except FileExistsError: - pass - - os.chmod(path, 0o755) - - -def create_all_tracks() -> List[models.Track]: - """ - Gets all songs under the ~/ directory. - """ - print("Getting all songs...") - - tracks: list[models.Track] = [] - - for track in instances.songs_instance.get_all_songs(): - try: - os.chmod(track["filepath"], 0o755) - except FileNotFoundError: - instances.songs_instance.remove_song_by_filepath(track["filepath"]) - - album = instances.album_instance.get_album_by_name(track['album', track['albumartist']]) - - if album is None: - track['albumid'] = album['albumid'] - track['image'] = album['image'] - tracks.append(models.Track(track)) - - return tracks - - -def create_all_albums() -> List[models.Album]: - """Creates album objects for all albums""" - albums: list[models.Album] = [] - - for album in instances.album_instance.get_all_albums(): - albums.append(models.Album(album)) - - return albums - - -def extract_colors(image) -> list: +def extract_image_colors(image) -> list: """Extracts 2 of the most dominant colors from an image.""" try: colors = sorted(colorgram.extract(image, 2), key=lambda c: c.hsl.h) @@ -194,33 +138,3 @@ def extract_colors(image) -> list: formatted_colors.append(color) return formatted_colors - - -def get_album_duration(album: List[models.Track]) -> int: - """ - Gets the duration of an album. - """ - - album_duration = 0 - - for track in album: - try: - album_duration += track.length - except AttributeError: - album_duration += track["length"] - - return album_duration - - -def get_album_image(album: list) -> str: - """ - Gets the image of an album. - """ - - for track in album: - img = functions.extract_thumb(track["filepath"]) - - if img is not None: - return img - - return functions.use_defaults() diff --git a/server/app/models.py b/server/app/models.py index e5f31ba7..1244519a 100644 --- a/server/app/models.py +++ b/server/app/models.py @@ -253,6 +253,7 @@ class Track: def __init__(self, tags): self.trackid = tags["_id"]["$oid"] + self.albumid = tags["albumid"] self.title = tags["title"] self.artists = tags["artists"].split(", ") self.albumartist = tags["albumartist"] diff --git a/server/app/prep.py b/server/app/prep.py new file mode 100644 index 00000000..ffea0136 --- /dev/null +++ b/server/app/prep.py @@ -0,0 +1,23 @@ +import os +from app import settings + + +def create_config_dir() -> None: + """ + Creates the config directory if it doesn't exist. + """ + + _home_dir = os.path.expanduser("~") + config_folder = os.path.join(_home_dir, settings.CONFIG_FOLDER) + + dirs = ["", "images", "images/artists", "images/thumbnails"] + + for _dir in dirs: + path = os.path.join(config_folder, _dir) + + try: + os.makedirs(path) + except FileExistsError: + pass + + os.chmod(path, 0o755) diff --git a/server/app/settings.py b/server/app/settings.py new file mode 100644 index 00000000..53b0e8f4 --- /dev/null +++ b/server/app/settings.py @@ -0,0 +1,2 @@ +CONFIG_FOLDER = "alice" +LAST_FM_API_KEY = "762db7a44a9e6fb5585661f5f2bdf23a" diff --git a/server/app/tracks.py b/server/app/tracks.py new file mode 100644 index 00000000..c68499d7 --- /dev/null +++ b/server/app/tracks.py @@ -0,0 +1,34 @@ +import os +from typing import List +from app import models, instances + + +ALL_MUSIC: List[models.Track] = [] + + +def create_all_tracks() -> List[models.Track]: + """ + Gets all songs under the ~/ directory. + """ + print("Getting all songs...") + + tracks: list[models.Track] = [] + + for track in instances.songs_instance.get_all_songs(): + print(track) + try: + os.chmod(track["filepath"], 0o755) + except FileNotFoundError: + instances.songs_instance.remove_song_by_filepath(track["filepath"]) + + album = instances.album_instance.get_album_by_name( + track["album"], track["albumartist"] + ) + + track["albumid"] = album["_id"]["$oid"] + track["image"] = album["image"] + + tracks.append(models.Track(track)) + + ALL_MUSIC.clear() + ALL_MUSIC.extend(tracks) diff --git a/src/assets/css/BottomBar/BottomBar.scss b/src/assets/css/BottomBar/BottomBar.scss index e862a4c6..41ffb3ae 100644 --- a/src/assets/css/BottomBar/BottomBar.scss +++ b/src/assets/css/BottomBar/BottomBar.scss @@ -8,6 +8,18 @@ height: 100%; padding-right: $small; + .ctrl-btn { + height: 2rem; + width: 2rem; + background-size: 1.5rem !important; + cursor: pointer; + border-radius: 0.5rem; + + &:hover { + background-color: $red; + } + } + @include phone-only { grid-template-columns: 1fr 9.2rem; } @@ -76,28 +88,15 @@ align-items: center; gap: $small; - & > * { - height: 2rem; - width: 2rem; - background-size: 1.2rem !important; - background-position: 45% 50%; - cursor: pointer; - border-radius: 0.5rem; - - &:hover { - background-color: rgb(170, 50, 50); - } - } - - .heart { + #heart { background-image: url(../../icons/heart.svg); } - .add-to { + #add-to { background-image: url(../../icons/plus.svg); } - .repeat { + #repeat { background-image: url(../../icons/repeat.svg); } } diff --git a/src/assets/icons/album.svg b/src/assets/icons/album.svg index a3c051aa..345ba566 100644 --- a/src/assets/icons/album.svg +++ b/src/assets/icons/album.svg @@ -1 +1,3 @@ - + + + diff --git a/src/assets/icons/artist.svg b/src/assets/icons/artist.svg index 2b4b86f5..1ac9f0d9 100644 --- a/src/assets/icons/artist.svg +++ b/src/assets/icons/artist.svg @@ -1 +1,3 @@ - + + + diff --git a/src/assets/icons/folder.svg b/src/assets/icons/folder.svg index 556d1189..8827d6c4 100644 --- a/src/assets/icons/folder.svg +++ b/src/assets/icons/folder.svg @@ -1 +1,3 @@ - \ No newline at end of file + + + diff --git a/src/assets/icons/heart.svg b/src/assets/icons/heart.svg index d4668ca5..8d2427a5 100644 --- a/src/assets/icons/heart.svg +++ b/src/assets/icons/heart.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/assets/icons/home.svg b/src/assets/icons/home.svg index eb92d766..d1186bb2 100644 --- a/src/assets/icons/home.svg +++ b/src/assets/icons/home.svg @@ -1 +1,3 @@ - \ No newline at end of file + + + diff --git a/src/assets/icons/next.svg b/src/assets/icons/next.svg index d96118d7..f1c9d486 100644 --- a/src/assets/icons/next.svg +++ b/src/assets/icons/next.svg @@ -1,4 +1,3 @@ - - - + + diff --git a/src/assets/icons/no-results.svg b/src/assets/icons/no-results.svg deleted file mode 100644 index e7d4e406..00000000 --- a/src/assets/icons/no-results.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/assets/icons/pause.svg b/src/assets/icons/pause.svg index 19dce7a3..2b2b8d95 100644 --- a/src/assets/icons/pause.svg +++ b/src/assets/icons/pause.svg @@ -1,4 +1,3 @@ - - - + + diff --git a/src/assets/icons/play.svg b/src/assets/icons/play.svg index 47fcf5b3..ba1a89ce 100644 --- a/src/assets/icons/play.svg +++ b/src/assets/icons/play.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/assets/icons/playlist.svg b/src/assets/icons/playlist.svg index b7bc2556..e29bd4d2 100644 --- a/src/assets/icons/playlist.svg +++ b/src/assets/icons/playlist.svg @@ -1 +1,3 @@ - + + + diff --git a/src/assets/icons/plus.svg b/src/assets/icons/plus.svg index 71dca58d..412c6087 100644 --- a/src/assets/icons/plus.svg +++ b/src/assets/icons/plus.svg @@ -1,4 +1,3 @@ - - - + + diff --git a/src/assets/icons/previous.svg b/src/assets/icons/previous.svg index faebdeb9..a63081c7 100644 --- a/src/assets/icons/previous.svg +++ b/src/assets/icons/previous.svg @@ -1,4 +1,3 @@ - - - + + diff --git a/src/assets/icons/queue.svg b/src/assets/icons/queue.svg index a0dd923e..e29bd4d2 100644 --- a/src/assets/icons/queue.svg +++ b/src/assets/icons/queue.svg @@ -1,6 +1,3 @@ - - - - - + + diff --git a/src/assets/icons/repeat.svg b/src/assets/icons/repeat.svg index 6b914822..94a6be78 100644 --- a/src/assets/icons/repeat.svg +++ b/src/assets/icons/repeat.svg @@ -1,3 +1,3 @@ - - + + diff --git a/src/assets/icons/search.svg b/src/assets/icons/search.svg index 079bb6a4..124fe83a 100644 --- a/src/assets/icons/search.svg +++ b/src/assets/icons/search.svg @@ -1,5 +1,3 @@ - - - - + + diff --git a/src/assets/icons/settings.svg b/src/assets/icons/settings.svg index 91ffeedf..5d7f6679 100644 --- a/src/assets/icons/settings.svg +++ b/src/assets/icons/settings.svg @@ -1 +1,3 @@ - \ No newline at end of file + + + diff --git a/src/components/BottomBar/BottomBar.vue b/src/components/BottomBar/BottomBar.vue index f3422064..18d483c0 100644 --- a/src/components/BottomBar/BottomBar.vue +++ b/src/components/BottomBar/BottomBar.vue @@ -1,5 +1,5 @@
+
@@ -13,9 +13,9 @@ }}
-
-
-
+
+
+
@@ -32,7 +32,6 @@ import state from "../../composables/state"; import perks from "../../composables/perks"; import playAudio from "../../composables/playAudio"; -const current_pos = playAudio.current_time +const current_pos = playAudio.current_time; const formatSeconds = perks.formatSeconds; - diff --git a/src/components/RightSideBar/Tabs.vue b/src/components/RightSideBar/Tabs.vue index 61265052..b6846c03 100644 --- a/src/components/RightSideBar/Tabs.vue +++ b/src/components/RightSideBar/Tabs.vue @@ -59,7 +59,7 @@ const tabs = useTabStore() } .home { - background-image: url("../../assets/icons/dashboard.svg"); + background-image: url("../../assets/icons/home.svg"); } } diff --git a/src/components/shared/HotKeys.vue b/src/components/shared/HotKeys.vue index b0cf6a6a..6ea04781 100644 --- a/src/components/shared/HotKeys.vue +++ b/src/components/shared/HotKeys.vue @@ -1,12 +1,12 @@ @@ -27,24 +27,12 @@ const isPlaying = playAudio.playing; width: 100%; gap: $small; - & * { - height: 2rem; - width: 2rem; - background-size: 1.2rem !important; - cursor: pointer; - border-radius: 0.5rem; - - &:hover { - background-color: $pink; - } - } - #previous { background-image: url(../../assets/icons/previous.svg); } .play-pause { - background-image: url(../../assets/icons/play.svg); + background-image: url(../../assets/icons/play.svg) !important; } .isPlaying {