]>
iEval git - lyrics-fetcher-lyricstranslate.git/blob - lib/Lyrics/Fetcher/LyricsTranslate.pm
1 package Lyrics
::Fetcher
::LyricsTranslate
;
9 use Scalar
::Util qw
/looks_like_number/;
11 our $VERSION = '0.001';
12 our $BASE_URL = 'http://lyricstranslate.com';
13 # 0 means (from) any language; the following arguments are the
14 # destination language, artist, and title. The meaning of the last
15 # parameter is unknown.
16 our $URL_FORMAT = "$BASE_URL/en/translations/0/%s/%s/%s/none";
18 my $ht = HTTP
::Tiny
->new(agent
=> "Lyrics-Fetcher-LyricsTranslate/$VERSION ");
20 our %LANGUAGES; # Filled at the end of the file
23 my ($self, $artist, $song, $language) = @_;
24 $language //= 'English';
25 $language = $LANGUAGES{$language} unless looks_like_number
$language;
26 $Lyrics::Fetcher
::Error
= 'OK';
27 my $url = sprintf $URL_FORMAT, $language, $artist, $song;
28 my $response = $ht->get($url);
29 unless ($response->{success
}) {
30 $Lyrics::Fetcher
::Error
= 'Search request failed: ' . $response->{reason
};
33 my $tree = HTML
::TreeBuilder
->new_from_content($response->{content
});
34 # First result would be the link to the artist, so we get the second one
35 my (undef, $result) = $tree->look_down(class => 'ltsearch-translatenameoriginal');
37 $Lyrics::Fetcher
::Error
= 'Lyrics not found';
39 $response = $ht->get($BASE_URL . $result->find('a')->attr('href'));
40 unless ($response->{success
}) {
41 $Lyrics::Fetcher
::Error
= 'Lyrics request failed: ' . $response->{reason
};
44 $tree = HTML
::TreeBuilder
->new_from_content($response->{content
});
45 my $node = $tree->look_down(class => qr/\btranslate-node-text\b/);
46 my $ltf = $node->look_down(class => qr/\bltf\b/);
47 my @pars = $ltf->look_down(class => 'par');
49 join '', map { $_->as_trimmed_text . "\n" } $_->content_list
68 'Filipino/Tagalog' => 373,
98 'Transliteration' => 718,
103 'Adunaic' => 1000213,,
107 'Al Bhed' => 1000269,
109 'American Sign Language' => 1000218,
112 'Angolar Creole' => 1034642,
113 'Aragonese' => 1032780,
114 'Aramaic (Modern Syriac Dialects)' => 1025338,
115 'Aramaic (Syriac Classical)' => 1025337,
117 'Armenian (Homshetsi dialect)' => 1025608,
119 'Asturian' => 1000136,
130 'Black Speech' => 1000212,
131 'Blackfoot' => 1028055,
132 'Breton (Brezhoneg)' => 608,
133 'Burmese' => 1020572,
134 'Butuanon' => 1019909,
135 'Cantabrian' => 1034733,
136 'Cape Verdean' => 808,
137 'Castithan' => 1022982,
138 'Catalan (Medieval)' => 1033121,
139 'Cebuano' => 1000245,
141 'Chavacano' => 1000278,
142 'Chechen' => 1021776,
143 'Cherokee' => 1029750,
145 'Chinese (Hakka)' => 1032630 ,
146 'Chuvash' => 1027857,
147 'Circassian' => 1030979,
149 'Comorian' => 1000199,
150 'Cornish' => 1030748,
152 'Crimean Tatar' => 827,
153 'Croatian (Chakavian dialect)' => 1000152,
154 'Croatian (Kajkavian dialect)' => 1022139,
156 'Arabic (other varieties)' => 1000186,
157 'Darnassian' => 1000188,
160 'Dothraki' => 1000228,
162 'Dutch (Middle Dutch)' => 1022075,
163 'Dutch (Old Dutch)' => 1028105,
164 'Dutch dialects' => 434,
165 'Dzongkha' => 1000197,
166 'Egyptian (Old Egyptian/Coptic)' => 1028479,
167 'Emilian-Romagnol' => 1000240,
168 'English (Jamaican)' => 1023750,
169 'English (Middle English)' => 1020671,
170 'English (Old English)' => 1000210,
171 'English (Scots)' => 521,
172 'English Creole (Tok Pisin)' => 1029190,
174 'Estonian (South)' => 1022579,
175 'Extremaduran' => 1034916,
178 'Finnish (Savo)' => 436,
181 'French (Antillean Creole)' => 1037027,
182 'French (Haitian Creole)' => 570,
183 'French (Indian French)' => 1028744,
184 'French (Louisiana Creole French)' => 1023092,
185 'French (Middle French)' => 1028104,
186 'French (Old French)' => 1020670,
187 'French (Réunion Creole)' => 1033982,
190 'Gaelic (Irish Gaelic)' => 607,
191 'Gaelic (Scottish Gaelic)' => 597,
194 'Galician-Portuguese' => 1000238,
195 'Garifuna' => 1033983,
197 'Genoese' => 1000272,
199 'German (Austrian/Bavarian)' => 658,
200 'German (Berlinerisch dialect)' => 1031655,
201 'German (central dialects)' => 1000195,
202 'German (Kölsch)' => 1033301,
203 'German (Low German)' => 1000131,
204 'German (Middle High German)' => 824,
205 'German (Old High German)' => 825,
206 'German (Swiss-German/Allemanic)' => 631,
207 'Gilbertese' => 1000202,
208 'Goranian' => 1037077,
210 'Greek (classical)' => 823,
211 'Greek (Cypriot)' => 1032770,
212 'Greek (Pontic)' => 1000172,
213 'Greenlandic' => 1029356,
215 'Guaraní' => 1031493,
219 'High Valyrian' => 1022167,
220 'Hiligaynon' => 1000247,
222 'Hungarian (Old Hungarian)' => 1033943,
224 'Ilokano' => 1000246,
225 'Indigenous Languages (Mexico)' => 1037074,
227 'Interlingua' => 1037062,
228 'Inuktitut ' => 1035431,
230 'Iranian (Balochi)' => 1025775,
231 'Iranian (Gilaki)' => 1033120,
232 'Iranian (Luri)' => 1037061,
233 'Istriot' => 1000239,
234 'Italian (Medieval)' => 1024385,
237 'Kannada' => 1025336,
238 'Kapampangan' => 1019910,
239 'Karachay-Balkar' => 1024275,
240 'Karakalpak' => 1020990,
241 'Karelian' => 1020968,
243 'Kashubian' => 1025888,
245 'Khuzdul' => 1000214,
246 'Kinaray-a' => 1019911,
247 'Kinyarwanda' => 1021709,
248 'Kirundi' => 1000198,
249 'Klingon' => 1000220,
251 'Kriol (Guinea Bissau)' => 1033054,
253 'Kurdish (Kurmanji)' => 327,
254 'Kurdish (Sorani)' => 1024274,
255 'Kurdish dialects' => 1022466,
257 'Ladin (Rhaeto-Romance)' => 1032848,
258 'Ladino (Judeo-Spanish)' => 1023993,
260 'Latvian (Latgalian)' => 1033068,
262 'Lingala' => 1028743,
263 'Livonian' => 1025670,
264 'Lombard' => 1035433,
266 'Luganda' => 1000268,
267 'Luxembourgish' => 785,
268 'Malagasy' => 1033944,
270 'Maldivian (dhivehi)' => 1021237,
271 'Maltese' => 1000067,
273 'Manx Gaelic' => 1000071,
275 'Mapudungun' => 1035835,
278 'Minangkabau' => 1022890,
282 'Mongolian (Buryat dialect)' => 1037067,
283 'Montenegrin' => 657,
284 'Nahuatl' => 1000226,
290 'Norwegian (Dano-Norwegian)' => 1020252,
291 'Norwegian (Sognamål)' => 1025146,
292 'Occitan' => 1000068,
293 'Old Church Slavonic' => 1000135,
294 'Old East Slavic' => 1024273,
295 'Old Norse/Norrønt' => 826,
296 'Old Prussian' => 1026171,
297 'Ossetic' => 1000139,
300 'Pangasinan' => 1000249,
301 'Papiamento' => 1000209,
303 'Paumotuan' => 1024518,
304 'Piedmontese' => 1036374,
305 'Polish (Poznan dialect)' => 1031836,
306 'Pseudo-Latin' => 1000279,
308 'Quechua' => 1000142,
310 'Quichua (Kichwa)' => 1031957,
311 'Rapa Nui' => 1000145,
312 'Rarotongan' => 1000273,
313 'Roman dialect' => 1035163,
315 'Romanian (Aromanian)' => 810,
316 'Romansh' => 1000130,
317 'Romeyika/Rumka' => 1032709,
320 'Salentine' => 1035162,
323 'Sanskrit' => 1000138,
325 'Sardo-corsican' => 1029194,
326 'Sicilian' => 1000225,
327 'Sindarin' => 1000184,
332 'Spanish (Old Castillian)' => 1035797,
333 'Sranan Tongo' => 1022039,
334 'Sumerian' => 1026172,
335 'Sundanese' => 1035432,
336 'Surzhyk ' => 1020339,
338 'Swedish (dialects)' => 1037078,
339 'Swedish (Old Swedish)' => 1033302,
340 'Tagalog (dialects)' => 44,
341 'Tahitian' => 1000227,
345 'Tamashek-Berber/Tuareg' => 791,
352 'Thalassian' => 1000189,
353 'Tibetan' => 1000143,
354 'Tigrinya' => 1000201,
355 'Tokelauan' => 1000185,
356 'Tongan (Old Tongan)' => 1022633,
357 'Torlakian dialect' => 1000230,
358 'Totonac' => 1037076,
360 'Turkish (Anatolian dialects)' => 1021735,
361 'Turkish (Middle Turkic)' => 1032996,
362 'Turkish (Ottoman)' => 1019916,
364 'Tuvaluan' => 1000203,
366 'Tzotzil' => 1031492,
368 'Upper Sorbian' => 1022610,
372 'Uzbek dialects' => 1025822,
373 'Venetian' => 1033821,
377 'Waray-Waray' => 1019914,
382 'Yolŋu Matha' => 817,
385 'Zapotec' => 1000196,
397 Lyrics::Fetcher::LyricsTranslate - Get lyrics from lyricstranslate.com
401 # This module should be used directly
402 use Lyrics::Fetcher::LyricsTranslate;
403 print Lyrics::Fetcher::LyricsTranslate->fetch('Lyube', 'Kombat');
405 # Can also be used via Lyrics::Fetcher but produces ugly output
407 print Lyrics::Fetcher->fetch('Lyube', 'Kombat', 'LyricsTranslate');
411 This module tries to get translated lyrics from
412 L<http://lyricstranslate.com>. It does a search for a translation of
413 the given artist and song title from any language to English, and
414 returns the contents of the first result found.
416 This is a very basic implementation of the concept and it should be
417 improved in future versions (for example supporting multiple
418 destination languages).
420 It is recommended to use the module directly, as using it via
421 L<Lyrics::Fetcher> loses empty lines between parahraphs.
429 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
431 =head1 COPYRIGHT AND LICENSE
433 Copyright (C) 2016 by Marius Gavrilescu
435 This library is free software; you can redistribute it and/or modify
436 it under the same terms as Perl itself, either Perl version 5.24.0 or,
437 at your option, any later version of Perl 5 you may have available.
This page took 0.092021 seconds and 4 git commands to generate.