Closed Rexadev closed 1 week ago
#include <foobar2000.h>
#include <your_additional_headers.h>
#include <http/client.h>
#include <helpers/string_helper.h>
#include <html/parsing.h>
class LyricsifySource : public lyrics_source
{
public:
void retrieve_lyrics(const metadb_handle_ptr& track, threaded_process_status& p_status, abort_callback& p_abort)
{
try
{
// Fetch lyrics from lyricsify.com
pfc::string8 url = get_lyricsify_url(track);
http_request::ptr request = http_client::get()->create_request("GET");
request->add_header("User-Agent", "foobar2000");
// Make an HTTP request to the lyricsify.com page
http_request::ptr response = request->run(url, p_abort);
// Parse the HTML response and extract the lyrics
pfc::string8 lyrics = extract_lyrics(response->get_content());
// Format the lyrics for display in the LYRICS tab
lyrics = format_lyrics(lyrics);
// Update the lyrics display in the LYRICS tab
set_result(track, lyrics);
}
catch (std::exception& e)
{
console::info("Failed to fetch lyrics: %s", e.what());
}
}
private:
pfc::string8 get_lyricsify_url(const metadb_handle_ptr& track)
{
// Implement the logic to retrieve the lyricsify.com URL for the given track
// You may need to construct the URL based on the track's metadata or search for the lyricsify.com URL using a third-party API or database
return "";
}
pfc::string8 extract_lyrics(const pfc::string8& html)
{
// Parse the HTML response and extract the lyrics using optimized HTML parsing
html::parser_dom parser;
parser.parse_string(html);
// Find the lyrics node using optimized searching techniques
html::node::ptr lyricsNode = find_lyrics_node(parser.get_root());
if (lyricsNode.is_valid())
{
// Extract the text content from the lyrics node
return html::parser::get_inner_text(lyricsNode);
}
return "";
}
html::node::ptr find_lyrics_node(const html::node::ptr& root)
{
// Implement the logic to find the lyrics node in the HTML DOM tree
// Use optimized searching techniques such as tag names, class names, or other identifying attributes
html::node::ptr lyricsNode = root->find_first_node("div", "class", "lyrics");
return lyricsNode;
}
pfc::string8 format_lyrics(const pfc::string8& lyrics)
{
// Format the lyrics for display in the LYRICS tab
pfc::string8 formattedLyrics = lyrics;
// Replace line breaks with actual line breaks in the text
formattedLyrics.replace_string("<br>", "\n");
formattedLyrics.replace_string("<br/>", "\n");
formattedLyrics.replace_string("<br />", "\n");
return formattedLyrics;
}
};
class LyricsifySourceFactory : public service_impl_t<lyrics_source_factory>
{
public:
lyrics_source_ptr create()
{
return new service_impl_t<LyricsifySource>();
}
};
static const service_factory_single_t<LyricsifySourceFactory> g_LyricsifySourceFactory;
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
return TRUE;
}
I was just about to make a request for this. Not many sources for synced lyrics, so adding this site would be nice.
Song - https://en.wikipedia.org/wiki/Mannish_Boy
https://www.lyricsify.com/lyrics/muddy-waters/mannish-boy/ZVo2Zw
Example 2- https://www.lyricsify.com/lyrics/bon-jovi/runaway/ZmNTZQ
Song https://en.wikipedia.org/wiki/Runaway_(Bon_Jovi_song)