diff --git a/Cargo.lock b/Cargo.lock index dcdadd2..fa28252 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "android_system_properties" @@ -293,6 +293,7 @@ dependencies = [ "genius-rust", "owo-colors", "rand", + "reqwest", "serde", "serde_json", "tabled", diff --git a/Cargo.toml b/Cargo.toml index f58190a..94c04ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,8 @@ colored_json = "2.1.0" genius-rust = "0.1.1" owo-colors = "3.5.0" rand = "0.8.5" -serde = "1.0.144" +reqwest = { version = "0.11", features = ["json"] } +serde = { version = "1.0.144", features = ["derive"] } serde_json = "1.0.85" tabled = "0.8.0" tokio = { version = "1.20.1", features = ["full"] } diff --git a/src/main.rs b/src/main.rs index 5d31abb..69f1a36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,104 @@ use std::{env, process::exit}; use clap::{Arg, Command}; use colored_json::ToColoredJson; -use genius_cli::colorizer::print_colorized; use genius_rust::Genius; +use owo_colors::{ + colors::{css::Orange, Black, BrightGreen, BrightYellow, Cyan, Magenta, Yellow}, + OwoColorize, +}; +use rand::Rng; +use serde::Deserialize; + +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +struct LyricsApiResponse { + #[serde(default)] + id: u32, + title: String, + #[serde(default)] + artist_names: String, + url: String, + lyrics: String, + primary_artist: ApiPrimaryArtist, +} + +#[allow(dead_code)] +#[derive(Debug, Deserialize)] +struct ApiPrimaryArtist { + #[serde(default)] + id: u32, + name: String, + url: String, +} + +fn print_song_info(artist_name: &str, title: &str, url: &str) { + let mut rng = rand::thread_rng(); + match rng.gen_range(0..5) { + 0 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + 1 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + 2 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + 3 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + 4 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + 5 => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + _ => { + println!( + "\n{}{}{}", + artist_name.fg::().bg::(), + " - ".fg::().bg::(), + title.fg::().bg::() + ); + println!("{}\n", url.fg::()); + } + } +} fn cli() -> Command<'static> { const VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -79,13 +175,38 @@ async fn main() { .unwrap() .parse::() .unwrap(); - let result = genius.get_song(id, "plain").await; - let song = result.unwrap(); - - print_colorized(&song); - - let lyrics = genius.get_lyrics(id).await.unwrap(); - println!("{}", lyrics.join("\n")); + + // Fetch lyrics from the new API + let url = format!("https://genius-mcp.xvzf.workers.dev/api/song/{}/lyrics", id); + let client = reqwest::Client::new(); + + match client.get(&url).send().await { + Ok(response) => { + match response.json::().await { + Ok(lyrics_data) => { + // Print song info using our helper function + print_song_info( + &lyrics_data.primary_artist.name, + &lyrics_data.title, + &lyrics_data.url + ); + + // Print the lyrics + println!("{}", lyrics_data.lyrics); + } + Err(e) => { + eprintln!("Error parsing API response: {}", e); + eprintln!("Please check that the song ID exists."); + exit(1); + } + } + } + Err(e) => { + eprintln!("Error fetching lyrics from API: {}", e); + eprintln!("Please check your internet connection and try again."); + exit(1); + } + } } Some(("song", sub_matches)) => { let id = sub_matches -- 2.51.2 From 8d0bd978906c51d78a7757facbe62cc45e48993f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 27 Jan 2026 03:07:30 +0000 Subject: [PATCH 3/4] Fix code review issues - correct random range and improve comments - Change print_song_info() range from 0..5 to 0..6 to make case 5 reachable - Add detailed comments explaining why all fields are needed in API structs - Re-add #[allow(dead_code)] with explanation for deserialization requirements Co-authored-by: jchoi2x <2028917+jchoi2x@users.noreply.github.com> --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 69f1a36..30e967c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,9 @@ use owo_colors::{ use rand::Rng; use serde::Deserialize; +// API response structure from https://genius-mcp.xvzf.workers.dev/api/song/{id}/lyrics +// All fields are part of the API response and need to be present for deserialization +// Some fields aren't directly used in the code but are required for proper JSON parsing #[allow(dead_code)] #[derive(Debug, Deserialize)] struct LyricsApiResponse { @@ -17,7 +20,7 @@ struct LyricsApiResponse { id: u32, title: String, #[serde(default)] - artist_names: String, + artist_names: String, // Alternative to primary_artist.name url: String, lyrics: String, primary_artist: ApiPrimaryArtist, @@ -34,7 +37,7 @@ struct ApiPrimaryArtist { fn print_song_info(artist_name: &str, title: &str, url: &str) { let mut rng = rand::thread_rng(); - match rng.gen_range(0..5) { + match rng.gen_range(0..6) { 0 => { println!( "\n{}{}{}", -- 2.51.2 From 1c7e15a906a600cdc575a5d82e54bbff4d3d2e17 Mon Sep 17 00:00:00 2001 From: James Choi Date: Mon, 26 Jan 2026 21:11:54 -0600 Subject: [PATCH 4/4] update Cargo.toml --- Cargo.lock | 2 +- Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fa28252..be350c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -286,7 +286,7 @@ dependencies = [ [[package]] name = "genius-cli" -version = "0.1.2" +version = "0.2.0" dependencies = [ "clap", "colored_json", diff --git a/Cargo.toml b/Cargo.toml index 94c04ad..6fa7c79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "genius-cli" -version = "0.1.2" +version = "0.2.0" edition = "2021" description = "A command-line interface for Genius.com" readme = "README.md" repository = "https://github.com/tsirysndr/genius-cli" license = "MIT" -authors = ["Tsiry Sandratraina "] +authors = ["Tsiry Sandratraina ", "James Choi "] categories = ["command-line-utilities"] keywords = ["tokio", "lyrics", "cli", "genius"]