Skip to content

Commit

Permalink
Merge branch 'release/0.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Aug 2, 2014
2 parents e9f1d03 + d5880a8 commit 4059062
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 92 deletions.
2 changes: 1 addition & 1 deletion spotify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.8.1'
__version__ = '0.8.2'

try:
from spotify.client import Spotify
Expand Down
61 changes: 50 additions & 11 deletions spotify/commands/flash.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
from spotify.commands.base import Command
from spotify.commands.flash_key import FLASH_KEY

import logging
import urllib

log = logging.getLogger(__name__)


class PingFlash2(Command):
host = 'spflash.herokuapp.com'

def process(self, ping):
ping = ping.split(' ')
pong = "undefined 0"
version = self.sp.config.get('cdn')

if version:
pos = version.rfind('/')

if pos >= 0:
version = version[pos + 1:]
else:
version = None

if not version:
version = 'generic'

self.session.get(
'http:https://%s/%s/get?ping=%s' % (
self.host, version,
urllib.quote(ping)
)
).add_done_callback(self.on_result)

def on_result(self, future):
if not self.validate(future):
return

res = future.result()

# Validate response
if res.status_code != 200:
# 503 = Backend service timeout
if res.status_code == 503:
self.emit('error', 'PingFlash2 - service unavailable')
return

self.emit('error', 'PingFlash2 - service returned unexpected status code (%s)' % res.status_code)
return

if len(ping) >= 20:
result = []
if not res.text:
self.emit('error', 'PingFlash2 - response doesn\'t look valid')
return

for idx, code in FLASH_KEY:
val = int(ping[idx])
self.send('sp/pong_flash2', res.text)

result.append(str(val ^ code if type(code) is int else code[val]))
def validate(self, future):
ex = future.exception()

pong = ' '.join(result)
if not ex:
return True

log.debug('received ping %s, sending pong: %s' % (ping, pong))
if ex.args:
ex = ex.args[0].reason

return self.send('sp/pong_flash2', pong)
self.emit('close', *ex)
return False
80 changes: 0 additions & 80 deletions spotify/commands/flash_key.py

This file was deleted.

0 comments on commit 4059062

Please sign in to comment.