POC genius proxy
This commit is contained in:
@ -36,7 +36,7 @@ class Extension( ext.Extension ):
|
||||
schema['locale'] = config.String()
|
||||
schema['spotify_authorization_url'] = config.String()
|
||||
schema['lastfm_authorization_url'] = config.String()
|
||||
schema['genius_provider_url'] = config.String()
|
||||
schema['genius_authorization_url'] = config.String()
|
||||
schema['snapcast_enabled'] = config.Boolean()
|
||||
schema['snapcast_host'] = config.String()
|
||||
schema['snapcast_port'] = config.Integer()
|
||||
|
||||
@ -966,6 +966,26 @@ class IrisCore(object):
|
||||
return True
|
||||
|
||||
|
||||
##
|
||||
# Spotify authentication
|
||||
#
|
||||
# Uses the Client Credentials Flow, so is invisible to the user. We need this token for
|
||||
# any backend spotify requests (we don't tap in to Mopidy-Spotify, yet). Also used for
|
||||
# passing token to frontend for javascript requests without use of the Authorization Code Flow.
|
||||
##
|
||||
|
||||
def get_lyrics(self, *args, **kwargs):
|
||||
callback = kwargs.get('callback', False)
|
||||
data = kwargs.get('data', False)
|
||||
error = False
|
||||
|
||||
url = 'https://genius.com'+data['path']
|
||||
|
||||
http_client = tornado.httpclient.HTTPClient()
|
||||
request = tornado.httpclient.HTTPRequest(url)
|
||||
response = http_client.fetch(request, callback=callback)
|
||||
|
||||
|
||||
##
|
||||
# Simple test method. Not for use in production for any purposes.
|
||||
##
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -98,7 +98,7 @@
|
||||
|
||||
// Release details
|
||||
// These are automatically injected to built HTML
|
||||
var build = "1534466976";
|
||||
var build = "1534641077";
|
||||
var version = "3.23.2";
|
||||
|
||||
// Construct the script tag
|
||||
|
||||
@ -23,10 +23,16 @@ export function set(data){
|
||||
var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
if (endpoint.startsWith('https://') || endpoint.startsWith('http://')){
|
||||
var url = endpoint;
|
||||
} else {
|
||||
var url = 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token;
|
||||
}
|
||||
|
||||
// create our ajax request config
|
||||
var config = {
|
||||
method: method,
|
||||
url: 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token,
|
||||
url: url,
|
||||
timeout: 30000,
|
||||
crossDomain: true
|
||||
}
|
||||
@ -124,19 +130,21 @@ export function getMe(){
|
||||
export function getTrackLyrics(uri, path){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
track: {
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: uri,
|
||||
lyrics: null,
|
||||
lyrics_path: null
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
sendRequest(dispatch, getState, "?action=lyrics&path="+path)
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: '//'+getState().mopidy.host+':'+getState().mopidy.port+'/iris/http/get_lyrics',
|
||||
timeout: 10000
|
||||
}
|
||||
|
||||
$.ajax(config)
|
||||
.then(
|
||||
response => {
|
||||
|
||||
(response, status, xhr) => {
|
||||
var html = $(response);
|
||||
var lyrics = html.find('.lyrics');
|
||||
if (lyrics.length > 0){
|
||||
@ -150,19 +158,17 @@ export function getTrackLyrics(uri, path){
|
||||
lyrics_html = lyrics_html.replace(/(\[)/g, '<span class="grey-text">[');
|
||||
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
|
||||
|
||||
dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
track: {
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: uri,
|
||||
lyrics: lyrics_html,
|
||||
lyrics_path: path
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
},
|
||||
error => {
|
||||
(xhr, status, error) => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not extract track lyrics',
|
||||
'Could not get track lyrics',
|
||||
error
|
||||
));
|
||||
}
|
||||
@ -180,25 +186,22 @@ export function findTrackLyrics(track){
|
||||
query = query.replace(/\([^)]*\) */g, ''); // anything in circle-braces
|
||||
query = query.replace(/\([^[]*\] */g, ''); // anything in square-braces
|
||||
|
||||
sendRequest(dispatch, getState, '?action=search&query='+encodeURIComponent(query))
|
||||
sendRequest(dispatch, getState, 'search', 'GET', 'q='+encodeURIComponent(query))
|
||||
.then(
|
||||
response => {
|
||||
if (response.response.hits && response.response.hits.length > 0){
|
||||
if (response.hits && response.hits.length > 0){
|
||||
var lyrics_results = [];
|
||||
for (var i = 0; i < response.response.hits.length; i++){
|
||||
for (var i = 0; i < response.hits.length; i++){
|
||||
lyrics_results.push({
|
||||
title: response.response.hits[i].result.full_title,
|
||||
url: response.response.hits[i].result.url,
|
||||
path: response.response.hits[i].result.path
|
||||
title: response.hits[i].result.full_title,
|
||||
url: response.hits[i].result.url,
|
||||
path: response.hits[i].result.path
|
||||
});
|
||||
}
|
||||
dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
track: {
|
||||
dispatch(coreActions.trackLoaded({
|
||||
uri: track.uri,
|
||||
lyrics_results: lyrics_results
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
// Immediately go and get the first result's lyrics
|
||||
var lyrics_result = lyrics_results[0];
|
||||
@ -207,7 +210,7 @@ export function findTrackLyrics(track){
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
'Could not get track info',
|
||||
'Could not search for track lyrics',
|
||||
error
|
||||
));
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
|
||||
import ReactGA from 'react-ga'
|
||||
|
||||
var helpers = require('../../helpers.js')
|
||||
var coreActions = require('../core/actions.js')
|
||||
var uiActions = require('../ui/actions.js')
|
||||
var mopidyActions = require('../mopidy/actions.js')
|
||||
var pusherActions = require('./actions.js')
|
||||
var lastfmActions = require('../lastfm/actions.js')
|
||||
var spotifyActions = require('../spotify/actions.js')
|
||||
var helpers = require('../../helpers')
|
||||
var coreActions = require('../core/actions')
|
||||
var uiActions = require('../ui/actions')
|
||||
var mopidyActions = require('../mopidy/actions')
|
||||
var pusherActions = require('./actions')
|
||||
var lastfmActions = require('../lastfm/actions')
|
||||
var geniusActions = require('../lastfm/actions')
|
||||
var spotifyActions = require('../spotify/actions')
|
||||
|
||||
const PusherMiddleware = (function(){
|
||||
|
||||
|
||||
@ -290,11 +290,7 @@ export function getTrack(uri){
|
||||
}
|
||||
)
|
||||
|
||||
dispatch({
|
||||
type: 'TRACK_LOADED',
|
||||
key: uri,
|
||||
track: track
|
||||
});
|
||||
dispatch(coreActions.trackLoaded(track));
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
@ -1333,10 +1329,7 @@ export function getAlbum(uri){
|
||||
response => {
|
||||
|
||||
// dispatch our loaded artists (simple objects)
|
||||
dispatch({
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: response.artists
|
||||
});
|
||||
dispatch(coreActions.artistsLoaded(response.artists));
|
||||
|
||||
var album = Object.assign(
|
||||
{},
|
||||
@ -1357,11 +1350,7 @@ export function getAlbum(uri){
|
||||
}
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: 'ALBUM_LOADED',
|
||||
key: album.uri,
|
||||
album: album
|
||||
});
|
||||
dispatch(coreActions.albumLoaded(album));
|
||||
|
||||
// now get all the artists for this album (full objects)
|
||||
// we do this to get the artist artwork
|
||||
@ -1374,10 +1363,7 @@ export function getAlbum(uri){
|
||||
sendRequest(dispatch, getState, 'artists/?ids='+artist_ids )
|
||||
.then(
|
||||
response => {
|
||||
dispatch({
|
||||
type: 'ARTISTS_LOADED',
|
||||
artists: response.artists
|
||||
});
|
||||
dispatch(coreActions.artistsLoaded(response.artists));
|
||||
},
|
||||
error => {
|
||||
dispatch(coreActions.handleException(
|
||||
|
||||
Reference in New Issue
Block a user