mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-24 18:40:05 +00:00
add ping check
- fix artist downloader function
This commit is contained in:
parent
3cf44759b5
commit
12c8406a0d
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
BIN
server/assets/default.webp
Normal file
BIN
server/assets/default.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.0 KiB |
@ -8,7 +8,7 @@ gpath=$(poetry run which gunicorn)
|
||||
while getopts ':s' opt; do
|
||||
case $opt in
|
||||
s)
|
||||
echo "🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴"
|
||||
echo "Starting Alice server"
|
||||
cd "./app"
|
||||
"$gpath" -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" &
|
||||
cd ../
|
||||
|
Loading…
x
Reference in New Issue
Block a user