POC genius proxy
This commit is contained in:
@ -36,7 +36,7 @@ class Extension( ext.Extension ):
|
|||||||
schema['locale'] = config.String()
|
schema['locale'] = config.String()
|
||||||
schema['spotify_authorization_url'] = config.String()
|
schema['spotify_authorization_url'] = config.String()
|
||||||
schema['lastfm_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_enabled'] = config.Boolean()
|
||||||
schema['snapcast_host'] = config.String()
|
schema['snapcast_host'] = config.String()
|
||||||
schema['snapcast_port'] = config.Integer()
|
schema['snapcast_port'] = config.Integer()
|
||||||
|
|||||||
@ -966,6 +966,26 @@ class IrisCore(object):
|
|||||||
return True
|
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.
|
# 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
|
// Release details
|
||||||
// These are automatically injected to built HTML
|
// These are automatically injected to built HTML
|
||||||
var build = "1534466976";
|
var build = "1534641077";
|
||||||
var version = "3.23.2";
|
var version = "3.23.2";
|
||||||
|
|
||||||
// Construct the script tag
|
// Construct the script tag
|
||||||
|
|||||||
@ -23,10 +23,16 @@ export function set(data){
|
|||||||
var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
var sendRequest = (dispatch, getState, endpoint, method = 'GET', data = false) => {
|
||||||
return new Promise((resolve, reject) => {
|
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
|
// create our ajax request config
|
||||||
var config = {
|
var config = {
|
||||||
method: method,
|
method: method,
|
||||||
url: 'https://api.genius.com/'+endpoint+'?access_token='+getState().genius.access_token,
|
url: url,
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
crossDomain: true
|
crossDomain: true
|
||||||
}
|
}
|
||||||
@ -124,19 +130,21 @@ export function getMe(){
|
|||||||
export function getTrackLyrics(uri, path){
|
export function getTrackLyrics(uri, path){
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
|
||||||
dispatch({
|
dispatch(coreActions.trackLoaded({
|
||||||
type: 'TRACK_LOADED',
|
|
||||||
track: {
|
|
||||||
uri: uri,
|
uri: uri,
|
||||||
lyrics: null,
|
lyrics: null,
|
||||||
lyrics_path: 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(
|
.then(
|
||||||
response => {
|
(response, status, xhr) => {
|
||||||
|
|
||||||
var html = $(response);
|
var html = $(response);
|
||||||
var lyrics = html.find('.lyrics');
|
var lyrics = html.find('.lyrics');
|
||||||
if (lyrics.length > 0){
|
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 class="grey-text">[');
|
||||||
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
|
lyrics_html = lyrics_html.replace(/(\])/g, ']</span>');
|
||||||
|
|
||||||
dispatch({
|
dispatch(coreActions.trackLoaded({
|
||||||
type: 'TRACK_LOADED',
|
|
||||||
track: {
|
|
||||||
uri: uri,
|
uri: uri,
|
||||||
lyrics: lyrics_html,
|
lyrics: lyrics_html,
|
||||||
lyrics_path: path
|
lyrics_path: path
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
error => {
|
(xhr, status, error) => {
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
'Could not extract track lyrics',
|
'Could not get track lyrics',
|
||||||
error
|
error
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -180,25 +186,22 @@ export function findTrackLyrics(track){
|
|||||||
query = query.replace(/\([^)]*\) */g, ''); // anything in circle-braces
|
query = query.replace(/\([^)]*\) */g, ''); // anything in circle-braces
|
||||||
query = query.replace(/\([^[]*\] */g, ''); // anything in square-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(
|
.then(
|
||||||
response => {
|
response => {
|
||||||
if (response.response.hits && response.response.hits.length > 0){
|
if (response.hits && response.hits.length > 0){
|
||||||
var lyrics_results = [];
|
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({
|
lyrics_results.push({
|
||||||
title: response.response.hits[i].result.full_title,
|
title: response.hits[i].result.full_title,
|
||||||
url: response.response.hits[i].result.url,
|
url: response.hits[i].result.url,
|
||||||
path: response.response.hits[i].result.path
|
path: response.hits[i].result.path
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
dispatch({
|
dispatch(coreActions.trackLoaded({
|
||||||
type: 'TRACK_LOADED',
|
|
||||||
track: {
|
|
||||||
uri: track.uri,
|
uri: track.uri,
|
||||||
lyrics_results: lyrics_results
|
lyrics_results: lyrics_results
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
// Immediately go and get the first result's lyrics
|
// Immediately go and get the first result's lyrics
|
||||||
var lyrics_result = lyrics_results[0];
|
var lyrics_result = lyrics_results[0];
|
||||||
@ -207,7 +210,7 @@ export function findTrackLyrics(track){
|
|||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
'Could not get track info',
|
'Could not search for track lyrics',
|
||||||
error
|
error
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
|
|
||||||
import ReactGA from 'react-ga'
|
import ReactGA from 'react-ga'
|
||||||
|
|
||||||
var helpers = require('../../helpers.js')
|
var helpers = require('../../helpers')
|
||||||
var coreActions = require('../core/actions.js')
|
var coreActions = require('../core/actions')
|
||||||
var uiActions = require('../ui/actions.js')
|
var uiActions = require('../ui/actions')
|
||||||
var mopidyActions = require('../mopidy/actions.js')
|
var mopidyActions = require('../mopidy/actions')
|
||||||
var pusherActions = require('./actions.js')
|
var pusherActions = require('./actions')
|
||||||
var lastfmActions = require('../lastfm/actions.js')
|
var lastfmActions = require('../lastfm/actions')
|
||||||
var spotifyActions = require('../spotify/actions.js')
|
var geniusActions = require('../lastfm/actions')
|
||||||
|
var spotifyActions = require('../spotify/actions')
|
||||||
|
|
||||||
const PusherMiddleware = (function(){
|
const PusherMiddleware = (function(){
|
||||||
|
|
||||||
|
|||||||
@ -290,11 +290,7 @@ export function getTrack(uri){
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
dispatch({
|
dispatch(coreActions.trackLoaded(track));
|
||||||
type: 'TRACK_LOADED',
|
|
||||||
key: uri,
|
|
||||||
track: track
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
@ -1333,10 +1329,7 @@ export function getAlbum(uri){
|
|||||||
response => {
|
response => {
|
||||||
|
|
||||||
// dispatch our loaded artists (simple objects)
|
// dispatch our loaded artists (simple objects)
|
||||||
dispatch({
|
dispatch(coreActions.artistsLoaded(response.artists));
|
||||||
type: 'ARTISTS_LOADED',
|
|
||||||
artists: response.artists
|
|
||||||
});
|
|
||||||
|
|
||||||
var album = Object.assign(
|
var album = Object.assign(
|
||||||
{},
|
{},
|
||||||
@ -1357,11 +1350,7 @@ export function getAlbum(uri){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch({
|
dispatch(coreActions.albumLoaded(album));
|
||||||
type: 'ALBUM_LOADED',
|
|
||||||
key: album.uri,
|
|
||||||
album: album
|
|
||||||
});
|
|
||||||
|
|
||||||
// now get all the artists for this album (full objects)
|
// now get all the artists for this album (full objects)
|
||||||
// we do this to get the artist artwork
|
// we do this to get the artist artwork
|
||||||
@ -1374,10 +1363,7 @@ export function getAlbum(uri){
|
|||||||
sendRequest(dispatch, getState, 'artists/?ids='+artist_ids )
|
sendRequest(dispatch, getState, 'artists/?ids='+artist_ids )
|
||||||
.then(
|
.then(
|
||||||
response => {
|
response => {
|
||||||
dispatch({
|
dispatch(coreActions.artistsLoaded(response.artists));
|
||||||
type: 'ARTISTS_LOADED',
|
|
||||||
artists: response.artists
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
dispatch(coreActions.handleException(
|
dispatch(coreActions.handleException(
|
||||||
|
|||||||
Reference in New Issue
Block a user