Skip to content
Browse files

add (ghetto?) support for album art

  • Loading branch information...
1 parent 2666975 commit dedfa0fb6e4fc4e76363333876b960830c87a47e @mkjones committed Jan 24, 2012
Showing with 23 additions and 8 deletions.
  1. +1 −1 README.md
  2. +1 −0 index.html
  3. +3 −0 master.py
  4. +11 −7 spotify.py
  5. +7 −0 spotnado.py
View
2 README.md
@@ -15,7 +15,7 @@ which (rightfully) doesn't have permissions to touch Spotify. So instead
I wrote it with Tornado in Python.
# How to use
-0. Install Tornado (http://www.tornadoweb.org/)
+0. Install Tornado (http://www.tornadoweb.org/) and Imagemagick (http://www.imagemagick.org).
1. Start up Spotify.
2. Run `python spotnado.py`
3. Hit http://*your computer's IP*:8888 from your iphone or browser
View
1 index.html
@@ -68,6 +68,7 @@
<div class="song">
<div class="name">{{ track_name }}</div>
<div class="artist">{{ track_artist }}</div>
+ <div class="artwork"><img width="120" height="120" src="/art" /></div>
</div>
<div id="buttons">
<form action="/do" method="post">
View
3 master.py
@@ -36,6 +36,9 @@ def get(self):
if (internal):
self.redirect('http://%s:8888/' % (internal))
else:
+ self.render('unknown_addr.html',
+ remote_ip=remote_ip,
+ all_addrs = RegisterHandler.addrs)
self.write('unknown address %s' % (remote_ip))
application = tornado.web.Application([
View
18 spotify.py
@@ -1,6 +1,7 @@
import os
import subprocess
import binhex
+import binascii
class Spotify:
@@ -45,13 +46,16 @@ def setVolume(self, value):
def getArt(self):
raw = self._get('artwork of current track')
- data = raw[10:-1]
- f = open('/tmp/whatever', 'w')
- f.write(data)
- f.close
- binhex.hexbin(open('/tmp/whatever', 'r'),
- open('/tmp/whatever.out', 'w'))
-
+ binary = binascii.a2b_hex(raw[11:-3])
+ f = open('/tmp/whatever.tiff', 'w')
+ f.write(binary)
+ f.close()
+ subprocess.Popen(('convert', '/tmp/whatever.tiff',
+ '/tmp/whatever.jpg')).wait()
+ jpg = open('/tmp/whatever.jpg')
+ ret = jpg.read(1000000)
+ jpg.close()
+ return ret
def _get(self, thing):
things = (
View
7 spotnado.py
@@ -37,9 +37,16 @@ def post(self):
self.redirect('/')
+class ArtHandler(tornado.web.RequestHandler):
+ def get(self):
+ s = Spotify()
+ self.set_header('Content-Type', 'image/jpeg')
+ self.write(s.getArt())
+
application = tornado.web.Application([
(r"/", MainHandler),
(r"/do", DoHandler),
+ (r"/art", ArtHandler),
])
if __name__ == "__main__":

0 comments on commit dedfa0f

Please sign in to comment.
Something went wrong with that request. Please try again.