forked from alexxxnf/VLC-Lyrics-Finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyricsfinder.lua
1474 lines (1286 loc) · 42.7 KB
/
lyricsfinder.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--Lyrics Finder
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 2 of the License, or
-- (at your option) any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- Lyrics Finder incorporates some code of VLsub.
--Supported websites (by priority)
--MetroLyrics (1 000 000 song lyrics)
--Sonic Hits (many lyrics)
--Lyrics Mode (1 000 000 song lyrics)
--Golyr.de
--AZ Lyrics
--Lyrics.com (-)
--Lyricsmania.com (-) (is http://www.parolesmania.com the same?)
-- FIXME: add additional site compatibility
--------- http://lyrics123.net (500.000 song lyrics)
--------- http://www.azlyrics.com/lyrics/whispers/mygirl.html
--------- http://www.songteksten.nl/ (Dutch songs)
--------- http://www.lyricsfreak.com (+ instead of _) -> we will need to use the artist page here
--------- http://decoda.com/
--------- Requires use of the search page to implement
--------- http://www.lyricsondemand.com/results.html?q=kiss+from+a+rose (.gs-per-result-labels)
--------- http://www.lyrics007.com/search.php?q=whitney+houston (only title or author, not both, requires adding prefix)
--------- http://www.lyricsplanet.com
--------- http://letssingit.com
--------- http://www.lyricsfly.com
--------- http://www.lyred.com (not well updated)
--------- http://www.songteksten.net (uses ids)
--------- Less coverage / otherwise less interesting
--------- http://lyrics.wikia.com (not accurate)
--------- http://www.lyricsfind.com (bad coverage)
--------- http://lyricsvault.net (bot protection - maybe we can get around it)
--------- https://www.musixmatch (doesn't work)
-- FIXME: add built-in search when page is not found
-- FIXME: make use of artist page on metrolyrics.com when we end up there
-- FIXME: make use of search page: http://www.lyricsmode.com/search.php?search=i%27m%20gonna%20make%20you%20love%20me
-- FIXME: add intelligent guessing for artist / title position (artist first or title first?)
--------- LONGEST = title, unless difference < 5 chars (use default)
--------- LONGEST = author if it includes AND or &
--------- MOST SPACES = title
-- FIXME: Title (extratitle) for Metro Lyrics
-- FIXME: In another life, I would like to add acoustic fingerprinting
dlg = nil
title = nil
artist = nil
lyric = nil
source_label = nil
debug_enabled = false
langcode = "" --dut
translation = {
dialogtitle_normal = 'Lyrics',
dialogtitle_notfound = 'Not Found',
dialogtitle_lyricsof= 'Lyrics of',
dialogtitle_performedby = 'by',
button_getlyrics = 'Get Lyrics',
button_refresh = 'Refresh',
button_switch = 'Switch',
button_close = 'Close',
button_google = 'Search with Google',
button_update = 'Get updates',
label_title = 'Title:',
label_artist = 'Artist:',
label_source = 'Source:',
message_newsong = 'New song loaded. To get the lyrics, click Get Lyrics.',
message_loading = "Loading..",
message_incorrect = 'Incorrect artist or title.',
message_notfound = 'Lyrics not found.'
}
languages = {
{'afr', 'Afrikaans'},
{'alb', 'Albanian'},
{'ara', 'Arabic'},
{'arm', 'Armenian'},
{'baq', 'Basque'},
{'ben', 'Bengali'},
{'bos', 'Bosnian'},
{'bre', 'Breton'},
{'bul', 'Bulgarian'},
{'bur', 'Burmese'},
{'cat', 'Catalan'},
{'chi', 'Chinese'},
{'hrv', 'Croatian'},
{'cze', 'Czech'},
{'dan', 'Danish'},
{'dut', 'Dutch'},
{'eng', 'English'},
{'epo', 'Esperanto'},
{'est', 'Estonian'},
{'fin', 'Finnish'},
{'fre', 'French'},
{'glg', 'Galician'},
{'geo', 'Georgian'},
{'ger', 'German'},
{'ell', 'Greek'},
{'heb', 'Hebrew'},
{'hin', 'Hindi'},
{'hun', 'Hungarian'},
{'ice', 'Icelandic'},
{'ind', 'Indonesian'},
{'ita', 'Italian'},
{'jpn', 'Japanese'},
{'kaz', 'Kazakh'},
{'khm', 'Khmer'},
{'kor', 'Korean'},
{'lav', 'Latvian'},
{'lit', 'Lithuanian'},
{'ltz', 'Luxembourgish'},
{'mac', 'Macedonian'},
{'may', 'Malay'},
{'mal', 'Malayalam'},
{'mon', 'Mongolian'},
{'nor', 'Norwegian'},
{'oci', 'Occitan'},
{'per', 'Persian'},
{'pol', 'Polish'},
{'por', 'Portuguese'},
{'pob', 'Brazilian Portuguese'},
{'rum', 'Romanian'},
{'rus', 'Russian'},
{'scc', 'Serbian'},
{'sin', 'Sinhalese'},
{'slo', 'Slovak'},
{'slv', 'Slovenian'},
{'spa', 'Spanish'},
{'swa', 'Swahili'},
{'swe', 'Swedish'},
{'syr', 'Syriac'},
{'tgl', 'Tagalog'},
{'tel', 'Telugu'},
{'tha', 'Thai'},
{'tur', 'Turkish'},
{'ukr', 'Ukrainian'},
{'urd', 'Urdu'},
{'vie', 'Vietnamese'}
}
-- Languages code conversion table: iso-639-1 to iso-639-3
-- See https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
local lang_os_to_iso = {
af = "afr",
sq = "alb",
ar = "ara",
hy = "arm",
eu = "baq",
bn = "ben",
bs = "bos",
br = "bre",
bg = "bul",
my = "bur",
ca = "cat",
zh = "chi",
hr = "hrv",
cs = "cze",
da = "dan",
nl = "dut",
en = "eng",
eo = "epo",
et = "est",
fi = "fin",
fr = "fre",
gl = "glg",
ka = "geo",
de = "ger",
el = "ell",
he = "heb",
hi = "hin",
hu = "hun",
is = "ice",
id = "ind",
it = "ita",
ja = "jpn",
kk = "kaz",
km = "khm",
ko = "kor",
lv = "lav",
lt = "lit",
lb = "ltz",
mk = "mac",
ms = "may",
ml = "mal",
mn = "mon",
no = "nor",
oc = "oci",
fa = "per",
pl = "pol",
pt = "por",
po = "pob",
ro = "rum",
ru = "rus",
sr = "scc",
si = "sin",
sk = "slo",
sl = "slv",
es = "spa",
sw = "swa",
sv = "swe",
tl = "tgl",
te = "tel",
th = "tha",
tr = "tur",
uk = "ukr",
ur = "urd",
vi = "vie"
}
-- start of VLC required functions
-- VLC Extension Descriptor
function descriptor()
return {
title = "Lyrics Finder";
version = "0.3.7";
author = "rsyh93, alexxxnf, Smile4ever";
url = 'https://github.com/Smile4ever/VLC-Lyrics-Finder';
description = "<center><b>Lyrics Finder</b></center>"
.. "<br /><b>Gets the lyrics for your favorite songs</b>"
.. "<br /><b>(Based on the script made by Jean-Philippe Andre)</b>"
.. "<br /><b>(Modified by Aleksey Maydokin)</b>"
.. "<br /><b>(Modified and translated by Geoffrey De Belie</b>";
shortdesc = "Lyrics Finder";
capabilities = { "input-listener"; "meta-listener"; "playing-listener" }
}
end
-- Function triggered when the extension is activated
function activate()
vlc.msg.dbg(_VERSION) --display Lua version in the VLC message window
vlc.msg.dbg("[Lyrics Finder] Activating ")
langcode = getenv_lang() --auto guess
if dlg then
dlg:show()
end
show_dialog()
return true
end
function close()
deactivate()
end
-- Function triggered when the extension is deactivated
function deactivate()
reset_variables()
vlc.deactivate()
vlc.msg.dbg("[Lyrics Finder] Deactivated")
return true
end
function new_dialog(title)
dlg=vlc.dialog(title)
end
function show_dialog()
en_translation = translation --make a copy
if langcode then
--GPL code from VLsub (adapted)
if get_platform() == "windows" then
slash = "\\"
else
slash = "/"
end
local path_generic = {"lua", "extensions", "lyricsfinder", "locale"}
local dirPath = slash..table.concat(path_generic, slash)..slash
local transl_file_userpath = vlc.config.userdatadir() .. dirPath .. langcode .. ".xml"
--prefer user file
if file_exist(transl_file_userpath) then
vlc.msg.dbg("[Lyrics Finder] Loading translation from user file " .. transl_file_userpath)
load_transl(transl_file_userpath,langcode)
else
--use system file if no user file is present
local transl_file_syspath = vlc.config.datadir() .. dirPath .. langcode .. ".xml"
if file_exist(transl_file_syspath) then
vlc.msg.dbg("[Lyrics Finder] Loading translation from system file " .. transl_file_syspath)
load_transl(transl_file_syspath,langcode)
end
end
--end GPL code from VLsub (adapted)
end
if dlg == nil then
new_dialog(translation["dialogtitle_normal"])
end
-- column, row, col_span, row_span, width, height
dlg:add_label(translation["label_title"], 1, 1, 1, 1)
title = dlg:add_text_input(get_title(), 2, 1, 3, 1)
dlg:add_label(translation["label_artist"], 1, 2, 1)
artist = dlg:add_text_input(get_artist(), 2, 2, 3)
dlg:add_button("Save lyrics", click_save, 5, 1, 1)
--dlg:add_button(translation["button_refresh"], update_metas, 5, 1, 1)
--dlg:add_button("Lyrics Connect", lyricsconnect, 5, 2, 1)
dlg:add_button(translation["button_switch"], click_switch, 5, 2, 1)
dlg:add_button(translation["button_getlyrics"], update_lyrics, 1, 3, 1)
dlg:add_button(translation["button_google"], click_google, 2, 3, 1)
source_label=dlg:add_label(translation["label_source"], 3, 3, 1)
dlg:add_button(translation["button_update"], download_update, 5, 3, 1)
-- dlg:add_button(translation["button_close"], deactivate, 5, 3, 1)
lyric = dlg:add_html("", 1, 4, 7, 12, 7, 12)
update_lyrics()
return true
end
-- Resets dialog
function reset_variables()
dlg = nil
title = nil
artist = nil
lyric = nil
source_label = nil
languages = nil
translation = nil
end
-- Update input fields and lyrics (refresh functionality)
function update_metas()
title:set_text(get_title())
artist:set_text(get_artist())
update_lyrics()
dlg:update()
return true
end
-- end of VLC functions
--GPL code from VLSub
function load_transl(path,code)
langcode = code
local tmpFile = assert(io.open(path, "rb"))
local resp = tmpFile:read("*all")
tmpFile:flush()
tmpFile:close()
translation = nil
translation = parse_xml(resp)
apply_translation()
end
--GPL code from VLSub
function apply_translation()
-- Overwrite default conf with loaded conf
for k, v in pairs(en_translation) do
if not translation[k] then
translation[k] = en_translation[k]
--else
--vlc.msg.dbg("Lyrics Finder" .. translation[k])
end
end
end
--GPL code from VLSub
function file_exist(name) -- test readability
if not name or trim(name) == ""
then return false end
local f=io.open(name ,"r")
if f~=nil then
io.close(f)
return true
else
return false
end
end
--GPL code from VLSub
function parse_xml(data)
local tree = {}
local stack = {}
local tmp = {}
local level = 0
local op, tag, p, empty, val
table.insert(stack, tree)
for op, tag, p, empty, val in string.gmatch(
data,
"[%s\r\n\t]*<(%/?)([%w:_]+)(.-)(%/?)>[%s\r\n\t]*([^<]*)[%s\r\n\t]*"
) do
if op=="/" then
if level>0 then
level = level - 1
table.remove(stack)
end
else
level = level + 1
if val == "" then
if type(stack[level][tag]) == "nil" then
stack[level][tag] = {}
table.insert(stack, stack[level][tag])
else
if type(stack[level][tag][1]) == "nil" then
tmp = nil
tmp = stack[level][tag]
stack[level][tag] = nil
stack[level][tag] = {}
table.insert(stack[level][tag], tmp)
end
tmp = nil
tmp = {}
table.insert(stack[level][tag], tmp)
table.insert(stack, tmp)
end
else
if type(stack[level][tag]) == "nil" then
stack[level][tag] = {}
end
stack[level][tag] = vlc.strings.resolve_xml_special_chars(val)
table.insert(stack, {})
end
if empty ~= "" then
stack[level][tag] = ""
level = level - 1
table.remove(stack)
end
end
end
collectgarbage()
return tree
end
--GPL code from VLsub
function getenv_lang()
-- Retrieve the user OS language
local os_lang = os.getenv("LANG")
if not os_lang then
os_lang = os.getenv("LC_ALL")
end
if os_lang then -- unix, mac
os_lang = string.sub(os_lang, 0, 2)
if type(lang_os_to_iso[os_lang]) then
return lang_os_to_iso[os_lang]
end
else -- Windows
local lang_w = string.match(os.setlocale("", "collate"), "^[^_]+")
for i, v in ipairs(languages) do
if v[2] == lang_w then
return v[1]
end
end
end
end
function click_save()
local path = ""
local platform = get_platform()
local filename = ""
local lyricsText = trim(cleanHTML(lyric:get_text()))
if platform == "unix" then
path = "/tmp/"
end
if platform == "windows" then
path = "C:\\Temp\\"
end
filename = path .. "Lyrics " .. artist:get_text() .. " - " .. title:get_text() .. ".txt"
vlc.msg.dbg("[Lyrics Finder] Platform is " .. platform);
vlc.msg.dbg("[Lyrics Finder] Filename is " .. filename);
vlc.msg.dbg("[Lyrics Finder] Text is " .. lyricsText);
local lines = magiclines(lyricsText)
vlc.msg.dbg("[Lyrics Finder] Text is " .. lyricsText);
local firstLine = true
for line in magiclines(lyricsText) do
if firstLine == false then
os.execute(string.format('echo "%s" >> "' .. filename .. '"', line))
else
os.execute(string.format('echo "%s" > "' .. filename .. '"', line))
firstLine = false
end
end
if platform == "unix" then
os.execute(string.format('xdg-open "%s"', filename))
end
if platform == "windows" then
os.execute(string.format('start "" "%s"', filename))
end
end
function click_switch()
local title_local = title:get_text()
title:set_text(artist:get_text())
artist:set_text(title_local)
dlg:update()
return true
end
function click_google()
local query = artist:get_text() .. " - " .. title:get_text()
query = query:gsub('&', 'and')
query = query .. "+lyrics"
open_url("https://google.com/search?q=" .. query)
end
function get_downloads_path()
local download_path = os.getenv("XDG_DOWNLOAD_DIR")
if not download_path then
download_path = os.getenv("HOME")
if download_path then
download_path = download_path .. "/Downloads"
end
end
return download_path
end
function download_update()
--local installed_version = descriptor()["version"]
open_url("https://github.com/Smile4ever/VLC-Lyrics-Finder")
end
function lyricsconnect()
local current_song = readfile(get_downloads_path() .. "/current-song.txt");
if current_song then
vlc.msg.dbg("current_song is " .. current_song)
local artistc = get_artist(current_song)
local titlec = get_title(current_song)
artist:set_text(artistc)
title:set_text(titlec)
update_lyrics()
end
end
function readfile(path)
local tmpFile = assert(io.open(path, "rb"))
local resp = tmpFile:read("*a")
tmpFile:flush()
tmpFile:close()
return resp
end
function get_lyrics(title_x, artist_x)
if title_x == "" or artist_x == "" then
return ""
end
title_x = trim(title_x)
artist_x = trim(artist_x)
title_x = string.gsub(title_x, " ", "_")
artist_x = artist_x:gsub('%s_%s', ' and ') --Womack _ Womack - Friends
artist_x = string.gsub(artist_x, " ", "_")
title_x = string.lower(title_x)
artist_x = string.lower(artist_x)
title_x = title_x:gsub("-", "_")
local original_title = title_x
title_x = title_x:gsub('[^%w_]','')
title_x = title_x:gsub('&','and')
artist_x = artist_x:gsub('&', 'and')
--artist_x = artist_x:gsub('_&_','_and_')
artist_x = artist_x:gsub('_&_','_')
artist_x = artist_x:gsub('%.','')
artist_x = artist_x:gsub('ó', 'o') --Róisín Murphy
artist_x = artist_x:gsub('í', 'i') --Róisín Murphy
local artist_metro = artist_x:gsub('[-]','') --a-ha is aha on metro lyrics, but a_ha on lyrics mode
artist_metro = artist_metro:gsub('_','-')
artist_x = artist_x:gsub('[-]','_')
--artist_x = artist_x:gsub('[^%w_]','')
local metrotitle = title_x:gsub('_','-')
local url = ""
local lyric_string = ""
local isLyricsMode = false
if is_lyric_page(lyric_string) == false then
local metrourl = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..artist_metro..".html"
local artist_and_location = string.find(artist_metro, "-and-")
if artist_and_location then
artist_and_location = artist_metro:find("and", artist_and_location - 2)
if artist_and_location then
local tried_together_and
local tried_together_withdash
if is_lyric_page(lyric_string) == false then
--vlc.msg.dbg("location:" .. string.len(artist_metro) - artist_and_location)
if string.len(artist_metro) - artist_and_location < 14 then
--quick code path to reduce the number of false tries
--probably not two separate artists, but one with a & in the name
--together
lyric_string = fetch_lyrics(metrourl)
tried_together_and = true
if is_lyric_page(lyric_string) == false then
--together with a dash
local new_artist_metro = artist_metro:sub(1, artist_and_location - 2) .. "-" .. artist_metro:sub(artist_and_location + 4)
local url = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
tried_together_withdash = true
end
end
end
local first_artist_url
if is_lyric_page(lyric_string) == false then
--first artist
local new_artist_metro = artist_metro:sub(1, artist_and_location - 2)
local url = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html" --must be the same as above (except for the new_)
first_artist_url = url
lyric_string = fetch_lyrics(url)
end
if is_lyric_page(lyric_string) == false then
--second artist
local new_artist_metro = artist_metro:sub(artist_and_location + 4)
local url = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html" --must be the same as above (except for the new_)
if first_artist_url == url then
--do nothing
else
lyric_string = fetch_lyrics(url)
end
end
if is_lyric_page(lyric_string) == false and tried_together_withdash == false then
--together with a dash
local new_artist_metro = artist_metro:sub(1, artist_and_location - 2) .. "-" .. artist_metro:sub(artist_and_location + 4)
local url = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
end
if is_lyric_page(lyric_string) == false then
--try again without and between artists
local new_artist_metro = artist_metro:sub(1, artist_and_location - 2) .. artist_metro:sub(artist_and_location + 4)
local url = "http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
end
if is_lyric_page(lyric_string) == false and tried_together_and == false then
--together
lyric_string = fetch_lyrics(metrourl)
end
end
else
lyric_string = fetch_lyrics(metrourl)
if is_lyric_page(lyric_string) == false and string.find(artist_metro, 'the%-') then
local new_artist_metro = artist_metro:gsub('the%-','')
lyric_string = fetch_lyrics("http://www.metrolyrics.com/"..metrotitle.."-lyrics-"..new_artist_metro..".html")
end
end
source_label:set_text("MetroLyrics")
isLyricsMode = false;
end
--best coverage, but a bit slow to put first
if is_lyric_page(lyric_string) == false then
url = "http://sonichits.com/video/" .. artist_x .. "/" .. original_title:gsub("-", "_")
lyric_string = fetch_lyrics(url)
source_label:set_text("Sonic Hits")
isLyricsMode = false
end
local artist_and_location = artist_x:find("_and_")
if artist_and_location then
artist_and_location = artist_x:find("and", artist_and_location - 2)
end
if artist_and_location then
if is_lyric_page(lyric_string) == false then
local new_artist_x = artist_x:sub(1, artist_and_location - 2) .. "_" .. artist_x:sub(artist_and_location + 4)
url = "http://www.lyricsmode.com/lyrics/"..new_artist_x:sub(1,1).."/"..new_artist_x.."/"..title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
end
local first_artist_name
if is_lyric_page(lyric_string) == false then
if artist_and_location then
artist_and_location = artist_x:find("and", artist_and_location - 2)
--try again without and (first artist)
local new_artist_x = artist_x:sub(1, artist_and_location - 2)
first_artist_name = new_artist_x
url = "http://www.lyricsmode.com/lyrics/"..new_artist_x:sub(1,1).."/"..new_artist_x.."/"..title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
if is_lyric_page(lyric_string) == false then
url = "http://www.lyricsmode.com/lyrics/"..artist_x:sub(1,1).."/"..artist_x.."/"..title_x..".html"
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
end
if is_lyric_page(lyric_string) == false then
local artist_and_location = artist_x:find("_and_")
if artist_and_location then
artist_and_location = artist_x:find("and", artist_and_location - 2)
--try again without and (second artist)
local new_artist_x = artist_x:sub(artist_and_location + 4) --length of and + 1
if first_artist_name == new_artist_x then
--try again without and (before: do nothing)
-- Womack & Womack - MPB
local new_artist_x = artist_x:sub(1, artist_and_location - 2) .. "_" .. artist_x:sub(artist_and_location + 4)
url = "http://www.lyricsmode.com/lyrics/"..new_artist_x:sub(1,1).."/"..new_artist_x.."/"..title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
else
url = "http://www.lyricsmode.com/lyrics/"..new_artist_x:sub(1,1).."/"..new_artist_x.."/"..title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
end
end
if is_lyric_page(lyric_string) == false then
local title_dec_loc = title_x:find("twee")
if title_dec_loc then
--try again, replacing the full word with a decimal
local new_title_x = title_x:gsub("twee", "2")
url = "http://www.lyricsmode.com/lyrics/"..artist_x:sub(1,1).."/"..artist_x.."/"..new_title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
end
if is_lyric_page(lyric_string) == false then
local artist_the_location = artist_x:find("the")
if artist_the_location then
--try again without the
local new_artist_x = artist_x:gsub("the_", "")
url = "http://www.lyricsmode.com/lyrics/"..new_artist_x:sub(1,1).."/"..new_artist_x.."/"..title_x..".html" --must be the same as above (except for the new_)
lyric_string = fetch_lyrics(url)
isLyricsMode = true
end
end
if isLyricsMode then
source_label:set_text("LyricsMode")
if lyric_string == nil then
return ""
end
--Lyrics Mode has some problems with encoding, fix these before showing (todo: this crashes on some songs)
lyric_string = lyric_string:gsub('ґ', "%'") --replace ґt with 't
lyric_string = lyric_string:gsub('й', "é") --French
lyric_string = lyric_string:gsub("к", "ê") --French
lyric_string = lyric_string:gsub("и", "è") --French
lyric_string = lyric_string:gsub("ы", "û") --French
lyric_string = lyric_string:gsub("њ", "œ") --French
lyric_string = lyric_string:gsub("д", "ä") --German
--cleanup first lines
local lower_artist_name = string.lower(artist:get_text())
local lower_title = string.lower(title:get_text())
local lower_lyric_string = string.lower(lyric_string)
local pos_author = lower_lyric_string:find(lower_artist_name)
local pos_title = lower_lyric_string:find(lower_title)
local pos_newline = lower_lyric_string:find("\n")
--check if the first line is empty
if pos_newline then
if pos_newline == 1 then
lyric_string = lyric_string:sub(pos_newline+1) --remove the first line (=empty line)
end
end
if pos_author then
--remove author name from first line(s)
if pos_author < pos_newline then
--contains
lyric_string = lyric_string:sub(pos_newline+1) --remove the first line (=artist name)
end
end
if pos_title then
--remove title from first line(s)
--pos_newline = lyric_string:find("\n", pos_newline+1)
if pos_title < pos_newline then
--contains
lyric_string = lyric_string:sub(pos_newline+1) --remove the first line (=title)
end
end
if pos_newline then
pos_new_newline = lyric_string:find("\n", pos_newline+1)
--artist:set_text(pos_newline .. "-" .. pos_new_newline)
if pos_new_newline == pos_newline+1 then
--next line is empty
lyric_string = lyric_string:sub(pos_new_newline+1)
end
end
end
if is_lyric_page(lyric_string) == false then
url = "http://www.golyr.de/" .. artist_x:gsub("_","-") .. "/songtext-" .. title_x:gsub("_", "-")
lyric_string = fetch_lyrics(url)
source_label:set_text("Golyr.de")
isLyricsMode = false
end
if is_lyric_page(lyric_string) == false then
url = "http://www.azlyrics.com/lyrics/" .. artist_x:gsub("_", "") .. "/" .. title_x:gsub("_", "") ..".html"
lyric_string = fetch_lyrics(url)
source_label:set_text("AZ Lyrics")
isLyricsMode = false
end
if is_lyric_page(lyric_string) == false then
url = "http://www.lyrics.com/"..title_x:gsub("_", "-").."-lyrics-"..artist_x:gsub("_", "-")..".html"
lyric_string = fetch_lyrics(url)
source_label:set_text("Lyrics.com")
isLyricsMode = false
end
if is_lyric_page(lyric_string) == false then
url = "http://www.lyricsmania.com/"..title_x:gsub("-", "_").."_lyrics_"..artist_x..".html"
lyric_string = fetch_lyrics(url)
source_label:set_text("LyricsMania")
end
if lyric_string == nil then
return ""
else
return lyric_string
end
end
function trim6(s)
return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end
function fetch_lyrics(url)
local metro_pos = url:find('metrolyrics')
local lyricsmania = url:find('lyricsmania')
local lyricscom = url:find('lyrics%.com')
local sonichits = url:find('sonichits')
local azlyrics = url:find('azlyrics')
local lyricsmode = url:find('lyricsmode')
local musixmatch = url:find('musixmatch')
local golyr = url:find('golyr')
--http://www.golyr.de/audrey-landers/songtext-honeymoon-in-trindidad
--DEBUG
--if metro_pos or lyricsmania or sonichits or golyr or lyricsmode then
-- return ""
--end
if debug_enabled then
vlc.msg.dbg("[Lyrics Finder] Fetch " .. url)
if lyric:get_text():find("http") then
lyric:set_text(lyric:get_text() ..url.."<br>")
else
lyric:set_text(url.."<br>")
end
else
if lyric:get_text():find(translation["message_loading"]) then
lyric:set_text(lyric:get_text() ..".")
else
lyric:set_text(translation["message_loading"])
end
end
dlg:update()
local s = vlc.stream(url)
if not s then
return ""
end
local data = s:read(65535)
data = string.gsub(data, "&#(%d+)", string.char);
if metro_pos then
--MetroLyrics
local a = string.find(data, 'lyrics%-body', 1)
if a == nil then
return ""
end
-- if any of these can be missing from data, additional checks must be made
local widgetRelated = string.find(data, '<!%-%-WIDGET %- RELATED%-%->', a)
local endWidgetRelated = string.find(data, '<!%-%-END WIDGET %- RELATED%-%->', a)
local widgetPhotos = string.find(data, '<!%-%-WIDGET %- PHOTOS%-%->', a)
local endWidgetPhotos = string.find(data, '<!%-%-END WIDGET %- PHOTOS%-%->', a)
data = data:sub(0, widgetRelated) ..
data:sub(endWidgetRelated, widgetPhotos) ..
data:sub(endWidgetPhotos)
local lyricsEnd = string.find(data, "writers", a) - 10
return trim6(data:sub(a + 13, lyricsEnd))
end
if lyricsmania then
local strong_text = "</strong>"
local lyrics_to = string.find(data, "Lyrics to")
if lyrics_to == nil then
return ""
end
--, lyrics_to , +
local _,a = string.find(data, strong_text, lyrics_to)
if a == nil then
return ""
end
local b,_ = string.find(data, "</div>", a + strong_text:len(), true)
return data:sub(a+1,b-1)
end
if lyricsmode then
--lyrics_text
--local a = string.find(data, '<p id="lyrics_text" class="ui-annotatable">')
local a = string.find(data, '<p id="lyrics_text"')
if a == nil then
return "";
end
local endofstring = '>'
local position = string.find(data, endofstring, a)
if position == nil then
return ""
end
local b,_ = string.find(data, "</p>", a, true)
return data:sub(position+1,b-1)
end
if sonichits then
local a = string.find(data, '<div id="lyrics"')
if a == nil then
return "";
end
local endofstring = '<br>'
local position = string.find(data, endofstring, a)
if position == nil then
return ""
end
position = string.find(data, endofstring, position+1)
if position == nil then
return ""
end
local b = string.find(data, "Contributed by", a)
if b == nil then
b = string.find(data, "Lyrics", a)
end
if b == nil then
b = string.find(data, "</div>", a)
else
b = string.find(data, "<br>", b-10)
end
if b == nil then
return ""
end
return data:sub(position+4,b-1)
end
if golyr then
local a = string.find(data, '<div id="lyrics"')
if a == nil then
return "";
end
local endofstring = 'h2'
local position = string.find(data, endofstring, a)