Skip to content

Commit c9168bb

Browse files
authored
Merge pull request #2622 from ronie/script.cu.lrclyrics-6.6.6
[script.cu.lrclyrics] 6.6.6
2 parents fb35bf6 + 145360a commit c9168bb

File tree

97 files changed

+941
-79
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+941
-79
lines changed

script.cu.lrclyrics/addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="script.cu.lrclyrics" name="CU LRC Lyrics" version="6.6.4" provider-name="Taxigps, ronie">
2+
<addon id="script.cu.lrclyrics" name="CU LRC Lyrics" version="6.6.6" provider-name="Taxigps, ronie">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.beautifulsoup4" version="4.8.2+matrix.1"/>

script.cu.lrclyrics/changelog.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v6.6.6
2+
- fixed several scrapers
3+
4+
v6.6.5
5+
- added "%A - %B - %N - %T" file format
6+
17
v6.6.4
28
- added "%N. %A - %T" file format
39

script.cu.lrclyrics/lib/culrcscrapers/lyricscom/lyricsScraper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
__priority__ = '240'
1111
__lrc__ = False
1212

13+
UserAgent = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
1314

1415
class LyricsFetcher:
1516
def __init__(self, *args, **kwargs):
@@ -25,7 +26,7 @@ def get_lyrics(self, song):
2526
lyrics.source = __title__
2627
lyrics.lrc = __lrc__
2728
try:
28-
request = sess.get(self.url % urllib.parse.quote_plus(song.artist), timeout=10)
29+
request = sess.get(self.url % urllib.parse.quote_plus(song.artist), headers=UserAgent, timeout=10)
2930
response = request.text
3031
except:
3132
return
@@ -37,7 +38,7 @@ def get_lyrics(self, song):
3738
break
3839
if url:
3940
try:
40-
req = sess.get(url, timeout=10)
41+
req = sess.get(url, headers=UserAgent, timeout=10)
4142
resp = req.text
4243
except:
4344
return
@@ -49,7 +50,7 @@ def get_lyrics(self, song):
4950
break
5051
if url:
5152
try:
52-
req2 = sess.get(url, timeout=10)
53+
req2 = sess.get(url, headers=UserAgent, timeout=10)
5354
resp2 = req2.text
5455
except:
5556
return

script.cu.lrclyrics/lib/culrcscrapers/lyricsify/lyricsScraper.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
__priority__ = '130'
1414
__lrc__ = True
1515

16-
UserAgent = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
16+
UserAgent = {"Host": "www.lyricsify.com", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:126.0) Gecko/20100101 Firefox/126.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br, zstd", "DNT": "1", "Alt-Used": "www.lyricsify.com", "Connection": "keep-alive", "Upgrade-Insecure-Requests": "1", "Sec-Fetch-Dest": "document", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Site": "none", "Sec-Fetch-User": "?1", "Priority": "u=1"}
1717

18+
# lyricsify uses captcha's & cloudflare protection for the search option, only direct lyrics access works
1819

1920
class LyricsFetcher:
2021
def __init__(self, *args, **kwargs):
@@ -23,6 +24,30 @@ def __init__(self, *args, **kwargs):
2324
self.SEARCH_URL = 'https://www.lyricsify.com/lyrics/%s/%s'
2425
self.LYRIC_URL = 'https://www.lyricsify.com%s'
2526

27+
def get_lyrics(self, song):
28+
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
29+
lyrics = Lyrics(settings=self.settings)
30+
lyrics.song = song
31+
lyrics.source = __title__
32+
lyrics.lrc = __lrc__
33+
artist = song.artist.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
34+
title = song.title.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
35+
url = self.SEARCH_URL % (artist.lower(), title.lower())
36+
try:
37+
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
38+
search = requests.get(url, headers=UserAgent, timeout=10)
39+
response = search.text
40+
except:
41+
return None
42+
matchcode = re.search('details">(.*?)</div', response, flags=re.DOTALL)
43+
if matchcode:
44+
lyricscode = (matchcode.group(1))
45+
lyr = re.sub('<[^<]+?>', '', lyricscode)
46+
lyrics.lyrics = lyr
47+
return lyrics
48+
return None
49+
50+
'''
2651
def get_lyrics(self, song):
2752
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
2853
lyrics = Lyrics(settings=self.settings)
@@ -73,3 +98,4 @@ def get_lyrics_from_list(self, link):
7398
lyricscode = (matchcode.group(1))
7499
cleanlyrics = re.sub('<[^<]+?>', '', lyricscode)
75100
return cleanlyrics
101+
'''

