jacquesh / foo_openlyrics

An open-source lyric display panel for foobar2000
MIT License
402 stars 24 forks source link

request: bandcamp.com #82

Open Mrakobes666 opened 2 years ago

Mrakobes666 commented 2 years ago

A request for lyrics from a site that has a structure that parses well, this site is a trend for a huge number of musicians

https://deltasleep.bandcamp.com/album/spring-island?from=discover-top

2021-12-07 17-48-37

Rexadev commented 1 year ago

Code not tested

Using Curl

// Include necessary libraries and headers
#include <string>
#include <curl/curl.h>

// Function to retrieve lyrics from Bandcamp
std::string getBandcampLyrics(const std::string& trackUrl) {
  std::string lyrics;

  // Make a request to the track URL
  CURL* curl = curl_easy_init();

  if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, trackUrl.c_str());
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    // Specify any additional CURL options if required

    // Perform the HTTP request and retrieve the response
    CURLcode res = curl_easy_perform(curl);

    if (res == CURLE_OK) {
      // Process the response to extract the lyrics
      lyrics = extractLyricsFromResponse(curl);
    }

    // Clean up the CURL resources
    curl_easy_cleanup(curl);
  }

  return lyrics;
}

// Modify the existing fetchLyrics() function in the foo_openlyrics source file
void fetchLyrics(const std::string& trackUrl) {
  std::string lyrics;

  // Check if the track URL is from Bandcamp
  if (isBandcampTrack(trackUrl)) {
    lyrics = getBandcampLyrics(trackUrl);
  }

  // Handle the fetched lyrics as per the existing logic
  handleFetchedLyrics(lyrics);
}
Rexadev commented 1 year ago

@jacquesh When using this. Add option to only search on bandcamp.com when file has source metadata has word bandcamp in it.