X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FLyrics%2FFetcher%2FLyricsTranslate.pm;h=2ae56b2d8f167c813ae12c93fe232870010d066f;hb=b452276fd2b64718bd217a38e8d0450129f8086f;hp=55f3761156ac294cdd89e0e32f763b20d6969eee;hpb=0f0918b195051cc97ab7a757eb0f01d29d0acb93;p=lyrics-fetcher-lyricstranslate.git diff --git a/lib/Lyrics/Fetcher/LyricsTranslate.pm b/lib/Lyrics/Fetcher/LyricsTranslate.pm index 55f3761..2ae56b2 100644 --- a/lib/Lyrics/Fetcher/LyricsTranslate.pm +++ b/lib/Lyrics/Fetcher/LyricsTranslate.pm @@ -8,7 +8,7 @@ use HTML::TreeBuilder; use HTTP::Tiny; use Scalar::Util qw/looks_like_number/; -our $VERSION = '0.001'; +our $VERSION = '0.002001'; our $BASE_URL = 'http://lyricstranslate.com'; # 0 means (from) any language; the following arguments are the # destination language, artist, and title. The meaning of the last @@ -42,7 +42,7 @@ sub fetch { return } $tree = HTML::TreeBuilder->new_from_content($response->{content}); - my $node = $tree->look_down(class => qr/\btranslate-node-text\b/); + my $node = $tree->look_down(class => qr/(?look_down(class => qr/\bltf\b/); my @pars = $ltf->look_down(class => 'par'); join "\n", map { @@ -401,28 +401,44 @@ Lyrics::Fetcher::LyricsTranslate - Get lyrics from lyricstranslate.com # This module should be used directly use Lyrics::Fetcher::LyricsTranslate; print Lyrics::Fetcher::LyricsTranslate->fetch('Lyube', 'Kombat'); + # Equivalent to + print Lyrics::Fetcher::LyricsTranslate->fetch('Lyube', 'Kombat', 'English'); + # Equivalent to + print Lyrics::Fetcher::LyricsTranslate->fetch('Lyube', 'Kombat', 328); - # Can also be used via Lyrics::Fetcher but produces ugly output + + print $Lyrics::Fetcher::LyricsTranslate::LANGUAGES{English}; # prints 328 + + + # Can also be used via Lyrics::Fetcher but produces ugly output and + # does not support a custom target language use Lyrics::Fetcher; print Lyrics::Fetcher->fetch('Lyube', 'Kombat', 'LyricsTranslate'); =head1 DESCRIPTION This module tries to get translated lyrics from -L. It does a search for a translation of -the given artist and song title from any language to English, and -returns the contents of the first result found. - -This is a very basic implementation of the concept and it should be -improved in future versions (for example supporting multiple -destination languages). +L. It searches for a translation of the +given artist and song title from any language to a requested language +(which defaults to English), and returns the contents of the first +result found. It is recommended to use the module directly, as using it via L loses empty lines between parahraphs. +The target language can be specified as either a number or a string. +If a string is given, it is looked up in the hash +C<%Lyrics::Fetcher::LyricsTranslate::LANGUAGES> which maps language +names to their numerical identifiers. The hash was generated from the +website, and it might be outdated. + +The target language is passed as the third argument to the B +method. If using the module via L, the target +language cannot be set and defaults to English. + =head1 SEE ALSO -L +L, L =head1 AUTHOR @@ -430,7 +446,7 @@ Marius Gavrilescu, Emarius@ieval.roE =head1 COPYRIGHT AND LICENSE -Copyright (C) 2016 by Marius Gavrilescu +Copyright (C) 2016-2017 by Marius Gavrilescu This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.24.0 or,