script.cu.lrclyrics/lib/culrcscrapers/megalobiz/lyricsScraper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from lib.utils import *
1414

1515
__title__ = "Megalobiz"
16-
__priority__ = '140'
16+
__priority__ = '150'
1717
__lrc__ = True
1818

1919

script.cu.lrclyrics/lib/culrcscrapers/musixmatch/lyricsScraper.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import random
1212
import difflib
13+
import html
1314
from bs4 import BeautifulSoup
1415
from lib.utils import *
1516

@@ -20,14 +21,40 @@
2021
headers = {}
2122
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0'
2223

24+
# search is not possible as it requires javascript, only direct access to the lyrics work.
2325

2426
class LyricsFetcher:
2527
def __init__(self, *args, **kwargs):
2628
self.DEBUG = kwargs['debug']
2729
self.settings = kwargs['settings']
28-
self.SEARCH_URL = 'https://www.musixmatch.com/search/'
29-
self.LYRIC_URL = 'https://www.musixmatch.com'
30+
self.SEARCH_URL = 'https://www.musixmatch.com/search?query='
31+
self.LYRIC_URL = 'https://www.musixmatch.com/lyrics/%s/%s'
3032

33+
def get_lyrics(self, song):
34+
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
35+
lyrics = Lyrics(settings=self.settings)
36+
lyrics.song = song
37+
lyrics.source = __title__
38+
lyrics.lrc = __lrc__
39+
artist = song.artist.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
40+
title = song.title.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
41+
url = self.LYRIC_URL % (artist, title)
42+
try:
43+
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
44+
search = requests.get(url, headers=headers, timeout=10)
45+
response = search.text
46+
except:
47+
return None
48+
matchcode = re.search('Lyrics of (.*?)Writer\(s\): ', response, flags=re.DOTALL)
49+
if matchcode:
50+
lyricscode = (matchcode.group(1))
51+
lyr = re.sub('<[^<]+?>', '\n', lyricscode)
52+
lyr = html.unescape(lyr)
53+
lyrics.lyrics = lyr.replace('\n\n\n\n', '\n')
54+
return lyrics
55+
return None
56+
57+
'''
3158
def get_lyrics(self, song):
3259
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
3360
lyrics = Lyrics(settings=self.settings)
@@ -84,3 +111,4 @@ def get_lyrics_from_list(self, link):
84111
for part in lyr:
85112
lyrics = lyrics + part.get_text() + '\n'
86113
return lyrics
114+
'''

