Skip to content

Instantly share code, notes, and snippets.

@nosun
Forked from jorgebastida/spotify.py
Created February 3, 2018 09:33
Show Gist options
  • Save nosun/046ef9bba0c26ec88676a539977d2c7e to your computer and use it in GitHub Desktop.
Save nosun/046ef9bba0c26ec88676a539977d2c7e 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