mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
fix merge conflict
This commit is contained in:
+3
-2
@@ -59,7 +59,8 @@ def rebuild_store(db_dirs: list[str]):
|
||||
|
||||
try:
|
||||
populate.Populate(instance_key=instance_key)
|
||||
except populate.PopulateCancelledError:
|
||||
except populate.PopulateCancelledError as e:
|
||||
print(e)
|
||||
reload_everything(instance_key)
|
||||
return
|
||||
|
||||
@@ -68,7 +69,7 @@ def rebuild_store(db_dirs: list[str]):
|
||||
log.info("Rebuilding library... ✅")
|
||||
|
||||
|
||||
# I freaking don't know what this function does anymore
|
||||
# I freaking don't know what this function does anymore
|
||||
def finalize(new_: list[str], removed_: list[str], db_dirs_: list[str]):
|
||||
"""
|
||||
Params:
|
||||
|
||||
+2
-2
@@ -57,8 +57,8 @@ class HandleArgs:
|
||||
value = settings.Keys.get(key)
|
||||
|
||||
if not value:
|
||||
log.error(f"ERROR: {key} not set in environment")
|
||||
sys.exit(0)
|
||||
log.error(f"WARNING: {key} not set in environment")
|
||||
#sys.exit(0)
|
||||
|
||||
lines.append(f'{key} = "{value}"\n')
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ class Populate:
|
||||
log.error(
|
||||
"Internet connection lost. Downloading artist images suspended."
|
||||
)
|
||||
log.error(e) # REVIEW More informations = good
|
||||
else:
|
||||
log.warning(f"No internet connection. Downloading artist images suspended!")
|
||||
|
||||
@@ -113,6 +114,7 @@ class Populate:
|
||||
|
||||
if has_connection():
|
||||
try:
|
||||
print("Attempting to download similar artists...")
|
||||
FetchSimilarArtistsLastFM(instance_key)
|
||||
except PopulateCancelledError as e:
|
||||
log.warn(e)
|
||||
@@ -135,6 +137,7 @@ class Populate:
|
||||
unmodified_paths.add(track.filepath)
|
||||
continue
|
||||
except (FileNotFoundError, OSError) as e:
|
||||
log.warning(e) # REVIEW More informations = good
|
||||
TrackStore.remove_track_obj(track)
|
||||
remove_tracks_by_filepaths(track.filepath)
|
||||
|
||||
@@ -286,6 +289,7 @@ def save_similar_artists(_map: tuple[str, Artist]):
|
||||
instance_key, artist = _map
|
||||
|
||||
if POPULATE_KEY != instance_key:
|
||||
print("Warning: Populate key changed")
|
||||
raise PopulateCancelledError(
|
||||
"'FetchSimilarArtistsLastFM': Populate key changed"
|
||||
)
|
||||
@@ -321,6 +325,7 @@ class FetchSimilarArtistsLastFM:
|
||||
|
||||
with ThreadPoolExecutor(max_workers=CPU_COUNT) as executor:
|
||||
try:
|
||||
print("Processing similar artists")
|
||||
results = list(
|
||||
tqdm(
|
||||
executor.map(save_similar_artists, key_artist_map),
|
||||
|
||||
@@ -6,7 +6,7 @@ import urllib.parse
|
||||
import requests
|
||||
from requests import ConnectionError, HTTPError, ReadTimeout
|
||||
|
||||
from app import settings
|
||||
#from app import settings
|
||||
from app.utils.hashing import create_hash
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ def fetch_similar_artists(name: str):
|
||||
"""
|
||||
url = f"https://kerve.last.fm/kerve/similarartists?artist={urllib.parse.quote_plus(name, safe='')}&autocorrect=1&tracks=1&image_size=large&limit=250&format=json"
|
||||
|
||||
# REVIEW This is the old way of doing it. The new way is to use the Kerve API.
|
||||
#url = f"https://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist={urllib.parse.quote_plus(name, safe='')}&api_key={settings.Keys.LASTFM_API_KEY}&format=json&limit=250"
|
||||
# TODO Cannot be tested due to PR message
|
||||
url = f"https://kerve.last.fm/kerve/similarartists?artist={urllib.parse.quote_plus(name, safe='')}&autocorrect=1&tracks=1&image_size=large&limit=250&format=json"
|
||||
try:
|
||||
response = requests.get(url, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
@@ -275,6 +275,9 @@ class Keys:
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
# TODO Remove this. Just an handy flag to test the app without the API key
|
||||
# IS_BUILD = True
|
||||
|
||||
if IS_BUILD:
|
||||
cls.SWINGMUSIC_APP_VERSION = configs.SWINGMUSIC_APP_VERSION
|
||||
cls.GIT_LATEST_COMMIT_HASH = configs.GIT_LATEST_COMMIT_HASH
|
||||
|
||||
@@ -32,5 +32,11 @@ def create_hash(*args: str, decode=False, limit=10) -> str:
|
||||
str_ = unidecode(str_)
|
||||
|
||||
str_ = str_.encode("utf-8")
|
||||
str_ = hashlib.sha256(str_).hexdigest()
|
||||
return str_[-limit:]
|
||||
str_ = hashlib.sha1(str_).hexdigest()
|
||||
# REVIEW Switched to sha1 hashlib.sha256(str_).hexdigest()
|
||||
|
||||
# REVIEW Take the first limit/2 and last limit/2 characters
|
||||
# This is to avoid collisions
|
||||
return str_[:limit // 2] + str_[-limit // 2:] if limit % 2 == 0 else str_[:limit // 2] + str_[-limit // 2 - 1:]
|
||||
|
||||
# return str_[-limit:]
|
||||
|
||||
@@ -3,10 +3,12 @@ import socket as Socket
|
||||
|
||||
def has_connection(host="google.it", port=80, timeout=3):
|
||||
"""
|
||||
# REVIEW Was:
|
||||
Host: 8.8.8.8 (google-public-dns-a.google.com)
|
||||
OpenPort: 53/tcp
|
||||
Service: domain (DNS/TCP)
|
||||
"""
|
||||
|
||||
try:
|
||||
Socket.setdefaulttimeout(timeout)
|
||||
Socket.socket(Socket.AF_INET, Socket.SOCK_STREAM).connect((host, port))
|
||||
|
||||
Reference in New Issue
Block a user