misc
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ notifier.py
|
||||
youtube*
|
||||
playlist_creator.py
|
||||
artist_genre_tag.py
|
||||
pg_migrate_lyrics.py
|
||||
uv.lock
|
||||
pyproject.toml
|
||||
mypy.ini
|
||||
|
@ -45,14 +45,14 @@ class Misc(FastAPI):
|
||||
handler,
|
||||
methods=["GET"],
|
||||
include_in_schema=True,
|
||||
dependencies=[Depends(RateLimiter(times=2, seconds=5))],
|
||||
dependencies=[Depends(RateLimiter(times=10, seconds=2))],
|
||||
)
|
||||
|
||||
app.add_api_route(
|
||||
"/misc/upload_activity_image",
|
||||
self.upload_activity_image,
|
||||
methods=["POST"],
|
||||
dependencies=[Depends(RateLimiter(times=2, seconds=5))],
|
||||
dependencies=[Depends(RateLimiter(times=10, seconds=2))],
|
||||
)
|
||||
|
||||
logging.debug("Loading NaaS reasons")
|
||||
|
@ -50,7 +50,8 @@ class Radio(FastAPI):
|
||||
for endpoint, handler in self.endpoints.items():
|
||||
app.add_api_route(
|
||||
f"/{endpoint}", handler, methods=["POST"], include_in_schema=True,
|
||||
dependencies=[Depends(RateLimiter(times=10, seconds=5))],
|
||||
dependencies=[Depends(
|
||||
RateLimiter(times=10, seconds=2))] if not endpoint == "radio/np" else None,
|
||||
)
|
||||
|
||||
# NOTE: Not in loop because method is GET for this endpoint
|
||||
|
@ -28,7 +28,7 @@ class Genius:
|
||||
self.genius_url: str = private.GENIUS_URL
|
||||
self.genius_search_url: str = f"{self.genius_url}api/search/song?q="
|
||||
self.headers: dict = common.SCRAPE_HEADERS
|
||||
self.timeout = ClientTimeout(connect=3, sock_read=3)
|
||||
self.timeout = ClientTimeout(connect=5, sock_read=5)
|
||||
self.datautils = utils.DataUtils()
|
||||
self.matcher = utils.TrackMatcher()
|
||||
self.cache = cache.Cache()
|
||||
@ -105,6 +105,7 @@ class Genius:
|
||||
best_match: tuple = self.matcher.find_best_match(
|
||||
input_track=searched, candidate_tracks=to_scrape
|
||||
)
|
||||
logging.info("To scrape: %s", to_scrape)
|
||||
((scrape_stub, track), confidence) = best_match
|
||||
scrape_url: str = f"{self.genius_url}{scrape_stub[1:]}"
|
||||
|
||||
|
@ -23,7 +23,7 @@ class LRCLib:
|
||||
self.label: str = "LRCLib"
|
||||
self.lrclib_url: str = "https://lrclib.net/api/search"
|
||||
self.headers: dict = common.SCRAPE_HEADERS
|
||||
self.timeout = ClientTimeout(connect=2, sock_read=3)
|
||||
self.timeout = ClientTimeout(connect=3, sock_read=8)
|
||||
self.datautils = utils.DataUtils()
|
||||
self.matcher = utils.TrackMatcher()
|
||||
self.cache = cache.Cache()
|
||||
|
@ -50,19 +50,19 @@ class RadioUtil:
|
||||
"/usr/local/share", "sqlite_dbs", "track_album_art.db"
|
||||
)
|
||||
self.playback_genres: list[str] = [
|
||||
"post-hardcore",
|
||||
"post hardcore",
|
||||
"metalcore",
|
||||
"deathcore",
|
||||
"edm",
|
||||
"electronic",
|
||||
# "metal",
|
||||
# # "hip hop",
|
||||
# "metalcore",
|
||||
# "deathcore",
|
||||
# # "edm",
|
||||
# "electronic",
|
||||
# "hard rock",
|
||||
# "rock",
|
||||
# "ska",
|
||||
# "post punk",
|
||||
# "post-punk",
|
||||
# "pop punk",
|
||||
# "pop-punk",
|
||||
# # "ska",
|
||||
# # "post punk",
|
||||
# # "post-punk",
|
||||
# # "pop punk",
|
||||
# # "pop-punk",
|
||||
]
|
||||
self.active_playlist: list[dict] = []
|
||||
self.playlist_loaded: bool = False
|
||||
@ -321,7 +321,7 @@ class RadioUtil:
|
||||
if not res:
|
||||
artist_genre[artist] = "N/A"
|
||||
continue
|
||||
artist_genre[artist] = res["genre"]
|
||||
artist_genre[artist] = res["genre"].title()
|
||||
time_end: float = time.time()
|
||||
logging.info(f"Time taken: {time_end - time_start}")
|
||||
return artist_genre
|
||||
@ -377,7 +377,7 @@ class RadioUtil:
|
||||
"artist": double_space.sub(" ", r["artist"]).strip(),
|
||||
"song": double_space.sub(" ", r["song"]).strip(),
|
||||
"album": double_space.sub(" ", r["album"]).strip(),
|
||||
"genre": r["genre"],
|
||||
"genre": r["genre"].title() if r["genre"] else "Not Found",
|
||||
"artistsong": double_space.sub(
|
||||
" ", r["artistdashsong"]
|
||||
).strip(),
|
||||
@ -419,19 +419,25 @@ class RadioUtil:
|
||||
if self.playback_genres:
|
||||
new_playlist: list[dict] = []
|
||||
logging.info("Limiting playback genres")
|
||||
# for item in self.active_playlist:
|
||||
# matched_genre: bool = False
|
||||
# item_genres: str = item.get("genre", "").strip().lower()
|
||||
# for genre in self.playback_genres:
|
||||
# genre = genre.strip().lower()
|
||||
# if genre in item_genres:
|
||||
# if item in new_playlist:
|
||||
# continue
|
||||
# new_playlist.append(item)
|
||||
# matched_genre = True
|
||||
# continue
|
||||
# if matched_genre:
|
||||
# continue
|
||||
for item in self.active_playlist:
|
||||
matched_genre: bool = False
|
||||
item_genres: str = item.get("genre", "").strip().lower()
|
||||
for genre in self.playback_genres:
|
||||
genre = genre.strip().lower()
|
||||
if genre in item_genres:
|
||||
if item in new_playlist:
|
||||
continue
|
||||
item_genres = item.get("genre", "").strip().lower()
|
||||
# Check if any genre matches and item isn't already in new_playlist
|
||||
if any(genre.strip().lower() in item_genres for genre in self.playback_genres):
|
||||
if item not in new_playlist:
|
||||
new_playlist.append(item)
|
||||
matched_genre = True
|
||||
continue
|
||||
if matched_genre:
|
||||
continue
|
||||
self.active_playlist = new_playlist
|
||||
logging.info(
|
||||
"%s items remain for playback after filtering",
|
||||
|
Reference in New Issue
Block a user