Skip Menu |

This queue is for tickets about the Lyrics-Fetcher CPAN distribution.

Report information
The Basics
Id: 133624
Status: open
Priority: 0/
Queue: Lyrics-Fetcher

People
Owner: davidp [...] preshweb.co.uk
Requestors: turnerjw784 [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.5.2
Fixed in: 0.5.2



Subject: PATCH to merge working fetcher modules + numerous fixes/updates
Greetings again, David, Since you merged my new/updated Lyrics::Fetcher modules (it looks like you forgot to add Musixmatch to CPAN, btw), I've had a chance to do a ton of real-world testing (by merging them into my Fauxdacious media player's lyrics plugins and streaming radio stations through it). Anyway, I've found and fixed several issues, mostly involving correctly formatting exceptional artist and song titles. One issue that you might notice is that I modified it to keep single blank lines (for paragraphs) between lyrics text (but still merge multiple ones into a single one), and also use "\r\n" for M$-Windows systems and "\n" for Linux/Unix, etc. I've also taken the liberty to merge the 3 known-working modules together into Lyrics::Fetcher and Cache, added an agent() method, and cleaned up / unified the code, particularly the POD documentation (I didn't change the content, just added the new stuff & mostly formatting and trying to make the three modules look and read as similar as possible and follow your coding conventions). I've created a single tarball for Lyrics::Fetcher which will install it and the three working modules together in a single install for the user, and assigns the same version# to each (in this case v1.00), and updated the README & CHANGES files to reflect this. Users should still be able to install and / or use the submodules independently, and you or I can add / merge new ones. This is how my "StreamFinder" module works - it has a "fetcher" submodule for each currently supported streaming site bundled in and I have added and removed sites/submodules regularly as needed, but one can install it as one bundle, but can either use the main module or any one of the submodules as desired (you can view / get it on CPAN). The reason for all this is is that I've found it challenging to go search CPAN to locate & determine which additional Lyrics::Fetcher-ish modules I need to install to get lyrics working, so in my instructions for installing and using Fauxdacious media player, I want to be able to tell my users that they simply need to install Lyrics::Fetcher in order for the Lyrics plugins to work for them without having to figure out which sites still work and which to install. In my "helper" script that the plugins use, I have it seemlessly try each of the "available" fetchers in random order until lyrics are found or all (currently 3) fetchers are exhausted. Also, if a user finds they need to change the user agent later on, either they (or I - in my helper script) can change it and it will apply to all the fetchers. Anyway, please review what I've done and let me know what you think, any other ideas, suggestions, or fixes, or just want to use it for your next version. ;) Also, you can close out the prev. bug# If you're interested in how I'm using this now in Fauxdacous, please see: https://github.com/wildstar84/fauxdacious-plugins/commit/f33d6b88ed52b302921d6ba6df4ff88a443ce3db where I mentioned you and Lyrics::Fetcher, https://wildstar84.github.io/fauxdacious/FAQ.htm#37 or the main site: https://wildstar84.wordpress.com/fauxdacious/ Also see what led to this here!: https://redmine.audacious-media-player.org/boards/1/topics/2389 Oh, and here's my "helper" script that calls your modules from within the media player: https://github.com/wildstar84/fauxdacious/blob/master/contrib/FauxdaciousLyricsHelper.pl Thanks again for doing the heavy lifting creating this handy set of modules! Jim Turner
Subject: Lyrics-Fetcher-1.00.tar.gz

Message body not shown because it is not plain text.

Hi Jim, Many thanks for all your work! I plan to find time to review this all this week. On 2020-10-29 03:01:25, TURNERJW wrote: Show quoted text
> Since you merged my new/updated Lyrics::Fetcher modules (it looks like > you forgot to add Musixmatch to CPAN, btw),
Yeah, I wanted to do a bit more testing first, but had a busy week - will get that out there soon. Show quoted text
> I've had a chance to do a > ton of real-world testing (by merging them into my Fauxdacious media > player's lyrics plugins and streaming radio stations through it). > Anyway, I've found and fixed several issues, mostly involving > correctly formatting exceptional artist and song titles. One issue > that you might notice is that I modified it to keep single blank lines > (for paragraphs) between lyrics text (but still merge multiple ones > into a single one), and also use "\r\n" for M$-Windows systems and > "\n" for Linux/Unix, etc.
Excellent! Show quoted text
> I've also taken the liberty to merge the 3 known-working modules > together into Lyrics::Fetcher and Cache, [...] > I've created a single tarball for Lyrics::Fetcher which will > install it and the three working modules together in a single > install for the user,
I'm not entirely convinced I want to bundle the fetcher modules with Lyrics::Fetcher - I'd prefer each fetcher to remain its own CPAN distribution which can be updated independently, CI tested individually etc. I do understand the convenience of being able to quickly install L::F and all the "supported" fetchers easily though. What about if I added a Bundle::Lyrics::Fetcher which installs Lyrics::Fetcher and the Lyrics::Fetcher fetcher distributions which are known to work at that time? Also, for future contributions, if you're not averse to GitHub, then pull requests on GitHub would be really handy: https://github.com/bigpresh?tab=repositories&q=lyrics Of course, I'm quite happy to accept patches via RT too if that works better for you! Cheers David P (BIGPRESH
If you want to create a Bundle:: module, that'd work for me. I just need a way to make installation simple for my users, most of whom will likely not be familiar with CPAN or Perl (I already compile the 2 existing Perl "helper" scripts this project uses into .exe binaries for the Windows version!). From my project's point of view, fetching lyrics is a single function concept and isn't concerned with which lyrics site is sourced (why I added a "random" option, and the agent() function which can set the user-agent for all the submodules at once), similar to my "StreamFinder" module (written for this same project) is for fetching online radio stations, podcasts, and videos. I'm fine with using GitHub too (My Fauxdacious project, etc. are also there). I wasn't sure you were still updating it there though. When I was touching up the POD documentation, I only found it referenced in the main L::F module itself, not the others (you may want to copy & adjust that part of the POD into the others). I didn't actually change a whole lot, even though the diffs will look like I rewrote it all, mostly due to my attempts to line up the code format and POD docs between all the modules, so I could check myself by being able to diff the three site-specific modules against eachother to ensure I had everything in all of them and that they worked the same way and that the POD was all updated and consistant. If you're a Linux user (I'm not going to rebuild the Windows binary untill all this is settled), feel free to grab and build the latest Fauxdacious from beta from Github, and try out the Lyric plugins and see how well this is working! I only took a cursory look at the "Cache" module's code as I'm not really sure what it's supposed to do (I don't have it's prerequisites installed), so I didn't touch it. I also considered the other sites you cover that I found on CPAN (LyrDB, AstraWeb, and LyricsDownload) to see if I could update them as well, but those sites appear to now also be defunct, so at this time, I only know of 3 that still work (the ones I sent you). As I've found with StreamFinder, sites seem to come and go, change their HTML, and often deliberately make themselves hard or impossible to scrape (javascript, CloudFlare, cookies, etc). Thanks again! Jim On Sun Nov 01 17:10:12 2020, BIGPRESH wrote: Show quoted text
> > Hi Jim, > > Many thanks for all your work! > > I plan to find time to review this all this week. > > > On 2020-10-29 03:01:25, TURNERJW wrote:
> > Since you merged my new/updated Lyrics::Fetcher modules (it looks > > like > > you forgot to add Musixmatch to CPAN, btw),
> > Yeah, I wanted to do a bit more testing first, but had a busy week - > will get that out there soon. >
> > I've had a chance to do a > > ton of real-world testing (by merging them into my Fauxdacious media > > player's lyrics plugins and streaming radio stations through it). > > Anyway, I've found and fixed several issues, mostly involving > > correctly formatting exceptional artist and song titles. One issue > > that you might notice is that I modified it to keep single blank > > lines > > (for paragraphs) between lyrics text (but still merge multiple ones > > into a single one), and also use "\r\n" for M$-Windows systems and > > "\n" for Linux/Unix, etc.
> > Excellent! >
> > I've also taken the liberty to merge the 3 known-working modules > > together into Lyrics::Fetcher and Cache, [...] > > I've created a single tarball for Lyrics::Fetcher which will > > install it and the three working modules together in a single > > install for the user,
> > I'm not entirely convinced I want to bundle the fetcher modules with > Lyrics::Fetcher - I'd prefer each fetcher to remain its own CPAN > distribution which can be updated independently, CI tested > individually etc. I do understand the convenience of being able to > quickly install L::F and all the "supported" fetchers easily though. > What about if I added a Bundle::Lyrics::Fetcher which installs > Lyrics::Fetcher and the Lyrics::Fetcher fetcher distributions which > are known to work at that time? > > > Also, for future contributions, if you're not averse to GitHub, then > pull requests on GitHub would be really handy: > https://github.com/bigpresh?tab=repositories&q=lyrics > > Of course, I'm quite happy to accept patches via RT too if that works > better for you! > > Cheers > > David P (BIGPRESH
Hi, Just wanted to say I haven't forgotten this, just awaiting a moment to deal with it. As soon as I can, I'll review your changes and get new releases out, and release a Bundle::Lyrics::Fetcher which installs the Lyrics::Fetcher core and the three known-to-work fetchers. Cheers Dave P (BIGPRESH)
Good to here. I got ANOTHER submodule (lyrics site) you can add to it as well (ApiLyricsOph.pm - https://api.lyrics.ovh...) that's also working pretty well for me too! (see attached) Jim On Wed Nov 11 11:00:08 2020, BIGPRESH wrote: Show quoted text
> > Hi, > > Just wanted to say I haven't forgotten this, just awaiting a moment to > deal with it. > > As soon as I can, I'll review your changes and get new releases out, > and release a Bundle::Lyrics::Fetcher which installs the > Lyrics::Fetcher core and the three known-to-work fetchers. > > Cheers > > Dave P (BIGPRESH)
Subject: ApiLyricsOph.pm
package Lyrics::Fetcher::ApiLyricsOph; # $Id$ use 5.008000; use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use Carp; my $haveLyricsFetcher = 0; eval "use Lyrics::Fetcher (qw(\$VERSION \$AGENT)); \$haveLyricsFetcher = 1; 1"; our $VERSION = $haveLyricsFetcher ? $Lyrics::Fetcher::VERSION : '1.00'; # the HTTP User-Agent we'll send: our $AGENT = ($haveLyricsFetcher && defined $Lyrics::Fetcher::AGENT) ? $Lyrics::Fetcher::AGENT : "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0"; $Lyrics::Fetcher::Error = 'OK' unless ($haveLyricsFetcher); sub fetch { my $self = shift; my ($artist, $song) = @_; # reset the error var, change it if an error occurs. $Lyrics::Fetcher::Error = 'OK'; unless ($artist && $song) { carp($Lyrics::Fetcher::Error = 'fetch() called without artist and song'); return; } $artist =~ s#\s*\/.*$##; #ONLY USE 1ST ARTIST, IF MORE THAN ONE! $artist =~ s/\s+/\%20/g; $artist =~ s/[^a-z0-9\%]//gi; $song =~ s/\s+/\%20/g; $song =~ s/[^a-z0-9\%]//gi; # Their URLs look like e.g.: # https://api.lyrics.ovh/v1/Dire%20straits/heavy%sfuel%s my $url = "https://api.lyrics.ovh/v1/${artist}/$song"; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0, }, ); $ua->timeout(10); $ua->agent($AGENT); $ua->protocols_allowed(['https']); $ua->cookie_jar( {} ); push @{ $ua->requests_redirectable }, 'GET'; (my $referer = $url) =~ s{^(\w+)\:\/\/}{}; my $protocol = $1; $referer =~ s{\/.+$}{\/}; my $host = $referer; $host =~ s{\/$}{}; $referer = $protocol . '://' . $referer; my $req = new HTTP::Request 'GET' => $url; $req->header( 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language' => 'en-US,en;q=0.5', 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'keep-alive', 'Upgrade-insecure-requests' => 1, 'Host' => $host, ); my $res = $ua->request($req); if ($res->is_success) { my $lyrics = _parse($res->decoded_content); return $lyrics; } else { if ($res->status_line =~ /^404/) { $Lyrics::Fetcher::Error = 'Lyrics not found'; return; } else { carp($Lyrics::Fetcher::Error = "Failed to retrieve $url (".$res->status_line.')'); return; } } } # Allow user to specify a different user-agent: sub agent { if (defined $_[1]) { $AGENT = $_[1]; } else { return $AGENT; } } # Internal use only functions: sub _parse { my $html = shift; if (my ($goodbit) = $html =~ m{\{\"lyrics\"\:\"([^\"]+)\"}msi) { my $text = ''; # convert literal "\" followed by "r" or "n", etc. to "\r" or "\n" characters respectively: eval "\$text = \"$goodbit\";"; # fix apparent site bug where they use "\n\n" where they appear to mean "\r\n" (excess double-lines): $text =~ s/\n\n/\n/gs; # normalize Windowsey \r\n sequences: $text =~ s/\r+//gs; # strip off pre & post padding with spaces: $text =~ s/^ +//mg; $text =~ s/ +$//mg; # clear up repeated blank lines: $text =~ s/(\R){2,}/\n\n/gs; # and remove any blank top lines: $text =~ s/^\R+//s; $text =~ s/\R\R+$/\n/s; $text .= "\n" unless ($text =~ /\n$/s); # now fix up for either Windows or Linux/Unix: $text =~ s/\R/\r\n/gs if ($^O =~ /Win/); return $text; } else { carp "Failed to identify lyrics on result page"; return; } } # end of sub parse 1; __END__ =head1 NAME Lyrics::Fetcher::ApiLyricsOph - Get song lyrics from api.lyrics.ovh. =head1 SYNOPSIS #!/usr/bin/perl use Lyrics::Fetcher; print Lyrics::Fetcher->fetch("<artist>","<song>","ApiLyricsOph"); # or, if you want to use this module directly without Lyrics::Fetcher's involvement: use Lyrics::Fetcher::ApiLyricsOph; print Lyrics::Fetcher::ApiLyricsOph->fetch("<artist>", "<song>"); =head1 DESCRIPTION This module tries to get song lyrics from api.lyrics.ovh. It's designed to be called by Lyrics::Fetcher, but can be used directly if you'd prefer. =head1 INTERFACE =over 4 =item fetch($artist, $title) Attempts to fetch the lyrics for the given artist and title from api.lyrics.ovh. Returns lyrics as a string, or an empty string, if not found. =item agent([$useragent_string]) Set the desired user-agent (ie. browser name) to pass to the lyrics sites - some require you to look like a valid web browser in order to respond in order to prevent their sites from being "scraped" by programs, such as this. If not set, the current default is: "Mozilla/5.0 (X11; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0" If no argument is passed, it returns the current user-agent string in effect. =back =head1 SPECIAL GLOBAL VARIABLES =over 4 =item $Lyrics::Fetcher::Error Returns a description of the last error that occurred when failing to fetch lyrics for various reasons, or "OK" if last operation successful. =item $Lyrics::Fetcher::ApiLyricsOph::VERSION The current version# of Lyrics::Fetcher::ApiLyricsOph =back =head1 BUGS Probably. If you find any, please let me know. If api.lyrics.ovh change their site much, this module may well stop working. If you find any songs which have lyrics listed on the api.lyrics.ovh site, but for which this module is unable to fetch lyrics, please let me know also. It seems that the HTML on the lyrics pages isn't consistent, so it's entirely possible (likely, in fact) that there are some pages which this script will not be able to parse. Please report any bugs or feature requests to L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Lyrics-Fetcher-ApiLyricsOph>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 AUTHOR David Precious C<< <davidp@preshweb.co.uk> >> (CPAN Id: BIGPRESH) =head1 ACKNOWLEDGEMENTS Original version contributed by Jim Turner in RT 133592. =head1 COPYRIGHT AND LICENSE Copyright (C) 2020 by David Precious This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. Legal disclaimer: I have no connection with the owners of api.lyrics.ovh. Lyrics fetched by this script may be copyrighted by the authors, it's up to you to determine whether this is the case, and if so, whether you are entitled to request/use those lyrics. You will almost certainly not be allowed to use the lyrics obtained for any commercial purposes. =cut
I'm going ahead and including a tarball of my test version (now v1.01 beta), including the diffs between the first one I sent you before (v1.00 beta). It contains both the new ApiLyricsOvh.pm fetcher (with the SPELLING ERROR (ApiLyricsOph => ApiLyricsOvh) FIXED!) and some minor changes I've had to make after much more extensive testing in Fauxdacious. BTW, I did go ahead and build for M$-Windows (with "MY" vsn. of L::F compiled into the Perl binaries for now - until you release your new "bundle") b/c I wanted to finally get this thang out! If interested, you can get it here (it's very easy to install)!: https://github.com/wildstar84/fauxdacious-windows-easyinstaller It also includes an uninstall option (bin/uninst.exe) so you can get rid of it if you don't want it after playing with it. Thanks, Jim On Wed Nov 11 16:43:37 2020, TURNERJW wrote: Show quoted text
> Good to here. I got ANOTHER submodule (lyrics site) you can add to it > as well (ApiLyricsOph.pm - https://api.lyrics.ovh...) that's also > working pretty well for me too! (see attached) > > Jim > > > On Wed Nov 11 11:00:08 2020, BIGPRESH wrote:
> > > > Hi, > > > > Just wanted to say I haven't forgotten this, just awaiting a moment > > to > > deal with it. > > > > As soon as I can, I'll review your changes and get new releases out, > > and release a Bundle::Lyrics::Fetcher which installs the > > Lyrics::Fetcher core and the three known-to-work fetchers. > > > > Cheers > > > > Dave P (BIGPRESH)
Subject: Lyrics-Fetcher-1.01.tar
Download Lyrics-Fetcher-1.01.tar
application/x-tar 60k

Message body not shown because it is not plain text.