Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedb committed Oct 8, 2019
2 parents 6dbe422 + e34544e commit 5d49a4a
Show file tree
Hide file tree
Showing 162 changed files with 55,933 additions and 53,619 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"parser": "babel-eslint",
"extends": [
"airbnb"
],
"rules": {
"react/jsx-filename-extension": 0,
"react/no-danger": 0,
"no-console": 0,
"no-underscore-dangle": 0,
"react/prop-types": 0,
"linebreak-style": 0
},
"globals": {
"fetch": true
},
"env": {
"jest": true,
"browser": true,
"es6": true
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ Thumbs.db
npm-debug.log
*sublime*
.DS_Store
.idea
venv
docker/mopidy.conf
docker-compose.yml
50 changes: 44 additions & 6 deletions mopidy_iris/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ def change_radio(self, *args, **kwargs):
# Save results (minus first batch) for later use
self.radio['results'] = uris[3:]

self.add_radio_metadata(added)

if starting:
self.core.playback.play()
self.broadcast(data={
Expand Down Expand Up @@ -764,8 +766,26 @@ def check_for_radio_update( self ):
# Only add the next set of uris
uris = uris[0:3]

self.core.tracklist.add(uris = uris)
added = self.core.tracklist.add(uris = uris)

self.add_radio_metadata(added)


def add_radio_metadata( self, added ):
seeds = ''
if len(self.radio['seed_artists']) > 0:
seeds = seeds+(','.join(self.radio['seed_artists'])).replace('spotify:artist:','spotify_artist_')
if len(self.radio['seed_tracks']) > 0:
if seeds != '': seeds = seeds+','
seeds = seeds+(','.join(self.radio['seed_tracks'])).replace('spotify:track:','spotify_track_')
if len(self.radio['seed_genres']) > 0:
if seeds != '': seeds = seeds+','
seeds = seeds+(','.join(self.radio['seed_genres'])).replace('spotify:genre:','spotify_genre_')

metadata = {'tlids': [], 'added_by': 'Radio', 'added_from': 'iris:radio:'+seeds}
for added_tltrack in added.get():
metadata['tlids'].append(added_tltrack.tlid)
self.add_queue_metadata(data=metadata)


##
Expand Down Expand Up @@ -881,7 +901,6 @@ def run_command(self, *args, **kwargs):
}
else:
command = self.commands[str(data['id'])]

if "method" not in command:
error = {
'message': 'Command failed',
Expand All @@ -893,6 +912,8 @@ def run_command(self, *args, **kwargs):
'description': 'Missing required property "url"'
}

logger.debug("Running command "+str(command))

if error:
if (callback):
callback(False, error)
Expand All @@ -902,10 +923,22 @@ def run_command(self, *args, **kwargs):

# Construct the request
http_client = tornado.httpclient.HTTPClient()
# Build headers dict if additional headers are given
headers = None
if 'additional_headers' in command:
d = command['additional_headers'].split('\n')
lines = list(filter(lambda x: x.find(':') > 0, d))
fields = [(x.split(':', 1)[0].strip().lower(), x.split(':', 1)[1].strip()) for x in lines]
headers = dict(fields)

if (command['method'] == 'POST'):
request = tornado.httpclient.HTTPRequest(command['url'], connect_timeout=5, method='POST', body=json.dumps(command['post_data']), validate_cert=False)
if 'content-type' in headers and headers['content-type'].lower() != 'application/json':
post_data = command['post_data']
else:
post_data = json.dumps(command['post_data'])
request = tornado.httpclient.HTTPRequest(command['url'], connect_timeout=5, method='POST', body=post_data, validate_cert=False, headers=headers)
else:
request = tornado.httpclient.HTTPRequest(command['url'], connect_timeout=5, validate_cert=False)
request = tornado.httpclient.HTTPRequest(command['url'], connect_timeout=5, validate_cert=False, headers=headers)

# Make the request, and handle any request errors
try:
Expand All @@ -921,17 +954,22 @@ def run_command(self, *args, **kwargs):
else:
return error

# Attempt to parse JSON
# Attempt to parse body as JSON
try:
command_response_body = json.loads(command_response.body)
except:
command_response_body = command_response.body
# Perhaps it requires unicode encoding?
try:
command_response_body = tornado.escape.to_unicode(command_response.body)
except:
command_response_body = ""

# Finally, return the result
response = {
'message': 'Command run',
'response': command_response_body
}

if (callback):
callback(response)
return
Expand Down
Loading

0 comments on commit 5d49a4a

Please sign in to comment.