Added clean_search_query and gw.search

This commit is contained in:
RemixDev 2020-11-19 21:04:41 +01:00
parent 1856846992
commit 605efe5e2d
No known key found for this signature in database
GPG key ID: B33962B465BDB51C
4 changed files with 25 additions and 2 deletions

View file

@ -4,7 +4,7 @@ from deezer.gw import GW
from deezer.api import API
import json
__version__ = "0.0.3"
__version__ = "0.0.4"
class TrackFormats():
"""Number associtation for formats"""

View file

@ -1,6 +1,7 @@
import eventlet
requests = eventlet.import_patched('requests')
import json
from deezer.utils import map_artist_album
class LyricsStatus():
@ -213,6 +214,16 @@ class GW:
}
return self.api_call('page.get', params=params)
def search(self, query, index=0, limit=10, suggest=True, artist_suggest=True, top_tracks=True):
return self.api_call('deezer.pageSearch', {
"query": query,
"start": index,
"nb": limit,
"suggest": suggest,
"artist_suggest": artist_suggest,
"top_tracks": top_tracks
})
# Extra calls
def get_artist_discography_tabs(self, art_id, limit=100):

View file

@ -1,3 +1,5 @@
import re
RELEASE_TYPE = {0:"single", 1:"album", 2:"compile", 3:"ep", 4:"bundle"}
# maps gw-light api user/tracks to standard api
@ -185,3 +187,13 @@ def map_playlist(playlist):
},
'type': "playlist"
}
# Cleanup terms that can hurt search results
def clean_search_query(term):
term = str(term)
term = re.sub(r' feat[\.]? ', " ", term)
term = re.sub(r' ft[\.]? ', " ", term)
term = re.sub(r'\(feat[\.]? ', " ", term)
term = re.sub(r'\(ft[\.]? ', " ", term)
term = term.replace('&', " ").replace('', "-").replace('', "-")
return term

View file

@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text()
setup(
name="deezer-py",
version="0.0.3",
version="0.0.4",
description="A wrapper for all Deezer's APIs",
long_description=README,
long_description_content_type="text/markdown",