Giter Site home page Giter Site logo

elmoiv / azapi Goto Github PK

View Code? Open in Web Editor NEW
110.0 4.0 12.0 152 KB

Get Lyrics from AZLyrics.com like a Boss ~(0_0)~

License: GNU General Public License v3.0

Python 100.00%
music api lyrics azlyrics artists song songs lyrics-fetcher lyrics-search lyrics-api

azapi's Introduction

azapi

Build Status Python version

A fast and secure API for AZLyrics.com to get lyrics easily :)

Features

  • Get artist's songs list with Album, Year ...etc
  • Can get results via Google* and Duckduckgo* for accurate results.
  • Save lyrics in a .txt file or any format you like.
  • Avoid BAN using proxy** and multiple user agents.

Installation

azapi requires Python 3.

Use pip to install the package from PyPI:

pip install azapi

Or, install the latest version of the package from GitHub:

pip install git+https://github.com/elmoiv/azapi.git

Usage

import azapi

API = azapi.AZlyrics('google', accuracy=0.5)

API.artist = 'Tylor Swft'
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:

Changelog

v3.0.8 21-02-2022

  • #17 Use search engine method when normal method fails.

v3.0.7 03-01-2022

  • #6 [Re-Fixed] Single albums return relative urls.

v3.0.6 12-02-2021

  • #11 Fixed proxy not used properly.

v3.0.5 26-09-2020

  • #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

  • #9 Update title and artist attributes with exact values from AZLyrics.com.
  • Fixed minor bugs.

v3.0.3 13-08-2020

  • #8 Fixed getSongs not returning all songs.

v3.0.2 25-07-2020

  • #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

  • #6 Fixed single albums return relative urls.

v3.0.0 15-06-2020

  • Project re-done from scratch.
  • Added the ability to use search engines.
  • Fixed unicode issue with non-english lyrics.
  • Fixed songs list not working for artists with single album.
  • Removed search as it's no longer needed.
  • Fixed NoneType bugs.

v2.1.0 18-10-2019

  • Added search feature to getSongs and getLyrics.
  • You can use search albums, songs and artists.

v2.0.1 11-09-2019

  • First Release

Stargazers over time

Stargazers over time

Contributing

Please contribute! If you want to fix a bug, suggest improvements, or add new features to the project, just open an issue or send me a pull request.

*It is adviced not to send too many requests to avoid IP ban by search engines.

**Proxy is set by the user, defult is empty.

azapi's People

Contributors

elmoiv avatar freewillyb avatar robertlestak avatar ultirequiem avatar zivsimchoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

azapi's Issues

[Solved] getSongs() doesn't return all songs from an artist

Describe the bug
getSongs() fails to retrieve all songs from an artist

To Reproduce

from azapi import AZlyrics
import pprint

API = AZlyrics('google', accuracy=0.5)
API.artist = 'bangtanboys'
songs = API.getSongs()
pprint.pprint(songs, indent=2)

printed json

{
  "24/7=Heaven": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/247heaven.html",
    "year": "2014"
  },
  "2nd Grade (2학년)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/2ndgrade2.html",
    "year": "2014"
  },
  "Attack On Bangtan (진격의 방탄; Jingyeogui Bangtan)": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/attackonbangtanjingyeoguibangtan.html",
    "year": "2013"
  },
  "BTS Cypher Pt. 1": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/btscypherpt1.html",
    "year": "2013"
  },
  "BTS Cypher Pt. 2: Triptych": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/btscypherpt2triptych.html",
    "year": "2014"
  },
  "BTS Cypher Pt. 3: Killer": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/btscypherpt3killer.html",
    "year": "2014"
  },
  "Blanket Kick (이불킥)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/blanketkick.html",
    "year": "2014"
  },
  "Boy In Luv (상남자; Sang-Namja)": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/boyinluvsangnamja.html",
    "year": "2014"
  },
  "Can You Turn Off Your Cellphone? (핸드폰 좀 꺼줄래)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/canyouturnoffyourcellphone.html",
    "year": "2014"
  },
  "Coffee": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/coffee.html",
    "year": "2013"
  },
  "Danger": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/danger.html",
    "year": "2014"
  },
  "Does That Make Sense? (Outro) (그게 말이 돼? (Outro))": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/doesthatmakesenseoutrooutro.html",
    "year": "2014"
  },
  "Hip Hop Lover (힙합성애자)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/hiphoplover.html",
    "year": "2014"
  },
  "I Like It (Slow Jam Remix) (좋아요; Joh-Ayo)": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/ilikeitslowjamremixjohayo.html",
    "year": "2014"
  },
  "I Like It (좋아요; Joayo)": {
    "album": "2 Cool 4 Skool",
    "type": "single",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/ilikeitjoayo.html",
    "year": "2013"
  },
  "If I Ruled The World": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/ifiruledtheworld.html",
    "year": "2013"
  },
  "Interlude: What Are You Doing? (Interlude:뭐해; Interlude: Mwohae)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/interludewhatareyoudoinginterludeinterludemwohae.html",
    "year": "2014"
  },
  "Intro: 2 Cool 4 Skool": {
    "album": "2 Cool 4 Skool",
    "type": "single",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/intro2cool4skool.html",
    "year": "2013"
  },
  "Intro: O!RUL8,2": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/introorul82.html",
    "year": "2013"
  },
  "Intro: Skool Luv Affair": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/introskoolluvaffair.html",
    "year": "2014"
  },
  "Jump": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/jump.html",
    "year": "2014"
  },
  "Just One Day (하루만; Haruman)": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/justonedayharuman.html",
    "year": "2014"
  },
  "Let Me Know": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/letmeknow.html",
    "year": "2014"
  },
  "Look Here (여기 봐)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/lookhere.html",
    "year": "2014"
  },
  "Miss Right": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/missright.html",
    "year": "2014"
  },
  "N.O": {
    "album": "O!RUL8,
    2?",
"type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/no.html",
    "year": "2013"
  },
  "No More Dream": {
    "album": "2 Cool 4 Skool",
    "type": "single",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/nomoredream.html",
    "year": "2013"
  },
  "Outro: Luv In Skool": {
    "album": "O!RUL8,
    2?",
          "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/outroluvinskool.html",
    "year": "2013"
  },
  "Outro: Propose": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/outropropose.html",
    "year": "2014"
  },
  "Path (길; Gil)": {
    "album": "2 Cool 4 Skool",
    "type": "single",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/pathgil.html",
    "year": "2013"
  },
  "Rain": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/rain.html",
    "year": "2014"
  },
  "Satoori Rap (팔도강산; Paldogangsan)": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/satoorirappaldogangsan.html",
    "year": "2013"
  },
  "Skit: Soulmate": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/skitsoulmate.html",
    "year": "2014"
  },
  "Spine Breaker (등골브레이커; Deung-Gol Beuleikeo)": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/spinebreakerdeunggolbeuleikeo.html",
    "year": "2014"
  },
  "Tomorrow": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/tomorrow.html",
    "year": "2014"
  },
  "War Of Hormone (호르몬 전쟁)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/warofhormone.html",
    "year": "2014"
  },
  "We Are Bulletproof Pt. 2": {
    "album": "2 Cool 4 Skool",
    "type": "single",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/wearebulletproofpt2.html",
    "year": "2013"
  },
  "We On": {
    "album": "O!RUL8,2?",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/weon.html",
    "year": "2013"
  },
  "What Am I To You (Intro)": {
    "album": "Dark & Wild",
    "type": "album",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/whatamitoyouintro.html",
    "year": "2014"
  },
  "Where Did You Come From? (어디에서 왔는지; Eodieseo Wassneunji)": {
    "album": "Skool Luv Affair",
    "type": "EP",
    "url": "http: //www.azlyrics.com/lyrics/bangtanboys/wheredidyoucomefromeodieseowassneunji.html",
    "year": "2014"
  }
}

