mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
replace progress.bar with tqdm
This commit is contained in:
@@ -44,7 +44,8 @@ def get_album_tracks():
|
|||||||
artist = data["artist"]
|
artist = data["artist"]
|
||||||
|
|
||||||
songs = trackslib.get_album_tracks(album, artist)
|
songs = trackslib.get_album_tracks(album, artist)
|
||||||
index = albumslib.find_album(album, artist)
|
albumhash = helpers.create_album_hash(album, artist)
|
||||||
|
index = albumslib.find_album(api.ALBUMS, albumhash)
|
||||||
album = api.ALBUMS[index]
|
album = api.ALBUMS[index]
|
||||||
|
|
||||||
album.count = len(songs)
|
album.count = len(songs)
|
||||||
|
|||||||
+12
-5
@@ -14,6 +14,8 @@ from app.lib.populate import Populate
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from progress.bar import Bar
|
from progress.bar import Bar
|
||||||
|
|
||||||
|
from app.lib.trackslib import create_all_tracks
|
||||||
|
|
||||||
|
|
||||||
@helpers.background
|
@helpers.background
|
||||||
def reindex_tracks():
|
def reindex_tracks():
|
||||||
@@ -41,6 +43,10 @@ def populate():
|
|||||||
pop = Populate()
|
pop = Populate()
|
||||||
pop.run()
|
pop.run()
|
||||||
|
|
||||||
|
tracks = create_all_tracks()
|
||||||
|
api.TRACKS.clear()
|
||||||
|
api.TRACKS.extend(tracks)
|
||||||
|
|
||||||
|
|
||||||
@helpers.background
|
@helpers.background
|
||||||
def fetch_image_path(artist: str) -> str or None:
|
def fetch_image_path(artist: str) -> str or None:
|
||||||
@@ -76,8 +82,9 @@ def fetch_artist_images():
|
|||||||
|
|
||||||
_bar = Bar("Processing images", max=len(artists))
|
_bar = Bar("Processing images", max=len(artists))
|
||||||
for artist in artists:
|
for artist in artists:
|
||||||
file_path = (helpers.app_dir + "/images/artists/" +
|
file_path = (
|
||||||
artist.replace("/", "::") + ".webp")
|
helpers.app_dir + "/images/artists/" + artist.replace("/", "::") + ".webp"
|
||||||
|
)
|
||||||
|
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
img_path = fetch_image_path(artist)
|
img_path = fetch_image_path(artist)
|
||||||
@@ -99,7 +106,8 @@ def fetch_album_bio(title: str, albumartist: str):
|
|||||||
Returns the album bio for a given album.
|
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(
|
last_fm_url = "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={}&artist={}&album={}&format=json".format(
|
||||||
settings.LAST_FM_API_KEY, albumartist, title)
|
settings.LAST_FM_API_KEY, albumartist, title
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(last_fm_url)
|
response = requests.get(last_fm_url)
|
||||||
@@ -108,8 +116,7 @@ def fetch_album_bio(title: str, albumartist: str):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bio = data["album"]["wiki"]["summary"].split(
|
bio = data["album"]["wiki"]["summary"].split('<a href="https://www.last.fm/')[0]
|
||||||
'<a href="https://www.last.fm/')[0]
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
bio = None
|
bio = None
|
||||||
|
|
||||||
|
|||||||
+18
-25
@@ -1,7 +1,6 @@
|
|||||||
"""
|
"""
|
||||||
This library contains all the functions related to albums.
|
This library contains all the functions related to albums.
|
||||||
"""
|
"""
|
||||||
from copy import deepcopy
|
|
||||||
import random
|
import random
|
||||||
import urllib
|
import urllib
|
||||||
from typing import List
|
from typing import List
|
||||||
@@ -12,7 +11,7 @@ from app import models
|
|||||||
from app.lib import taglib
|
from app.lib import taglib
|
||||||
from app.lib import trackslib
|
from app.lib import trackslib
|
||||||
from progress.bar import Bar
|
from progress.bar import Bar
|
||||||
|
from tqdm import tqdm
|
||||||
from app import helpers
|
from app import helpers
|
||||||
|
|
||||||
|
|
||||||
@@ -26,13 +25,9 @@ def get_all_albums() -> List[models.Album]:
|
|||||||
|
|
||||||
db_albums = instances.album_instance.get_all_albums()
|
db_albums = instances.album_instance.get_all_albums()
|
||||||
|
|
||||||
_bar = Bar("Creating albums", max=len(db_albums))
|
for album in tqdm(db_albums, desc="Creating albums"):
|
||||||
for album in db_albums:
|
|
||||||
aa = models.Album(album)
|
aa = models.Album(album)
|
||||||
albums.append(aa)
|
albums.append(aa)
|
||||||
_bar.next()
|
|
||||||
|
|
||||||
_bar.finish()
|
|
||||||
|
|
||||||
return albums
|
return albums
|
||||||
|
|
||||||
@@ -54,27 +49,23 @@ def create_everything() -> List[models.Track]:
|
|||||||
api.TRACKS.sort(key=lambda x: x.title)
|
api.TRACKS.sort(key=lambda x: x.title)
|
||||||
|
|
||||||
|
|
||||||
def find_album(albumtitle: str, artist: str) -> int or None:
|
def find_album(albums: List[models.Album], hash: str) -> int | None:
|
||||||
"""
|
"""
|
||||||
Finds an album by album title and artist.
|
Finds an album by album title and artist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
left = 0
|
left = 0
|
||||||
right = len(api.ALBUMS) - 1
|
right = len(albums) - 1
|
||||||
iter = 0
|
iter = 0
|
||||||
|
|
||||||
while left <= right:
|
while left <= right:
|
||||||
iter += 1
|
iter += 1
|
||||||
mid = (left + right) // 2
|
mid = (left + right) // 2
|
||||||
hash = helpers.create_album_hash(albumtitle, artist)
|
|
||||||
|
|
||||||
try:
|
if albums[mid].hash == hash:
|
||||||
if api.ALBUMS[mid].hash == hash:
|
|
||||||
return mid
|
return mid
|
||||||
except:
|
|
||||||
print(api.ALBUMS[mid])
|
|
||||||
|
|
||||||
if api.ALBUMS[mid].hash < hash:
|
if albums[mid].hash < hash:
|
||||||
left = mid + 1
|
left = mid + 1
|
||||||
else:
|
else:
|
||||||
right = mid - 1
|
right = mid - 1
|
||||||
@@ -136,9 +127,9 @@ class GetAlbumTracks:
|
|||||||
and album artist.
|
and album artist.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, album: str, artist: str) -> None:
|
def __init__(self, tracklist: list, albumhash: str) -> None:
|
||||||
self.hash = helpers.create_album_hash(album, artist)
|
self.hash = albumhash
|
||||||
self.tracks = api.DB_TRACKS
|
self.tracks = tracklist
|
||||||
self.tracks.sort(key=lambda x: x["albumhash"])
|
self.tracks.sort(key=lambda x: x["albumhash"])
|
||||||
|
|
||||||
def find_tracks(self):
|
def find_tracks(self):
|
||||||
@@ -151,7 +142,8 @@ class GetAlbumTracks:
|
|||||||
self.tracks.remove(track)
|
self.tracks.remove(track)
|
||||||
index = trackslib.find_track(self.tracks, self.hash)
|
index = trackslib.find_track(self.tracks, self.hash)
|
||||||
|
|
||||||
api.DB_TRACKS.extend(tracks)
|
# self.tracks.extend(tracks)
|
||||||
|
# self.tracks.sort(key=lambda x: x["albumhash"])
|
||||||
return tracks
|
return tracks
|
||||||
|
|
||||||
|
|
||||||
@@ -159,7 +151,7 @@ def get_album_tracks(album: str, artist: str) -> List:
|
|||||||
return GetAlbumTracks(album, artist).find_tracks()
|
return GetAlbumTracks(album, artist).find_tracks()
|
||||||
|
|
||||||
|
|
||||||
def create_album(track) -> models.Album:
|
def create_album(track: dict, tracklist: list) -> models.Album:
|
||||||
"""
|
"""
|
||||||
Generates and returns an album object from a track object.
|
Generates and returns an album object from a track object.
|
||||||
"""
|
"""
|
||||||
@@ -168,15 +160,16 @@ def create_album(track) -> models.Album:
|
|||||||
"artist": track["albumartist"],
|
"artist": track["albumartist"],
|
||||||
}
|
}
|
||||||
|
|
||||||
album_tracks = get_album_tracks(album["title"], album["artist"])
|
albumhash = helpers.create_album_hash(album["title"], album["artist"])
|
||||||
|
album_tracks = get_album_tracks(tracklist, albumhash)
|
||||||
|
|
||||||
|
if len(album_tracks) == 0:
|
||||||
|
return None
|
||||||
|
|
||||||
album["date"] = album_tracks[0]["date"]
|
album["date"] = album_tracks[0]["date"]
|
||||||
|
|
||||||
album["artistimage"] = urllib.parse.quote_plus(
|
|
||||||
album_tracks[0]["albumartist"] + ".webp"
|
|
||||||
)
|
|
||||||
|
|
||||||
album["image"] = get_album_image(album_tracks)
|
album["image"] = get_album_image(album_tracks)
|
||||||
|
# album["image"] = "".join(x for x in albumhash if x not in "\/:*?<>|")
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import time
|
|||||||
from typing import List
|
from typing import List
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
from app import api
|
from app import api
|
||||||
from app import helpers
|
from app import helpers
|
||||||
from app import models
|
from app import models
|
||||||
@@ -34,15 +36,11 @@ def create_folder(foldername: str) -> models.Folder:
|
|||||||
|
|
||||||
def create_all_folders() -> Set[models.Folder]:
|
def create_all_folders() -> Set[models.Folder]:
|
||||||
folders: List[models.Folder] = []
|
folders: List[models.Folder] = []
|
||||||
_bar = Bar("Creating folders", max=len(api.VALID_FOLDERS))
|
|
||||||
|
|
||||||
for foldername in api.VALID_FOLDERS:
|
for foldername in tqdm(api.VALID_FOLDERS, desc="Creating folders"):
|
||||||
folder = create_folder(foldername)
|
folder = create_folder(foldername)
|
||||||
folders.append(folder)
|
folders.append(folder)
|
||||||
|
|
||||||
_bar.next()
|
|
||||||
_bar.finish()
|
|
||||||
|
|
||||||
return folders
|
return folders
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from app.exceptions import TrackExistsInPlaylist
|
|||||||
from app import helpers
|
from app import helpers
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass(slots=True)
|
||||||
class Track:
|
class Track:
|
||||||
"""
|
"""
|
||||||
Track class
|
Track class
|
||||||
@@ -46,7 +46,7 @@ class Track:
|
|||||||
self.image = tags["image"]
|
self.image = tags["image"]
|
||||||
self.tracknumber = tags["tracknumber"]
|
self.tracknumber = tags["tracknumber"]
|
||||||
self.discnumber = tags["discnumber"]
|
self.discnumber = tags["discnumber"]
|
||||||
self.albumhash = tags['albumhash']
|
self.albumhash = tags["albumhash"]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -58,7 +58,6 @@ class Album:
|
|||||||
title: str
|
title: str
|
||||||
artist: str
|
artist: str
|
||||||
date: int
|
date: int
|
||||||
artistimage: str
|
|
||||||
image: str
|
image: str
|
||||||
hash: str
|
hash: str
|
||||||
count: int = 0
|
count: int = 0
|
||||||
@@ -68,10 +67,14 @@ class Album:
|
|||||||
self.title = tags["title"]
|
self.title = tags["title"]
|
||||||
self.artist = tags["artist"]
|
self.artist = tags["artist"]
|
||||||
self.date = tags["date"]
|
self.date = tags["date"]
|
||||||
self.artistimage = tags["artistimage"]
|
|
||||||
self.image = tags["image"]
|
self.image = tags["image"]
|
||||||
self.hash = helpers.create_album_hash(self.title, self.artist)
|
self.hash = helpers.create_album_hash(self.title, self.artist)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.hash = tags["albumhash"]
|
||||||
|
except KeyError:
|
||||||
|
self.hash = helpers.create_album_hash(self.title, self.artist)
|
||||||
|
|
||||||
|
|
||||||
def get_p_track(ptrack):
|
def get_p_track(ptrack):
|
||||||
for track in api.TRACKS:
|
for track in api.TRACKS:
|
||||||
|
|||||||
@@ -3,13 +3,15 @@ Contains default configs
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import multiprocessing
|
||||||
|
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
CONFIG_FOLDER = ".alice"
|
CONFIG_FOLDER = ".alice"
|
||||||
HOME_DIR = os.path.expanduser("~")
|
HOME_DIR = os.path.expanduser("~")
|
||||||
APP_DIR = os.path.join(HOME_DIR, CONFIG_FOLDER)
|
APP_DIR = os.path.join(HOME_DIR, CONFIG_FOLDER)
|
||||||
THUMBS_PATH = os.path.join(APP_DIR, "images", "thumbnails")
|
THUMBS_PATH = os.path.join(APP_DIR, "images", "thumbnails")
|
||||||
|
TEST_DIR = "/home/cwilvx/Music/Link to Music/Chill"
|
||||||
# URL
|
# URL
|
||||||
IMG_BASE_URI = "http://127.0.0.1:8900/images/"
|
IMG_BASE_URI = "http://127.0.0.1:8900/images/"
|
||||||
IMG_ARTIST_URI = IMG_BASE_URI + "artists/"
|
IMG_ARTIST_URI = IMG_BASE_URI + "artists/"
|
||||||
@@ -34,6 +36,8 @@ P_COLORS = [
|
|||||||
"rgb(141, 11, 2)",
|
"rgb(141, 11, 2)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CPU_COUNT = multiprocessing.cpu_count()
|
||||||
|
|
||||||
class logger:
|
class logger:
|
||||||
enable = True
|
enable = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user