Skip to content

Instantly share code, notes, and snippets.

@Slyyxp
Created June 20, 2022 03:57
Show Gist options
  • Save Slyyxp/b2a07a2756a5416bac4e9d03f85723ae to your computer and use it in GitHub Desktop.
Save Slyyxp/b2a07a2756a5416bac4e9d03f85723ae to your computer and use it in GitHub Desktop.
Melon.co.kr client
import requests
# epoints
# https://play.melon.com/cds/delivery/android/streaming_path.json
class Client:
def __init__(self):
self.session = requests.Session()
self.session.headers.update({
"User-Agent": "Mozilla/5.0 (Linux; Android 5.1.1; SM-G973N Build/PPR1.190810.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36",
})
resp = self.auth()
resp = self.prestream(34614815)
print(resp)
def make_call(self, sub, epoint, data):
r = self.session.post(
"https://{}.melon.com/{}".format(sub, epoint), data=data)
r.raise_for_status()
return r
def auth(self):
data = {
"client_id": "5c2982b2ec377339ee67d3686f4813ac",
"app_key": "5c2982b2ec377339ee67d3686f4813ac",
"email": "",
"password": ""}
r = self.session.post(
"https://auth.kakao.com/kakao_accounts/login.json", data=data
)
r.raise_for_status()
return r.json()
def streaming_path(self, id):
data = {
"cpId": "",
"cpKey": "",
"v": "4.0",
"resolution": "2",
"appVer": "6.4.1",
"cType": 1,
"cId": id,
"metaType": "",
"bitrate": "",
"sessionId": "",
"networkType": "wifi"
}
r = self.make_call("app", "cds/delivery/android/streaming_path.json", data)
return r
def prestream(self, id):
data = {
"q": "",
"cid": id,
"cacheEnable": "Y",
"isLocal": "N",
"bitrate": "96",
"metaType": "AAC"
}
file_path = "test.mp4"
r = self.session.post("https://spmd.melon.com/prestream", data=data)
with open(file_path, 'wb') as f:
for chunk in r.iter_content(32 * 1024):
if chunk:
f.write(chunk)
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment