Skip to content

Instantly share code, notes, and snippets.

@jorgebastida
Created November 16, 2012 17:18
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jorgebastida/4089133 to your computer and use it in GitHub Desktop.
Save jorgebastida/4089133 to your computer and use it in GitHub Desktop.
Rudimentary Spotify Web Proxy using mitmproxy
#!/usr/bin/env python
"""
Rudimentary Spotify Web Proxy using mitmproxy.
Use it by your own responsibility!!
This was only entertainment!!
"""
import random
import hashlib
from libmproxy import proxy, flow
class SpotifyProxy(flow.FlowMaster):
def run(self):
try:
flow.FlowMaster.run(self)
except KeyboardInterrupt:
self.shutdown()
def handle_request(self, r):
f = flow.FlowMaster.handle_request(self, r)
if f:
r._ack()
return f
def handle_response(self, r):
f = flow.FlowMaster.handle_response(self, r)
if f:
r._ack()
if 'cloudfront.net' in f.request.host and 'mp3' in f.request.path:
filename = '%s.mp3' % hashlib.sha1(str(random.random())).hexdigest()
mp3 = open(filename, 'w')
mp3.write(f.response.content)
mp3.close()
print "Saved to %s" % filename
return f
config = proxy.ProxyConfig()
state = flow.State()
server = proxy.ProxyServer(config, 9000)
m = SpotifyProxy(server, state)
m.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment