-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added support for searching lyrics from genius.com * Removed .DS_Store * Minor changes * Changed quotes, fixed tests, removed extra lines * Removed DS_Store, extra line from __init__ * Added MusixMatch Search
- Loading branch information
1 parent
59beb1c
commit d3e7b7c
Showing
7 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
'hello', | ||
'help', | ||
'joke', | ||
'lyrics', | ||
'movie', | ||
'music', | ||
'news', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import requests | ||
import config | ||
import os | ||
from bs4 import BeautifulSoup | ||
from templates.generic import * | ||
from templates.text import TextTemplate | ||
|
||
MUSIX_KEY = os.environ.get('MUSIX_API_KEY', config.MUSIX_API_KEY) | ||
|
||
def process(input, entities): | ||
output = {} | ||
try: | ||
query = entities['lyrics'][0]['value'] | ||
|
||
payload = { | ||
'apikey': MUSIX_KEY, | ||
'q_track': query, | ||
} | ||
|
||
r = requests.get('http://api.musixmatch.com/ws/1.1/track.search',params=payload) | ||
data = r.json() | ||
|
||
lyrics_url = data['message']['body']['track_list'][0]['track']['track_share_url'] | ||
track_id = data['message']['body']['track_list'][0]['track']['track_id'] | ||
|
||
payload = { | ||
'apikey': MUSIX_KEY, | ||
'track_id': track_id, | ||
} | ||
|
||
r = requests.get('http://api.musixmatch.com/ws/1.1/track.lyrics.get',params=payload) | ||
data = r.json() | ||
lyrics = '\n'.join(data['message']['body']['lyrics']['lyrics_body'].split('\n')[:-1]) | ||
|
||
title = query | ||
item_url = lyrics_url | ||
subtitle = lyrics | ||
|
||
template = GenericTemplate() | ||
template.add_element(title=title, item_url=item_url, subtitle=subtitle, buttons=[]) | ||
|
||
output['input'] = input | ||
output['output'] = template.get_message() | ||
output['success'] = True | ||
|
||
except: | ||
error_message = 'There was some error while retrieving data from genius.com' | ||
error_message += '\n Please ask me somrthing else, like:' | ||
error_message += '\n Lyrics for the song Wish you were here' | ||
output['error_msg'] = TextTemplate(error_message).get_message() | ||
output['success'] = False | ||
return output | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import modules | ||
|
||
def test_lyrics(): | ||
assert('lyrics' == modules.process_query("Lyrics for the song 'Wish you were here' ")[0]) | ||
assert('lyrics' == modules.process_query("lyrics for 'Go Robot' ")[0]) | ||
assert('lyrics' == modules.process_query("lyrics for the song Strawberry Fields Forever ")[0]) | ||
assert('lyrics' != modules.process_query("something random")[0]) |
Binary file not shown.