Skip to content

Commit

Permalink
Updated to v3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
elmoiv authored Sep 26, 2020
1 parent d49edc2 commit 22ef717
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 40 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ API.title = 'Bad Blods'
API.getLyrics(save=True, ext='lrc')

print(API.lyrics)

# Correct Artist and Title are updated from webpage
print(API.title, API.artist)
```
## Tests
Here are a few sample tests:
Expand All @@ -53,20 +56,25 @@ Here are a few sample tests:

## Changelog

### v3.0.5 26-09-2020
* [#10](https://github.com/elmoiv/azapi/issues/10) Fixed one-liner lyrics can't be retrieved.
* Direct lyrics URLs can now be passed without artist or title.
* Fixed minor bugs.

### v3.0.4 22-08-2020
* Update title and artist attributes with exact values from AZLyrics.com.
* [#9](https://github.com/elmoiv/azapi/issues/9) Update title and artist attributes with exact values from AZLyrics.com.
* Fixed minor bugs.

### v3.0.3 13-08-2020
* Fixed `getSongs` not returning all songs.
* [#8](https://github.com/elmoiv/azapi/issues/8) Fixed `getSongs` not returning all songs.

### v3.0.2 25-07-2020
* Added the ability to use custom path with `getLyrics`.
* [#7](https://github.com/elmoiv/azapi/issues/7)Added the ability to use custom path with `getLyrics`.
* Added `self.lyrics` and `self.songs` to store last call.
* Added `self.lyrics_history` that stores all fetched lyrics.

### v3.0.1 07-07-2020
* Fixed single albums return relative urls.
* [#6](https://github.com/elmoiv/azapi/issues/6) Fixed single albums return relative urls.

### v3.0.0 15-06-2020
* Project re-done from scratch.
Expand All @@ -86,11 +94,6 @@ Here are a few sample tests:
## Contributing
Please contribute! If you want to fix a bug, suggest improvements, or add new features to the project, just [open an issue](https://github.com/elmoiv/azapi/issues) or send me a pull request.



**It is adviced not to send too many requests to avoid IP ban by search engines.*
Expand Down
2 changes: 1 addition & 1 deletion azapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
__url__ = 'https://github.com/elmoiv/azapi'
__description__ = 'Get Lyrics from AZLyrics.com like a Boss ~(0_0)~'
__license__ = 'GPL-v3.0'
__version__ = '3.0.4'
__version__ = '3.0.5'
18 changes: 9 additions & 9 deletions azapi/azapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ def getLyrics(self, url=None, ext='txt', save=False, path='', sleep=3):
lyrics (str): Lyrics of the detected song
"""

if not self.artist + self.title:
raise ValueError("Both artist and title can't be empty!")

# Best cooldown is 5 sec
time.sleep(sleep)

link = url

if not url:
# v3.0.5: No need for artist and title if url is found
if not self.artist + self.title:
raise ValueError("Both artist and title can't be empty!")
if self.search_engine:
# If user can't remember the artist,
# he can search by title only

# Get AZlyrics url via Google Search
link = GoogleGet(
link = googleGet(
self.search_engine,
self.accuracy,
self.get,
Expand All @@ -69,7 +69,7 @@ def getLyrics(self, url=None, ext='txt', save=False, path='', sleep=3):
else:
# Sometimes search engines block you
# If happened use the normal get method
link = NormalGet(
link = normalGet(
self.artist,
self.title,
0)
Expand All @@ -86,7 +86,7 @@ def getLyrics(self, url=None, ext='txt', save=False, path='', sleep=3):
self.artist = filtr(metadata[0][:-7], True)
self.title = filtr(metadata[1][1:-1], True)

lyrics = ParseLyric(page)
lyrics = parseLyric(page)
self.lyrics = lyrics.strip()

# Saving Lyrics
Expand Down Expand Up @@ -130,7 +130,7 @@ def getSongs(self, sleep=3):
time.sleep(sleep)

if self.search_engine:
link = GoogleGet(
link = googleGet(
self.search_engine,
self.accuracy,
self.get,
Expand All @@ -140,7 +140,7 @@ def getSongs(self, sleep=3):
if not link:
return {}
else:
link = NormalGet(
link = normalGet(
self.artist,
'',
1)
Expand All @@ -151,5 +151,5 @@ def getSongs(self, sleep=3):
return {}

# Store songs for later usage
self.songs = ParseSongs(albums_page)
self.songs = parseSongs(albums_page)
return self.songs
28 changes: 8 additions & 20 deletions azapi/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def filtr(inpt, isFile=False):
return ''.join(i for i in inpt if i not in r'<>:"/\|?*')
return ''.join(i.lower() for i in inpt if i.lower() in letters)

def NormalGet(artist='', title='', _type=0):
def normalGet(artist='', title='', _type=0):
art, tit = filtr(artist), filtr(title)
if _type:
return 'https://www.azlyrics.com/{}/{}.html'.format(art[0], art)
return 'https://www.azlyrics.com/lyrics/{}/{}.html'.format(art, tit)

def GoogleGet(srch_eng, acc, get_func, artist='', title='', _type=0):
def googleGet(srch_eng, acc, get_func, artist='', title='', _type=0):
# Encode artist and title to avoid url encoding errors
data = artist + ' ' * (title != '' and artist != '') + title
encoded_data = quote(data.replace(' ', '+'))
Expand Down Expand Up @@ -92,24 +92,12 @@ def GoogleGet(srch_eng, acc, get_func, artist='', title='', _type=0):

return 0

def ParseLyric(page):
divs = htmlFindAll(page)('div')
for div in divs:
# Lyrics div has no class
# So we fast check if there is a class or not
try:
div['class']
continue
except:
pass
# Almost all lyrics have more than one <br> tag
# v3.0: some songs are too short like: Animals - Matin Garrix
found = div.find_all('br')
if len(found):
# Removing unnecessary lines
return div.text[2:-1]
# v3.0.5: Re-coded ParseLyrics to be more efficient
def parseLyric(page):
divs = [i.text for i in htmlFindAll(page)('div', {'class': None})]
return max(divs, key=len)

def ParseSongs(page):
def parseSongs(page):
songs = {}
Parent = htmlFind(page)('div', {'id':'listAlbum'})
if Parent:
Expand All @@ -118,7 +106,7 @@ def ParseSongs(page):
curType, curName, curYear = '', '', ''

for elmnt in Raw_Data:

# v3.0.3: Removed break after script due to google ads inside listAlbum
# is using script tag, which results in not all songs retrieved
#if elmnt.name == 'script':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setuptools.setup(
name="azapi",
version="3.0.4",
version="3.0.5",
author="elmoiv",
author_email="[email protected]",
description="Get Lyrics from AZLyrics.com like a Boss ~(0_0)~",
Expand Down

0 comments on commit 22ef717

Please sign in to comment.