Skip to content

Commit

Permalink
Upgrade to CU LRC 6.6.7 which adds RCLyricsBand and fixes others
Browse files Browse the repository at this point in the history
  • Loading branch information
twitham1 committed Sep 1, 2024
1 parent c7ed5e9 commit dc527d0
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 26 deletions.
2 changes: 2 additions & 0 deletions mythtv/programs/scripts/metadata/Music/lyrics/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ addon.xml
default.py
README.txt
resources
lib/gui.py
lib/sync.py

# twitham's extra files not needed:
filetweak.py
5 changes: 3 additions & 2 deletions mythtv/programs/scripts/metadata/Music/lyrics/README
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ FileLyrics 90 Yes/No
musixmatchlrc 100 Yes NEW in v34
lrclib 110 Yes NEW in v34
lyricsify 130 Yes NEW in v34
rclyricsband 140 Yes NEW in v35 2024/08
genius 200 No
musixmatch 210 No NEW in v34
lyricsmode 220 No
azlyrics 230 No NEW in v34
lyricscom 240 No
supermusic 250 No NEW in v34
darklyrics 260 No
megalobiz 400 Yes (too slow to be earlier, was 140)
megalobiz 400 Yes (too slow to be earlier, was 150)
music163 500 Yes (sometimes returns author only, was 120)


Expand All @@ -52,7 +53,7 @@ Simply overwrite lib/ with the latest from the source:
2 of addon.xml in the source and update the latest version number
into the header of ./common/culrcwrap.py

* ./testlyrics -k -t
* ./testlyrics.pl -k -t

That's all!

Expand Down
20 changes: 20 additions & 0 deletions mythtv/programs/scripts/metadata/Music/lyrics/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
v6.6.7
- fixed RCLyricsBand scraper

v6.6.6
- fixed several scrapers

v6.6.5
- added "%A - %B - %N - %T" file format

v6.6.4
- added "%N. %A - %T" file format

v6.6.3
- fix issue with empty ListItem.Property(part1)
- fix for spotify (and others) not in sync
- don't search online sources for saved lyrics files

v6.6.2
- improve megalobiz scraper

v6.6.1
- add supermusic scraper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# UPDATE THIS from https://gitlab.com/ronie/script.cu.lrclyrics
# second line of its addon.xml:
__version__ = '6.6.2'
__version__ = '6.6.7'

# simulate kodi/xbmc via very simplified Kodistubs.
import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
__priority__ = '240'
__lrc__ = False

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"}

class LyricsFetcher:
def __init__(self, *args, **kwargs):
Expand All @@ -25,7 +26,7 @@ def get_lyrics(self, song):
lyrics.source = __title__
lyrics.lrc = __lrc__
try:
request = sess.get(self.url % urllib.parse.quote_plus(song.artist), timeout=10)
request = sess.get(self.url % urllib.parse.quote_plus(song.artist), headers=UserAgent, timeout=10)
response = request.text
except:
return
Expand All @@ -37,7 +38,7 @@ def get_lyrics(self, song):
break
if url:
try:
req = sess.get(url, timeout=10)
req = sess.get(url, headers=UserAgent, timeout=10)
resp = req.text
except:
return
Expand All @@ -49,7 +50,7 @@ def get_lyrics(self, song):
break
if url:
try:
req2 = sess.get(url, timeout=10)
req2 = sess.get(url, headers=UserAgent, timeout=10)
resp2 = req2.text
except:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
__priority__ = '130'
__lrc__ = True

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"}
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"}

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

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

def get_lyrics(self, song):
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
lyrics = Lyrics(settings=self.settings)
lyrics.song = song
lyrics.source = __title__
lyrics.lrc = __lrc__
artist = song.artist.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
title = song.title.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
url = self.SEARCH_URL % (artist.lower(), title.lower())
try:
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
search = requests.get(url, headers=UserAgent, timeout=10)
response = search.text
except:
return None
matchcode = re.search('details">(.*?)</div', response, flags=re.DOTALL)
if matchcode:
lyricscode = (matchcode.group(1))
lyr = re.sub('<[^<]+?>', '', lyricscode)
lyrics.lyrics = lyr
return lyrics
return None

'''
def get_lyrics(self, song):
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
lyrics = Lyrics(settings=self.settings)
Expand Down Expand Up @@ -73,3 +98,4 @@ def get_lyrics_from_list(self, link):
lyricscode = (matchcode.group(1))
cleanlyrics = re.sub('<[^<]+?>', '', lyricscode)
return cleanlyrics
'''
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from lib.utils import *

__title__ = "Megalobiz"
__priority__ = '140'
__priority__ = '150'
__lrc__ = True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import random
import difflib
import html
from bs4 import BeautifulSoup
from lib.utils import *

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

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