script.cu.lrclyrics/lib/culrcscrapers/musixmatchlrc/lyricsScraper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_lyrics(self, song):
7878
search = '%s - %s' % (artist, title)
7979
try:
8080
url = self.SEARCH_URL % 'track.search'
81-
query = [('q', search), ('page_size', '5'), ('page', '1'), ('s_track_rating', 'desc'), ('quorum_factor', '1.0'), ('app_id', 'web-desktop-app-v1.0'), ('usertoken', self.token), ('t', self.current_time)]
81+
query = [('q', search), ('page_size', '5'), ('page', '1'), ('app_id', 'web-desktop-app-v1.0'), ('usertoken', self.token), ('t', self.current_time)]
8282
response = requests.get(url, params=query, timeout=10)
8383
result = response.json()
8484
except:
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#-*- coding: UTF-8 -*-
2+
'''
3+
Scraper for https://www.rclyricsband.com/
4+
'''
5+
6+
import requests
7+
import re
8+
import difflib
9+
from bs4 import BeautifulSoup
10+
from lib.utils import *
11+
12+
__title__ = "RCLyricsBand"
13+
__priority__ = '140'
14+
__lrc__ = True
15+
16+
UserAgent = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"}
17+
18+
class LyricsFetcher:
19+
def __init__(self, *args, **kwargs):
20+
self.DEBUG = kwargs['debug']
21+
self.settings = kwargs['settings']
22+
self.SEARCH_URL = 'https://rclyricsband.com/?search=%s %s'
23+
self.LYRIC_URL = 'https://rclyricsband.com/%s'
24+
25+
26+
def get_lyrics(self, song):
27+
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
28+
lyrics = Lyrics(settings=self.settings)
29+
lyrics.song = song
30+
lyrics.source = __title__
31+
lyrics.lrc = __lrc__
32+
artist = song.artist
33+
title = song.title
34+
try:
35+
url = self.SEARCH_URL % (artist, title)
36+
search = requests.get(url, headers=UserAgent, timeout=10)
37+
response = search.text
38+
except:
39+
return None
40+
links = []
41+
soup = BeautifulSoup(response, 'html.parser')
42+
for link in soup.find_all('a', {'class': 'song_search'}):
43+
if link.string:
44+
foundsong = link.string.split(' - ')[0]
45+
foundartist = link.string.split(' - ')[-1]
46+
if (difflib.SequenceMatcher(None, artist.lower(), foundartist.lower()).ratio() > 0.8) and (difflib.SequenceMatcher(None, title.lower(), foundsong.lower()).ratio() > 0.8):
47+
links.append((foundartist + ' - ' + foundsong, self.LYRIC_URL % link.get('href'), foundartist, foundsong))
48+
if len(links) == 0:
49+
return None
50+
elif len(links) > 1:
51+
lyrics.list = links
52+
for link in links:
53+
lyr = self.get_lyrics_from_list(link)
54+
if lyr:
55+
lyrics.lyrics = lyr
56+
return lyrics
57+
return None
58+
59+
def get_lyrics_from_list(self, link):
60+
title,url,artist,song = link
61+
try:
62+
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
63+
search = requests.get(url, headers=UserAgent, timeout=10)
64+
response = search.text
65+
except:
66+
return None
67+
matchcode = re.search("lrc_text_format'>(.*?)</p", response, flags=re.DOTALL)
68+
if matchcode:
69+
lyricscode = (matchcode.group(1))
70+
cleanlyrics = re.sub('<br>', '', lyricscode)
71+
return cleanlyrics

script.cu.lrclyrics/lib/scrapertest.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from lib.culrcscrapers.music163 import lyricsScraper as lyricsScraper_music163
1313
from lib.culrcscrapers.musixmatch import lyricsScraper as lyricsScraper_musixmatch
1414
from lib.culrcscrapers.musixmatchlrc import lyricsScraper as lyricsScraper_musixmatchlrc
15+
from lib.culrcscrapers.rclyricsband import lyricsScraper as lyricsScraper_rclyricsband
1516
from lib.culrcscrapers.supermusic import lyricsScraper as lyricsScraper_supermusic
1617

1718
FAILED = []
@@ -47,7 +48,7 @@ def test_scrapers():
4748
return
4849

4950
# test darklyrics
50-
dialog.update(8, LANGUAGE(32163) % 'darklyrics')
51+
dialog.update(7, LANGUAGE(32163) % 'darklyrics')
5152
log('==================== darklyrics ====================', debug=True)
5253
song = Song(opt=lyricssettings)
5354
song.artist = 'Neurosis'
@@ -66,7 +67,7 @@ def test_scrapers():
6667
return
6768

6869
# test genius
69-
dialog.update(16, LANGUAGE(32163) % 'genius')
70+
dialog.update(14, LANGUAGE(32163) % 'genius')
7071
log('==================== genius ====================', debug=True)
7172
song = Song(opt=lyricssettings)
7273
song.artist = 'Maren Morris'
@@ -85,7 +86,7 @@ def test_scrapers():
8586
return
8687

8788
# test lrclib
88-
dialog.update(24, LANGUAGE(32163) % 'lrclib')
89+
dialog.update(21, LANGUAGE(32163) % 'lrclib')
8990
log('==================== lrclib ====================', debug=True)
9091
song = Song(opt=lyricssettings)
9192
song.artist = 'CHVRCHES'
@@ -104,7 +105,7 @@ def test_scrapers():
104105
return
105106

106107
# test lyricscom
107-
dialog.update(32, LANGUAGE(32163) % 'lyricscom')
108+
dialog.update(28, LANGUAGE(32163) % 'lyricscom')
108109
log('==================== lyricscom ====================', debug=True)
109110
song = Song(opt=lyricssettings)
110111
song.artist = 'Blur'
@@ -123,11 +124,11 @@ def test_scrapers():
123124
return
124125

