Restyled by yapf

This commit is contained in:
Restyled.io
2022-04-03 10:45:57 +00:00
committed by Mungai Geoffrey
parent dc683e6314
commit bb69ac1fc1
3 changed files with 15 additions and 19 deletions
+3 -3
View File
@@ -16,8 +16,7 @@ def send_track_file(trackid):
""" """
try: try:
filepath = [ filepath = [
file["filepath"] file["filepath"] for file in api.PRE_TRACKS
for file in api.PRE_TRACKS
if file["_id"]["$oid"] == trackid if file["_id"]["$oid"] == trackid
][0] ][0]
except (FileNotFoundError, IndexError): except (FileNotFoundError, IndexError):
@@ -32,4 +31,5 @@ def get_sample_track():
Returns a sample track object. Returns a sample track object.
""" """
return instances.songs_instance.get_song_by_album("Legends Never Die", "Juice WRLD") return instances.songs_instance.get_song_by_album("Legends Never Die",
"Juice WRLD")
+9 -13
View File
@@ -29,7 +29,6 @@ from progress.bar import Bar
# from pprint import pprint # from pprint import pprint
@helpers.background @helpers.background
def reindex_tracks(): def reindex_tracks():
""" """
@@ -62,7 +61,8 @@ def populate():
""" """
start = time.time() start = time.time()
s, files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"], full=True) s, files = helpers.run_fast_scandir(settings.HOME_DIR, [".flac", ".mp3"],
full=True)
_bar = Bar("Processing files", max=len(files)) _bar = Bar("Processing files", max=len(files))
@@ -86,11 +86,8 @@ def populate():
end = time.time() end = time.time()
print( print(
str(datetime.timedelta(seconds=round(end - start))) str(datetime.timedelta(seconds=round(end - start))) + " elapsed for " +
+ " elapsed for " str(len(files)) + " files")
+ str(len(files))
+ " files"
)
def fetch_image_path(artist: str) -> str or None: def fetch_image_path(artist: str) -> str or None:
@@ -125,9 +122,8 @@ def populate_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 = ( file_path = (helpers.app_dir + "/images/artists/" +
helpers.app_dir + "/images/artists/" + artist.replace("/", "::") + ".webp" 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)
@@ -358,8 +354,7 @@ def get_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)
@@ -368,7 +363,8 @@ def get_album_bio(title: str, albumartist: str):
return None return None
try: try:
bio = data["album"]["wiki"]["summary"].split('<a href="https://www.last.fm/')[0] bio = data["album"]["wiki"]["summary"].split(
'<a href="https://www.last.fm/')[0]
except KeyError: except KeyError:
bio = None bio = None
+3 -3
View File
@@ -46,7 +46,8 @@ def get_album_image(album: list) -> str:
""" """
for track in album: for track in album:
img_p = (track["album"] + track["albumartist"] + ".webp").replace("/", "::") img_p = (track["album"] + track["albumartist"] + ".webp").replace(
"/", "::")
img = functions.extract_thumb(track["filepath"], webp_path=img_p) img = functions.extract_thumb(track["filepath"], webp_path=img_p)
if img is not None: if img is not None:
@@ -84,8 +85,7 @@ def create_album(track) -> models.Album:
album["date"] = album_tracks[0]["date"] album["date"] = album_tracks[0]["date"]
album["artistimage"] = urllib.parse.quote_plus( album["artistimage"] = urllib.parse.quote_plus(
album_tracks[0]["albumartist"] + ".webp" album_tracks[0]["albumartist"] + ".webp")
)
album["image"] = get_album_image(album_tracks) album["image"] = get_album_image(album_tracks)