Skip to content

GetLyrics needs to update. #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
VithorCarlos opened this issue Jan 8, 2025 · 0 comments
Open

GetLyrics needs to update. #43

VithorCarlos opened this issue Jan 8, 2025 · 0 comments

Comments

@VithorCarlos
Copy link

Lyrics ins't returning nothing.
Use this code to solve this:

import axios from "axios";
import { load } from "cheerio";

const scrapeLyrics = async (url) => {
  try {
    const { data } = await axios.get(url);

    const $ = load(data);

    let lyrics = "";

    $("div[data-lyrics-container]").each((i, elem) => {
      const snippet = $(elem)
        .html()
        .replace(/<br\s*\/?>/g, "\n")
        .replace(/<[^>]+>/g, "");

      lyrics += snippet.trim() + "\n\n";
    });

    if (!lyrics) {
      console.log("No letters found.");
      return null;
    }

    return lyrics.trim();
  } catch (error) {
    console.error("Error while scraping:", error.message);
    return null;
  }
};

const lyrics = await scrapeLyrics(result.url);
hi021 added a commit to hi021/genius-lyrics-api that referenced this issue Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant