From d27c5b6b1b4116ac1ed6c69693237f75529883c3 Mon Sep 17 00:00:00 2001 From: Pierce Thompson Date: Wed, 3 Apr 2024 02:05:04 -0400 Subject: [PATCH] Match Genius' album path --- src/album.rs | 20 ++++++-------------- src/artist.rs | 4 ++-- templates/lyrics.html | 2 +- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/album.rs b/src/album.rs index 64fed2d..8983a01 100644 --- a/src/album.rs +++ b/src/album.rs @@ -2,9 +2,8 @@ use crate::genius::{self, GeniusAlbumResponse}; use crate::settings::{settings_from_req, Settings}; use crate::utils; use actix_web::HttpRequest; -use actix_web::{get, web, Responder, Result}; +use actix_web::{get, Responder, Result}; use askama::Template; -use serde::Deserialize; use crate::genius::GeniusAlbum; use crate::templates::template; @@ -16,18 +15,11 @@ struct AlbumTemplate { album: GeniusAlbum, } -#[derive(Debug, Deserialize)] -pub struct AlbumQuery { - path: String, -} - -#[get("/album")] -pub async fn album(req: HttpRequest, info: web::Query) -> Result { - let album_res = genius::extract_data::(&utils::ensure_path_prefix( - "albums", &info.path, - )) - .await?; - let mut album = album_res.album; +#[get("/albums/{name:.*}")] +pub async fn album(req: HttpRequest) -> Result { + let mut album = genius::extract_data::(req.path()) + .await? + .album; album.tracks = Some(genius::get_album_tracks(album.id).await?); diff --git a/src/artist.rs b/src/artist.rs index 168fc9b..c761270 100644 --- a/src/artist.rs +++ b/src/artist.rs @@ -11,7 +11,7 @@ use crate::templates::template; static GENIUS_IMAGE_URL: &str = "https://images.genius.com/"; static GENIUS_BASE_PATTERN: Lazy = lazy_regex!(r#"https?://\w*.?genius\.com/"#); -static GENIUS_ALBUMS_PATTERN: Lazy = lazy_regex!(r#"https?://\w*.?genius\.com/albums/"#); +static GENIUS_ALBUMS_PATTERN: Lazy = lazy_regex!(r#"https?://\w*.?genius\.com/"#); static GENIUS_ARTIST_PATTERN: Lazy = lazy_regex!(r#"https?://\w*.?genius\.com/"#); #[derive(Template)] @@ -50,7 +50,7 @@ fn rewrite_links(html: &str) -> String { GENIUS_IMAGE_URL, &format!("/api/image?url={}", GENIUS_IMAGE_URL), ); // Images - let html = GENIUS_ALBUMS_PATTERN.replace_all(&html, "/album?path=albums/"); // Albums + let html = GENIUS_ALBUMS_PATTERN.replace_all(&html, ""); // Albums let html = GENIUS_ARTIST_PATTERN.replace_all(&html, ""); // Artists let html = GENIUS_BASE_PATTERN.replace_all(&html, "/lyrics?path=/"); // Lyrics html.to_string() diff --git a/templates/lyrics.html b/templates/lyrics.html index 3ee913e..f9138a8 100644 --- a/templates/lyrics.html +++ b/templates/lyrics.html @@ -22,7 +22,7 @@

{% if song.album.is_some() %}

On - + {{ song.album.as_ref().unwrap().name|e }}