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