-
-
Save nosun/046ef9bba0c26ec88676a539977d2c7e to your computer and use it in GitHub Desktop.
Rudimentary Spotify Web Proxy using mitmproxy
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
#!/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