class LyricsFetcher:
def __init__(self, *args, **kwargs):
self.DEBUG = kwargs['debug']
self.settings = kwargs['settings']
self.SEARCH_URL = 'https://www.musixmatch.com/search/'
self.LYRIC_URL = 'https://www.musixmatch.com'
self.SEARCH_URL = 'https://www.musixmatch.com/search?query='
self.LYRIC_URL = 'https://www.musixmatch.com/lyrics/%s/%s'

def get_lyrics(self, song):
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
lyrics = Lyrics(settings=self.settings)
lyrics.song = song
lyrics.source = __title__
lyrics.lrc = __lrc__
artist = song.artist.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
title = song.title.replace("'", '').replace('!', '').replace('?', '').replace('"', '').replace('/', '').replace('.', '').replace('&', '').replace(',', '').replace('(', '').replace(')', '').replace(' ', '-')
url = self.LYRIC_URL % (artist, title)
try:
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
search = requests.get(url, headers=headers, timeout=10)
response = search.text
except:
return None
matchcode = re.search('Lyrics of (.*?)Writer\(s\): ', response, flags=re.DOTALL)
if matchcode:
lyricscode = (matchcode.group(1))
lyr = re.sub('<[^<]+?>', '\n', lyricscode)
lyr = html.unescape(lyr)
lyrics.lyrics = lyr.replace('\n\n\n\n', '\n')
return lyrics
return None

'''
def get_lyrics(self, song):
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
lyrics = Lyrics(settings=self.settings)
Expand Down Expand Up @@ -84,3 +111,4 @@ def get_lyrics_from_list(self, link):
for part in lyr:
lyrics = lyrics + part.get_text() + '\n'
return lyrics
'''
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_lyrics(self, song):
search = '%s - %s' % (artist, title)
try:
url = self.SEARCH_URL % 'track.search'
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)]
query = [('q', search), ('page_size', '5'), ('page', '1'), ('app_id', 'web-desktop-app-v1.0'), ('usertoken', self.token), ('t', self.current_time)]
response = requests.get(url, params=query, timeout=10)
result = response.json()
except:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#-*- coding: utf-8 -*-
'''
Scraper for https://www.rclyricsband.com/
'''

import requests
import re
import difflib
import html
from bs4 import BeautifulSoup
from lib.utils import *

__title__ = "RCLyricsBand"
__priority__ = '140'
__lrc__ = True

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"}

class LyricsFetcher:
def __init__(self, *args, **kwargs):
self.DEBUG = kwargs['debug']
self.settings = kwargs['settings']
self.SEARCH_URL = 'https://rclyricsband.com/'
self.LYRIC_URL = 'https://rclyricsband.com/%s'


def get_lyrics(self, song):
log("%s: searching lyrics for %s - %s" % (__title__, song.artist, song.title), debug=self.DEBUG)
lyrics = Lyrics(settings=self.settings)
lyrics.song = song
lyrics.source = __title__
lyrics.lrc = __lrc__
artist = song.artist
title = song.title
try:
url = self.SEARCH_URL
searchdata = {}
searchdata['search'] = '%s %s' % (artist, title)
search = requests.post(url, data=searchdata, headers=UserAgent, timeout=10)
response = search.text
except:
return None
links = []
soup = BeautifulSoup(response, 'html.parser')
for link in soup.find_all('a', {'class': 'song_search'}):
if link.string:
foundsong = link.string.split(' - ')[0]
foundartist = link.string.split(' - ')[-1]
if (difflib.SequenceMatcher(None, artist.lower(), foundartist.lower()).ratio() > 0.8) and (difflib.SequenceMatcher(None, title.lower(), foundsong.lower()).ratio() > 0.8):
links.append((foundartist + ' - ' + foundsong, self.LYRIC_URL % link.get('href'), foundartist, foundsong))
if len(links) == 0:
return None
elif len(links) > 1:
lyrics.list = links
for link in links:
lyr = self.get_lyrics_from_list(link)
if lyr:
lyrics.lyrics = lyr
return lyrics
return None

def get_lyrics_from_list(self, link):
title,url,artist,song = link
try:
log('%s: search url: %s' % (__title__, url), debug=self.DEBUG)
search = requests.get(url, headers=UserAgent, timeout=10)
response = search.text
except:
return None
matchcode = re.search("lrc_text_format'>(.*?)</p", response, flags=re.DOTALL)
if matchcode:
lyricscode = (matchcode.group(1))
cleanlyrics = re.sub('<br>', '\n', lyricscode)
cleanlyrics = html.unescape(cleanlyrics)
return cleanlyrics
Loading

0 comments on commit dc527d0

Please sign in to comment.