Skip to content

Instantly share code, notes, and snippets.

@Slyyxp
Created June 20, 2022 03:57
Show Gist options
  • Select an option

  • Save Slyyxp/b2a07a2756a5416bac4e9d03f85723ae to your computer and use it in GitHub Desktop.

Select an option

Save Slyyxp/b2a07a2756a5416bac4e9d03f85723ae to your computer and use it in GitHub Desktop.

Revisions

  1. Slyyxp renamed this gist Jun 20, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Slyyxp created this gist Jun 20, 2022.
    66 changes: 66 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    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