mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
add ping check
- fix artist downloader function
This commit is contained in:
@@ -27,6 +27,8 @@ def reindex_tracks():
|
|||||||
|
|
||||||
Populate()
|
Populate()
|
||||||
CreateAlbums()
|
CreateAlbums()
|
||||||
|
|
||||||
|
if helpers.Ping()():
|
||||||
CheckArtistImages()()
|
CheckArtistImages()()
|
||||||
|
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
@@ -73,7 +75,6 @@ class useImageDownloader:
|
|||||||
img.save(self.dest, format="webp")
|
img.save(self.dest, format="webp")
|
||||||
img.close()
|
img.close()
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
print("🔴🔴🔴🔴🔴🔴🔴")
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ class CheckArtistImages:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
img_path = (
|
img_path = (
|
||||||
helpers.app_dir
|
settings.APP_DIR
|
||||||
+ "/images/artists/"
|
+ "/images/artists/"
|
||||||
+ helpers.create_safe_name(artistname)
|
+ helpers.create_safe_name(artistname)
|
||||||
+ ".webp"
|
+ ".webp"
|
||||||
@@ -115,14 +116,15 @@ class CheckArtistImages:
|
|||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
useImageDownloader(url, img_path)()
|
useImageDownloader(url, img_path)()
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
self.artists = helpers.Get.get_all_artists()
|
self.artists = helpers.Get.get_all_artists()
|
||||||
|
|
||||||
with ThreadPoolExecutor() as pool:
|
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")
|
print("Done fetching images")
|
||||||
|
|
||||||
|
|||||||
+16
-3
@@ -8,12 +8,12 @@ from datetime import datetime
|
|||||||
from typing import Dict, Set
|
from typing import Dict, Set
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from app import models
|
from app import models
|
||||||
from app import settings
|
from app import settings
|
||||||
from app import instances
|
from app import instances
|
||||||
|
|
||||||
app_dir = settings.APP_DIR
|
|
||||||
|
|
||||||
|
|
||||||
def background(func):
|
def background(func):
|
||||||
"""
|
"""
|
||||||
@@ -73,6 +73,7 @@ def remove_duplicates(tracklist: List[models.Track]) -> List[models.Track]:
|
|||||||
|
|
||||||
return tracklist
|
return tracklist
|
||||||
|
|
||||||
|
|
||||||
def is_valid_file(filename: str) -> bool:
|
def is_valid_file(filename: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Checks if a file is valid. Returns True if it is, False if it isn't.
|
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.
|
Checks if the artist image is valid.
|
||||||
"""
|
"""
|
||||||
img_name = image.replace("/", "::") + ".webp"
|
img_name = image.replace("/", "::") + ".webp"
|
||||||
|
app_dir = settings.APP_DIR
|
||||||
if not os.path.exists(os.path.join(app_dir, "images", "artists", img_name)):
|
if not os.path.exists(os.path.join(app_dir, "images", "artists", img_name)):
|
||||||
return use_memoji()
|
return use_memoji()
|
||||||
else:
|
else:
|
||||||
@@ -194,3 +195,15 @@ class Get:
|
|||||||
"""
|
"""
|
||||||
p = instances.playlist_instance.get_all_playlists()
|
p = instances.playlist_instance.get_all_playlists()
|
||||||
return [models.Playlist(p) for p in p]
|
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
|
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.
|
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)
|
return len(tracks)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,11 +89,24 @@ class CreateAlbums:
|
|||||||
prealbums = self.filter_processed(self.db_albums, prealbums)
|
prealbums = self.filter_processed(self.db_albums, prealbums)
|
||||||
print(f"📌 {len(prealbums)}")
|
print(f"📌 {len(prealbums)}")
|
||||||
|
|
||||||
|
s = time.time()
|
||||||
albums = []
|
albums = []
|
||||||
|
|
||||||
for album in tqdm(prealbums, desc="Creating albums"):
|
for album in tqdm(prealbums, desc="Creating albums"):
|
||||||
a = self.create_album(album)
|
a = self.create_album(album)
|
||||||
|
if a is not None:
|
||||||
albums.append(a)
|
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:
|
if len(albums) > 0:
|
||||||
instances.album_instance.insert_many(albums)
|
instances.album_instance.insert_many(albums)
|
||||||
|
|
||||||
@@ -131,15 +144,20 @@ class CreateAlbums:
|
|||||||
hash = album.hash
|
hash = album.hash
|
||||||
|
|
||||||
album = {"image": None}
|
album = {"image": None}
|
||||||
|
iter = 0
|
||||||
|
|
||||||
while album["image"] is None:
|
while album["image"] is None:
|
||||||
track = UseBisection(self.db_tracks, "albumhash", [hash])()[0]
|
track = UseBisection(self.db_tracks, "albumhash", [hash])()[0]
|
||||||
|
|
||||||
if track is not None:
|
if track is not None:
|
||||||
|
iter += 1
|
||||||
album = create_album(track)
|
album = create_album(track)
|
||||||
self.db_tracks.remove(track)
|
self.db_tracks.remove(track)
|
||||||
else:
|
else:
|
||||||
album["image"] = hash
|
album["image"] = hash
|
||||||
|
try:
|
||||||
album = Album(album)
|
album = Album(album)
|
||||||
return album
|
return album
|
||||||
|
except KeyError:
|
||||||
|
print(f"📌 {iter}")
|
||||||
|
print(album)
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
+1
-1
@@ -8,7 +8,7 @@ gpath=$(poetry run which gunicorn)
|
|||||||
while getopts ':s' opt; do
|
while getopts ':s' opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
s)
|
s)
|
||||||
echo "🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴🔴"
|
echo "Starting Alice server"
|
||||||
cd "./app"
|
cd "./app"
|
||||||
"$gpath" -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" &
|
"$gpath" -b 0.0.0.0:9877 -w 4 --threads=2 "imgserver:app" &
|
||||||
cd ../
|
cd ../
|
||||||
|
|||||||
Reference in New Issue
Block a user