mirror of
https://github.com/zhaarey/AppleMusicDecrypt.git
synced 2025-10-23 15:11:06 +00:00
feat: mitm download
This commit is contained in:
33
src/mitm.py
Normal file
33
src/mitm.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import plistlib
|
||||
|
||||
import mitmproxy.http
|
||||
from mitmproxy import options
|
||||
from mitmproxy.tools import dump
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class RequestHandler:
|
||||
def __init__(self, callback):
|
||||
self.callback = callback
|
||||
|
||||
def response(self, flow: mitmproxy.http.HTTPFlow):
|
||||
if flow.request.host == "play.itunes.apple.com" and flow.request.path == "/WebObjects/MZPlay.woa/wa/subPlaybackDispatch":
|
||||
data = plistlib.loads(flow.response.content)
|
||||
m3u8 = data["songList"][0]["hls-playlist-url"]
|
||||
flow.response.status_code = 500
|
||||
self.callback(m3u8)
|
||||
|
||||
|
||||
async def start_proxy(host, port, callback):
|
||||
opts = options.Options(listen_host=host, listen_port=port, mode=["socks5"])
|
||||
|
||||
master = dump.DumpMaster(
|
||||
opts,
|
||||
with_termlog=False,
|
||||
with_dumper=False,
|
||||
)
|
||||
master.addons.add(RequestHandler(callback))
|
||||
|
||||
logger.info(f"Mitmproxy started at socks5://{host}:{port}")
|
||||
|
||||
await master.run()
|
||||
Reference in New Issue
Block a user