-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
92 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
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 | ||
|
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 |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.