Expected behavior
When going to the url: https://www.azlyrics.com/b/bangtanboys.html
we can see how songs have been chopped off in the print statement when compared to the actual list of songs on AZlyrics.com.
I believe this issue has to do the the ParseSongs() method in tools.py.
AZlyrics seems to include google adds in one under a certain div tag and I think this is causing early termination possibly.

Screenshots
image

Desktop (please complete the following information):
Using macOS Majove

Additional context
Add any other context about the problem here.

[Solved] README example not working

I tried with python 3.6.9


>>> import azapi
>>> Artist = azapi.AZlyrics()
>>> lyric = Artist.getLyrics("Taylor Swift", "Bad Blood", save=False)
Traceback (most recent call last):
  File "/home/mohit/.virtualenvs/spotify/lib/python3.6/site-packages/azapi/azapi.py", line 71, in getLyrics
    artist = filtr(str(htmlFindAll(page)('div', class_='lyricsh')[0])[29:-23], True)
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mohit/.virtualenvs/spotify/lib/python3.6/site-packages/azapi/azapi.py", line 75, in getLyrics
    raise Exception('Artist or Title not found!')
Exception: Artist or Title not found!
>>> 

getSongs doesn't work with certain artists

Don't know if this is an issue with azlyrics but when trying to get the songs from someone like Kanye it only works if you search "West". The terms "Kanye West" or "Kanye" throw errors.

getSongs() returns empty dict

The following code:

from azapi import AZlyrics

api = AZlyrics()
api.artist = "Aaliyah"
songs = api.getSongs()

produces an empty dictionary when I try to print(songs).

Desktop (please complete the following information):

  • OS: Pop!_OS 21.10
  • Python 3.7.6
  • azapi 3.0.7

Any ideas about what I might be doing wrong? Thanks in advance!

Error during getLyrics()

Describe the bug
Exception thrown during loading the lyrics.

Traceback (most recent call last):
  File "<input>", line 4, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azapi\azapi.py", line 90, in getLyrics
    self.lyrics = lyrics.strip()
AttributeError: 'NoneType' object has no attribute 'strip'

To Reproduce
Steps to reproduce the behavior:

api = azapi.AZlyrics('duckduckgo', accuracy=0.5)

api.artist = "Glass Animals"

api.getLyrics(url="http://www.azlyrics.com/lyrics/glassanimals/homemovie1994.html")

Expected behavior
It seem that no lyrics is available but the page exist. Maybe return None?

Proxy is not used

Your get method has a parameter for setting the proxy for the request:

def get(self, url, _proxies={}):

But you don't pass the proxy defined in the AZlyrics class to the method:

page = self.get(link)

albums_page = self.get(link)

azapi/azapi/tools.py

Lines 51 to 55 in 8f3d44b

google_page = get_func('{}{}+site%3Aazlyrics.com'.format(
search_engines[slctd_srch_engn],
encoded_data
)
)

Error 404 getting lyrics

I am using azapi on a Google Colabatory runtime and using the example given in the readme returns an Error 404. Am I doing something wrong? What could be causing this?
Screen Shot 2021-02-24 at 1 49 43 pm

[Solved] .getLyrics Errors

Describe the bug

I've been having issues with this library I worked on implementing into phonetic-songs and at one point I thought it was the way I phrased the code but then as seen in the screenshot, the same piece of code gave two different outputs immediately after each other so I knew it wasn't from my side.

Along with AttributeError: 'NoneType' object has no attribute 'strip', I would get Exception('Artist or Title not found!'), TypeError: string indices must be integers, TypeError: write() argument must be str, not None and IndexError: list index out of range all with the same piece of code. Perhaps something to do with the way it is fetching the data from AZLyrics?

To Reproduce

Steps to reproduce the behavior:

