Upgrade to 1.1
This commit is contained in:
parent
b8f80c4e71
commit
f6704ffb1f
@ -54,5 +54,10 @@ You can also install it system-wide using `sudo python3 -m pip install.`
|
|||||||
|
|
||||||
After installing, you can use it like this: `nicole -ior -d ~/music/artist --rm_explicit`
|
After installing, you can use it like this: `nicole -ior -d ~/music/artist --rm_explicit`
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
### 1.1
|
||||||
|
- Lyrics are now properly encoded.
|
||||||
|
- If a title contains paranthesis or umlaute, multiple possible urls will be checked.
|
||||||
|
|
||||||
## Importand Notice
|
## Importand Notice
|
||||||
This software comes with no warranty!
|
This software comes with no warranty!
|
||||||
|
@ -50,8 +50,6 @@ class Nicole:
|
|||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.write_history:
|
if self.write_history:
|
||||||
self._write_history()
|
self._write_history()
|
||||||
else:
|
|
||||||
print("NO")
|
|
||||||
|
|
||||||
def _load_history(self):
|
def _load_history(self):
|
||||||
config_path = path.expanduser("~") + "/.config/nicole/"
|
config_path = path.expanduser("~") + "/.config/nicole/"
|
||||||
@ -81,9 +79,10 @@ class Nicole:
|
|||||||
failed_file.write(file + "\n")
|
failed_file.write(file + "\n")
|
||||||
failed_file.close()
|
failed_file.close()
|
||||||
|
|
||||||
def get_url_azlyrics(self, artist:str, title:str):
|
def get_urls_azlyrics(self, artist:str, title:str):
|
||||||
"""
|
"""
|
||||||
Create a azlyrics html from the artist and title
|
Create a azlyrics html from the artist and title
|
||||||
|
If the title contains paranthesis or äüö, there will be multiple versions, one that contains the (...)öäü and one that doesn't.
|
||||||
"""
|
"""
|
||||||
# convert to lower case
|
# convert to lower case
|
||||||
artist = artist.casefold()
|
artist = artist.casefold()
|
||||||
@ -99,26 +98,70 @@ class Nicole:
|
|||||||
for match in re.finditer(r"\[.*\]", title):
|
for match in re.finditer(r"\[.*\]", title):
|
||||||
title = title.replace(match.group(), "")
|
title = title.replace(match.group(), "")
|
||||||
|
|
||||||
# remove spaces, from the title
|
titles = [title]
|
||||||
for c in [' ', '-', ',', '.', '\'', '"', '°', '`', '´', '/', '!', '?', '#', '*', '(', ')']:
|
|
||||||
title = title.replace(c, '')
|
|
||||||
artist = artist.replace(c, '')
|
|
||||||
|
|
||||||
# replace some stuff
|
# if title has(), create one version with and one without them
|
||||||
old = ['ä', 'ö', 'ü', '&']
|
if re.search(r"\(.*\)", title):
|
||||||
new = ['a', 'o', 'u', "and"]
|
for match in re.finditer(r"\(.*\)", title):
|
||||||
# new2 = ['', '', '', "and"]
|
title = title.replace(match.group(), "")
|
||||||
|
titles.append(title)
|
||||||
|
|
||||||
|
# some special chars
|
||||||
|
toNone = [' ', '-', ',', '.', '…', '\'', '"', '°', '`', '´', '/', '!', '?', '#', '*', '(', ')']
|
||||||
|
for c in toNone:
|
||||||
|
artist = artist.replace(c, "")
|
||||||
|
|
||||||
|
#
|
||||||
|
# replace umlaute, create multiple versions
|
||||||
|
#
|
||||||
|
old = ['ä', 'ö', 'ü', 'ß', '&']
|
||||||
|
new1 = ['a', 'o', 'u', 'ss', "and"]
|
||||||
|
new2 = ['', '', '', '', "and"]
|
||||||
|
|
||||||
|
# in artist
|
||||||
|
if any(c in old for c in artist):
|
||||||
for i in range(len(old)):
|
for i in range(len(old)):
|
||||||
title = title.replace(old[i], new[i])
|
artist = artist.replace(old[i], new1[i])
|
||||||
artist = artist.replace(old[i], new[i])
|
# multiple loops are needed since the array might grow
|
||||||
|
|
||||||
return "https://azlyrics.com/lyrics/" + artist + '/' + title + ".html"
|
# umlaute
|
||||||
|
for n in range(len(titles)):
|
||||||
|
if any(c in old for c in titles[n]):
|
||||||
|
# replace titles[n] with the first version and append the second
|
||||||
|
title2 = titles[n]
|
||||||
|
for i in range(len(old)):
|
||||||
|
titles[n] = titles[n].replace(old[i], new1[i])
|
||||||
|
title2 = title2.replace(old[i], new2[i])
|
||||||
|
titles.append(title2)
|
||||||
|
|
||||||
def get_lyrics_azlyrics(self, url):
|
# features
|
||||||
|
for title in titles:
|
||||||
|
match = re.search(r"fe?a?t\.?.*", title)
|
||||||
|
if match:
|
||||||
|
titles.append(title.replace(match.group(), ""))
|
||||||
|
|
||||||
|
# spaces, etc
|
||||||
|
for n in range(len(titles)):
|
||||||
|
for c in toNone:
|
||||||
|
titles[n] = titles[n].replace(c, '')
|
||||||
|
|
||||||
|
#
|
||||||
|
# create urls
|
||||||
|
#
|
||||||
|
urls = []
|
||||||
|
for title in titles:
|
||||||
|
urls.append("https://azlyrics.com/lyrics/" + artist + '/' + title + ".html")
|
||||||
|
print(urls)
|
||||||
|
return urls
|
||||||
|
|
||||||
|
|
||||||
|
def get_lyrics_azlyrics(self, urls):
|
||||||
"""
|
"""
|
||||||
Extract the lyrics from the html
|
Extract the lyrics from the html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
message = ""
|
||||||
|
for url in urls:
|
||||||
# visit the url
|
# visit the url
|
||||||
html = None
|
html = None
|
||||||
try:
|
try:
|
||||||
@ -126,7 +169,8 @@ class Nicole:
|
|||||||
sleep(self.delay) # azlyrics blocks requests if there is no delay
|
sleep(self.delay) # azlyrics blocks requests if there is no delay
|
||||||
except Exception:
|
except Exception:
|
||||||
sleep(self.delay) # azlyrics blocks requests if there is no delay
|
sleep(self.delay) # azlyrics blocks requests if there is no delay
|
||||||
return (False, f"Could not access url: {url}")
|
message += f"Could not access url: {url}\n "
|
||||||
|
continue
|
||||||
|
|
||||||
lyrics = None
|
lyrics = None
|
||||||
match = re.search(r"<!\-\- Usage of azlyrics.com content by any third\-party lyrics provider is prohibited by our licensing agreement. Sorry about that. \-\->(.|\n)+?</div>", html)
|
match = re.search(r"<!\-\- Usage of azlyrics.com content by any third\-party lyrics provider is prohibited by our licensing agreement. Sorry about that. \-\->(.|\n)+?</div>", html)
|
||||||
@ -147,7 +191,10 @@ class Nicole:
|
|||||||
lyrics = lyrics.replace(tag.group(), "")
|
lyrics = lyrics.replace(tag.group(), "")
|
||||||
|
|
||||||
return (True, lyrics)
|
return (True, lyrics)
|
||||||
return (False, f"Could not find lyrics in html: {url}")
|
|
||||||
|
message += f"Could not lyrics in html for {url}\n "
|
||||||
|
message = message.strip(" \n")
|
||||||
|
return (False, message)
|
||||||
|
|
||||||
def process_dir(self, directory):
|
def process_dir(self, directory):
|
||||||
if not path.isabs(directory):
|
if not path.isabs(directory):
|
||||||
@ -254,9 +301,9 @@ class Nicole:
|
|||||||
|
|
||||||
# currently the only supported site
|
# currently the only supported site
|
||||||
if self.lyrics_site == "azlyrics":
|
if self.lyrics_site == "azlyrics":
|
||||||
url = self.get_url_azlyrics(artist, title)
|
urls = self.get_urls_azlyrics(artist, title)
|
||||||
|
|
||||||
success, lyrics = self.get_lyrics_azlyrics(url)
|
success, lyrics = self.get_lyrics_azlyrics(urls)
|
||||||
if success:
|
if success:
|
||||||
if self.test_run:
|
if self.test_run:
|
||||||
print(f"{artist} - {title}:\n{lyrics}\n\n")
|
print(f"{artist} - {title}:\n{lyrics}\n\n")
|
||||||
@ -283,6 +330,9 @@ class Nicole:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
print("Nicole version 1.1")
|
||||||
|
# print("Get updates here: https://github.com/MatthiasQuintern/nicole")
|
||||||
|
|
||||||
helpstring = """Command line options:
|
helpstring = """Command line options:
|
||||||
-d [directory] process directory [directory]
|
-d [directory] process directory [directory]
|
||||||
-f [file] process file [file]
|
-f [file] process file [file]
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="nicole",
|
name="nicole",
|
||||||
version="1.0",
|
version="1.1",
|
||||||
description="Add lyrics from azlyrics.com to mp3-tag",
|
description="Add lyrics from azlyrics.com to mp3-tag",
|
||||||
|
|
||||||
author="Matthias Quintern",
|
author="Matthias Quintern",
|
||||||
|
Loading…
Reference in New Issue
Block a user