From 12c8406a0d459dc6500d1ab5f78834bbf94eedf2 Mon Sep 17 00:00:00 2001 From: geoffrey45 Date: Mon, 20 Jun 2022 09:49:16 +0300 Subject: [PATCH] add ping check - fix artist downloader function --- server/app/functions.py | 12 +++++++----- server/app/helpers.py | 19 ++++++++++++++++--- server/app/lib/folderslib.py | 4 ++-- server/app/lib/populate.py | 26 ++++++++++++++++++++++---- server/assets/default.webp | Bin 0 -> 4082 bytes server/start.sh | 2 +- 6 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 server/assets/default.webp diff --git a/server/app/functions.py b/server/app/functions.py index 7d5509bf..561760be 100644 --- a/server/app/functions.py +++ b/server/app/functions.py @@ -27,7 +27,9 @@ def reindex_tracks(): Populate() CreateAlbums() - CheckArtistImages()() + + if helpers.Ping()(): + CheckArtistImages()() time.sleep(60) @@ -73,7 +75,6 @@ class useImageDownloader: img.save(self.dest, format="webp") img.close() except requests.exceptions.ConnectionError: - print("🔴🔴🔴🔴🔴🔴🔴") time.sleep(5) @@ -102,7 +103,7 @@ class CheckArtistImages: """ img_path = ( - helpers.app_dir + settings.APP_DIR + "/images/artists/" + helpers.create_safe_name(artistname) + ".webp" @@ -115,14 +116,15 @@ class CheckArtistImages: if url is None: return - useImageDownloader(url, img_path)() def __call__(self): self.artists = helpers.Get.get_all_artists() with ThreadPoolExecutor() as pool: - pool.map(self.download_image, self.artists) + iter = pool.map(self.download_image, self.artists) + for i in iter: + pass print("Done fetching images") diff --git a/server/app/helpers.py b/server/app/helpers.py index ea11a63b..102e2b49 100644 --- a/server/app/helpers.py +++ b/server/app/helpers.py @@ -8,12 +8,12 @@ from datetime import datetime from typing import Dict, Set from typing import List +import requests + from app import models from app import settings from app import instances -app_dir = settings.APP_DIR - def background(func): """ @@ -73,6 +73,7 @@ def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]: return tracklist + def is_valid_file(filename: str) -> bool: """ Checks if a file is valid. Returns True if it is, False if it isn't. @@ -97,7 +98,7 @@ def check_artist_image(image: str) -> str: Checks if the artist image is valid. """ img_name = image.replace("/", "::") + ".webp" - + app_dir = settings.APP_DIR if not os.path.exists(os.path.join(app_dir, "images", "artists", img_name)): return use_memoji() else: @@ -194,3 +195,15 @@ class Get: """ p = instances.playlist_instance.get_all_playlists() return [models.Playlist(p) for p in p] + + +class Ping: + """Checks if there is a connection to the internet by pinging google.com""" + + @staticmethod + def __call__() -> bool: + try: + requests.get("https://google.com") + return True + except requests.exceptions.ConnectionError: + return False diff --git a/server/app/lib/folderslib.py b/server/app/lib/folderslib.py index 81217298..b5872736 100644 --- a/server/app/lib/folderslib.py +++ b/server/app/lib/folderslib.py @@ -14,11 +14,11 @@ class Dir: is_sym: bool -def get_folder_track_count(foldername: str) -> int: +def get_folder_track_count(path: str) -> int: """ Returns the number of files associated with a folder. """ - tracks = instances.tracks_instance.find_tracks_inside_path_regex(foldername) + tracks = instances.tracks_instance.find_tracks_inside_path_regex(path) return len(tracks) diff --git a/server/app/lib/populate.py b/server/app/lib/populate.py index 5ca7d31c..6fa2aead 100644 --- a/server/app/lib/populate.py +++ b/server/app/lib/populate.py @@ -89,10 +89,23 @@ class CreateAlbums: prealbums = self.filter_processed(self.db_albums, prealbums) print(f"📌 {len(prealbums)}") + s = time.time() albums = [] + for album in tqdm(prealbums, desc="Creating albums"): a = self.create_album(album) - albums.append(a) + if a is not None: + albums.append(a) + + # with ThreadPoolExecutor() as pool: + # iterator = pool.map(self.create_album, prealbums) + + # for i in iterator: + # if i is not None: + # albums.append(i) + + d = time.time() - s + Log(f"Created {len(albums)} albums in {d} seconds") if len(albums) > 0: instances.album_instance.insert_many(albums) @@ -131,15 +144,20 @@ class CreateAlbums: hash = album.hash album = {"image": None} + iter = 0 while album["image"] is None: track = UseBisection(self.db_tracks, "albumhash", [hash])()[0] if track is not None: + iter += 1 album = create_album(track) self.db_tracks.remove(track) else: album["image"] = hash - - album = Album(album) - return album + try: + album = Album(album) + return album + except KeyError: + print(f"📌 {iter}") + print(album) diff --git a/server/assets/default.webp b/server/assets/default.webp new file mode 100644 index 0000000000000000000000000000000000000000..d9795fa92300799db572c92fce72a617903e8cf7 GIT binary patch literal 4082 zcmVnbkPn%LHlqHFJRbQ*I|a_%KVuX7;XUvF&oCeV z{J?+z-~Qqc@E`x)u6_^ym!meaOj)c&*1JEpJC%fkU2*kK zG$blIAsAzw+8D)s9y?3;_N^n@Cpl((YOKlds>EG?_jflL;maXi|Gnk(krD7rNeh-& z=PT-OhRZS)Opfx))rqIm`@Gc|#p*x*`T4B~3ia<(*@*N1|NUNDZk+W-zyJSie5(}J z{{zWZq4FfnMEk&9P(9g4`~cKD)Tw==c2)MY#XtW!Yr5M*;N0%)dj2(QXXJg|p@mkz z*KF*|%XS%L3vxo?#4hE(M7^O7e7+l|?FN^>MJZ9g8vTm>fwvLL&hBp!`^X1lsMv-S z`Tq-Sd_fXmVI{q^qwcgjG}&nmm#y$ox$-lZSSSv0RUPXPSd9?cOGQT3OFj(1b6|d^ z_y7F$WnVG_cxwj z3V*yP^{!$>{t(80eL9CfYr(3v;YV>G3zL`_(+z8+gSgAxCPMb5D8Bj8OUYv?=Y*S_oPV&6(a%_Q^iT1 zu_+g?Vb04>ue>512Oghz=4AT z-@xNzZ>@mD2|pg(=_H5Sq0@?#u>oHK=ypTq^>wauTz0xsI}&@G33m^ciHW%n1~C6$ zPi3E*M~%a!M2fC2U~>S68zSa}iNeZ>U$bbEmF43Nly~E%#66C_onT8iE_~Kz&`s(v zGlN&cVz?{TbE#%QW-^q*YfBMp9H^0acD!<}OWRF_;$ACx^2{ev!$UCrk;Diq{K+*I|kk1bd{|--P}*7{`3rQCdYhBTB7c4ME=<3jd+$Py~OTM zHMlG_T0k^CyRj#R<*O@HYv{W|AR*-TJH&bUUS@9Uson`vyULLm*YzLlFQwZNCbI@R zR>`uYczHnbs4KCr=s@B6&gSPHnDozlk;gpOl%% zhBqXPJzdzoWgG>yFxY`dSbRIPc|9fBV!rY}&UVAWXM9VhZUhy6jV5p)5Hzg_r3USG zQ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