api = AZlyrics()
search_terms = input('Enter lyrics: ')
songs = api.search(search_terms, category='songs')   
song_url = songs[0]['url']
artist_name = songs[0]['artist']
song_title = songs[0]['name']
lyrics = api.getLyrics(url = song_url, save=False).strip()
filename = (artist_name + ' - ' + song_title + '.txt')
if Path('in/').exists():
  basepath = Path('in/')
else:
  os.mkdir('in')
  if Path('in/').exists():
    basepath = Path('in/')
  with open(basepath/filename,'w', encoding='latin-1') as export:
    export.write(lyrics)
    export.close()
...

Would also get it with

api = AZlyrics()
artist_name = input('Type in the name of the artist: ')
song_title = input('Type in the title of the song: ')
lyrics = api.getLyrics(artist = artist_name, title = song_title, save=False).strip()
filename = (artist_name + ' - ' + song_title + '.txt')
if Path('in/').exists():
  basepath = Path('in/')
else:
  os.mkdir('in')
  if Path('in/').exists():
    basepath = Path('in/')
  with open(basepath/filename,'w', encoding='latin-1') as export:
    export.write(lyrics)
    export.close()
...

Expected behavior
Lyrical output

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10 v19.03
  • Python: 3.7.2

Additional context
A collection of the errors thrown with various songs/lyrics

  • using artist and title
  1. Utada Hikaru - Apple and Cinnamon (IndexError: list index out of range and raise Exception('Artist or Title not found!')
  2. Adele - Hello (TypeError: write() argument must be str, not None)
  3. EDEN - Gone (AttributeError: 'NoneType' object has no attribute 'strip')
  • using lyric search feature
  1. apple and cinnamon (IndexError: list index out of range and Exception('Artist or Title not found!')
    It also at one point downloaded this song Drew Seeley - Christmas Nyc.txt instead
  2. you can't stop the beat (TypeError: string indices must be integers)
  3. hello it's me (TypeError: write() argument must be str, not None)
  4. hello from the other side (TypeError: write() argument must be str, not None)
  5. thriller night (Exception('Artist or Title not found!'))
  6. let it go (TypeError: write() argument must be str, not None'

Get captcha response when I try to run

Describe the bug
I've uploaded the script to a pythonanywhere instance and am using flask to return results to a website. For any query type I get the response: "Type the characters from the picture above: Input is case-insensitive Submit"

It looks like maybe it's catching a captcha or similar bot detector.

I'm assuming that a proxy might be what is required to bypass - would you mind providing instructions for how to use one - I see the feature flag but wasn't sure how to do it if you think that's what's causing this?

List Index Error for "metadata" Variable

Description:
When a computer on the same network is using VPN, there is a List Index Error for the "metadata" variable in azapi.py. When I printed the variable, its value was "["\r\n Our systems have detected unusual activity from your IP address (computer network). \r\n This page checks to see if it's really you sending the requests, and not a robot.\r\n "]
This error still lingers even after I turn off my VPN.

Steps to reproduce the behavior:

  1. Turn on VPN
  2. Follow the example flow to set up and call getLyrics()

Expected behavior
I expected for the search lyrics to work as normal and return lyrics if they can be found via its process.

Screenshots
If applicable, add screenshots to help explain your problem.
image

[Solved] .getSongs() TypeError: 'NoneType' object is not iterable

Describe the bug

----> 1 songs = api.getSongs()

1 frames
/usr/local/lib/python3.6/dist-packages/azapi/AZtools.py in filtr(inpt, isFile)
     14     if isFile:
     15         return ''.join(i for i in inpt if i not in r'<>:"/\|?*')
---> 16     return ''.join(i.lower() for i in inpt if i.lower() in letters)
     17 
     18 def ParseLyric(page):

TypeError: 'NoneType' object is not iterable

To Reproduce
Steps to reproduce the behavior:
`from azapi import AZlyrics

api = AZlyrics('Taylor Swift')

songs = api.getSongs()
`

Expected behavior
self explanatory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.