125126
# test lyricsify
126-
dialog.update(40, LANGUAGE(32163) % 'lyricsify')
127+
dialog.update(35, LANGUAGE(32163) % 'lyricsify')
127128
log('==================== lyricsify ====================', debug=True)
128129
song = Song(opt=lyricssettings)
129-
song.artist = 'Madonna'
130-
song.title = 'Crazy For You'
130+
song.artist = 'Tears For Fears'
131+
song.title = 'Shout'
131132
st = time.time()
132133
lyrics = lyricsScraper_lyricsify.LyricsFetcher(settings=lyricssettings, debug=True).get_lyrics(song)
133134
ft = time.time()
@@ -142,7 +143,7 @@ def test_scrapers():
142143
return
143144

144145
# test lyricsmode
145-
dialog.update(48, LANGUAGE(32163) % 'lyricsmode')
146+
dialog.update(42, LANGUAGE(32163) % 'lyricsmode')
146147
log('==================== lyricsmode ====================', debug=True)
147148
song = Song(opt=lyricssettings)
148149
song.artist = 'Maren Morris'
@@ -161,7 +162,7 @@ def test_scrapers():
161162
return
162163

163164
# test megalobiz
164-
dialog.update(56, LANGUAGE(32163) % 'megalobiz')
165+
dialog.update(50, LANGUAGE(32163) % 'megalobiz')
165166
log('==================== megalobiz ====================', debug=True)
166167
song = Song(opt=lyricssettings)
167168
song.artist = 'Michael Jackson'
@@ -180,7 +181,7 @@ def test_scrapers():
180181
return
181182

182183
# test music163
183-
dialog.update(64, LANGUAGE(32163) % 'music163')
184+
dialog.update(58, LANGUAGE(32163) % 'music163')
184185
log('==================== music163 ====================', debug=True)
185186
song = Song(opt=lyricssettings)
186187
song.artist = 'Madonna'
@@ -199,7 +200,7 @@ def test_scrapers():
199200
return
200201

201202
# test musixmatch
202-
dialog.update(72, LANGUAGE(32163) % 'musixmatch')
203+
dialog.update(66, LANGUAGE(32163) % 'musixmatch')
203204
log('==================== musixmatch ====================', debug=True)
204205
song = Song(opt=lyricssettings)
205206
song.artist = 'Kate Bush'
@@ -218,7 +219,7 @@ def test_scrapers():
218219
return
219220

220221
# test musixmatchlrc
221-
dialog.update(80, LANGUAGE(32163) % 'musixmatchlrc')
222+
dialog.update(73, LANGUAGE(32163) % 'musixmatchlrc')
222223
log('==================== musixmatchlrc ====================', debug=True)
223224
song = Song(opt=lyricssettings)
224225
song.artist = 'Kate Bush'
@@ -236,6 +237,25 @@ def test_scrapers():
236237
if dialog.iscanceled():
237238
return
238239

240+
# test rclyricsband
241+
dialog.update(80, LANGUAGE(32163) % 'rclyricsband')
242+
log('==================== rclyricsband ====================', debug=True)
243+
song = Song(opt=lyricssettings)
244+
song.artist = 'Taylor Swift'
245+
song.title = 'The Archer'
246+
st = time.time()
247+
lyrics = lyricsScraper_rclyricsband.LyricsFetcher(settings=lyricssettings, debug=True).get_lyrics(song)
248+
ft = time.time()
249+
tt = ft - st
250+
TIMINGS.append(['rclyricsband',tt])
251+
if lyrics:
252+
log(lyrics.lyrics, debug=True)
253+
else:
254+
FAILED.append('rclyricsband')
255+
log('FAILED: rclyricsband', debug=True)
256+
if dialog.iscanceled():
257+
return
258+
239259
# test supermusic
240260
dialog.update(88, LANGUAGE(32163) % 'supermusic')
241261
log('==================== supermusic ====================', debug=True)

script.cu.lrclyrics/lib/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def get_artist_from_filename(*args, **kwargs):
7676
elif SETTING_READ_FILENAME_FORMAT == 4:
7777
artist = basename.split('-', 2)[1].strip()
7878
title = os.path.splitext(basename.split('-', 2)[2].strip())[0]
79+
elif SETTING_READ_FILENAME_FORMAT == 6:
80+
artist = basename.split('-', 1)[0].strip()
81+
title = os.path.splitext(basename.split('-', 3)[3].strip())[0]
7982
except:
8083
# invalid format selected
8184
log('failed to get artist and title from filename', debug=DEBUG)

0 commit comments

Comments
 (0)