Skip to content

Commit

Permalink
Match Genius' album path
Browse files Browse the repository at this point in the history
  • Loading branch information
Insprill committed Apr 3, 2024
1 parent 98527ef commit d27c5b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
20 changes: 6 additions & 14 deletions src/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<AlbumQuery>) -> Result<impl Responder> {
let album_res = genius::extract_data::<GeniusAlbumResponse>(&utils::ensure_path_prefix(
"albums", &info.path,
))
.await?;
let mut album = album_res.album;
#[get("/albums/{name:.*}")]
pub async fn album(req: HttpRequest) -> Result<impl Responder> {
let mut album = genius::extract_data::<GeniusAlbumResponse>(req.path())
.await?
.album;

album.tracks = Some(genius::get_album_tracks(album.id).await?);

Expand Down
4 changes: 2 additions & 2 deletions src/artist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::templates::template;

static GENIUS_IMAGE_URL: &str = "https://images.genius.com/";
static GENIUS_BASE_PATTERN: Lazy<Regex> = lazy_regex!(r#"https?://\w*.?genius\.com/"#);
static GENIUS_ALBUMS_PATTERN: Lazy<Regex> = lazy_regex!(r#"https?://\w*.?genius\.com/albums/"#);
static GENIUS_ALBUMS_PATTERN: Lazy<Regex> = lazy_regex!(r#"https?://\w*.?genius\.com/"#);
static GENIUS_ARTIST_PATTERN: Lazy<Regex> = lazy_regex!(r#"https?://\w*.?genius\.com/"#);

#[derive(Template)]
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion templates/lyrics.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</p>
{% if song.album.is_some() %}
<p class="album-name">On
<a href="album?path={{ utils::path_from_url(song.album.as_ref().unwrap().url)|urlencode }}">
<a href="/{{ utils::path_from_url(song.album.as_ref().unwrap().url)|urlencode }}">
<cite>{{ song.album.as_ref().unwrap().name|e }}</cite>
</a>
</p>
Expand Down

0 comments on commit d27c5b6

Please sign in to comment.