Skip to content

Commit

Permalink
Lyrics Output needs work
Browse files Browse the repository at this point in the history
  • Loading branch information
newtoallofthis123 committed Nov 19, 2023
1 parent afd99e3 commit 9df3b46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ mod scraper;
async fn main() {
setup_panic!();
cli::splash_screen();
let x = scraper::get_search_options("Falling in love with you").await;
println!("{:?}", scraper::get_lyrics(x.get(&0).unwrap().1.as_str()).await );
let x = scraper::get_search_options("Chainsmokers paris").await;

let url = x.get(&0).unwrap().1.as_str();

let lyrics = scraper::get_lyrics(url).await;

println!("{}", lyrics);

/* let (input, cmd) = cli::parse_args();
if cmd == "-h" || cmd == "--help" {
cli::print_help();
Expand Down
18 changes: 15 additions & 3 deletions src/scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn clean_text(text: &str)->String{
text.replace(['\n', '\t'], "").trim().to_string()
}

pub async fn get_search_options(term: &str)->HashMap<i32, (String, String)>{
pub async fn get_search_options(term: &str)->HashMap<usize, (String, String)>{
let search_html = get_page_html(&format!("{DUMB_URL}/search?q={term}")).await;
let search_doc = Html::parse_document(&search_html);

Expand All @@ -32,7 +32,7 @@ pub async fn get_search_options(term: &str)->HashMap<i32, (String, String)>{
for (i, link) in search_links.enumerate() {
let link_text = clean_text(&link.text().collect::<Vec<_>>().join(""));
let link_href = link.value().attr("href").unwrap().to_string();
search_options.insert(i as i32, (link_text, link_href));
search_options.insert(i, (link_text, link_href));
}

search_options
Expand All @@ -41,5 +41,17 @@ pub async fn get_search_options(term: &str)->HashMap<i32, (String, String)>{
pub async fn get_lyrics(slug: &str)->String{
let lyrics_html = get_page_html(&format!("{DUMB_URL}{slug}")).await;

return lyrics_html;
let lyrics_doc = Html::parse_document(&lyrics_html);
let selector = Selector::parse("div#lyrics").unwrap();

let lyrics = lyrics_doc.select(&selector);

let lyrics = lyrics
.map(|lyric| lyric.text().collect::<Vec<_>>().join("\n"))
.collect::<String>();

//split by \"
// let lyrics = lyrics.split("\"").collect::<Vec<_>>().join("\n");

lyrics
}

0 comments on commit 9df3b46

Please sign in to comment.