Skip to content

Instantly share code, notes, and snippets.

@dengmin
Created January 7, 2020 02:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dengmin/64b5d3b288c67e29c537149a07c60ccc to your computer and use it in GitHub Desktop.
Save dengmin/64b5d3b288c67e29c537149a07c60ccc to your computer and use it in GitHub Desktop.
下载咪咕音乐的脚本
import requests
HEADERS = {
"Accept": '*/*',
"platform": 'iOS',
"ua": 'Ios_migu',
"msisdn": '13136170890',
"User-Agent": "MGMobileMusic/6.8.8 (iPhone;iOS 12.4.1; Scale/2.00)",
"Host": 'app.c.nf.migu.cn',
"referer": 'http://wwww.google.com/'
}
class Api:
session = requests.Session()
session.headers.update(HEADERS)
@classmethod
def request(cls, url, method="POST", data=None):
if method == 'GET':
resp = cls.session.get(url, params=data, timeout=10)
else:
resp = cls.session.post(url, data=data, timeout=10)
if resp.status_code != requests.codes.ok:
raise Exception(resp.text)
if not resp.text:
raise Exception("no response data")
return resp.json()
def migu_search(keyword):
params = {
'isCopyright': 1,
'isCorrect': 1,
'pageNo': 1,
'pageSize': 20,
'sort': 0,
'text': keyword,
'searchSwitch': '{"song":1,"album":0,"singer":0,"tagSong":1,"mvSong":0,"songlist":0,"bestShow":1,"lyricSong":0}'
}
response = Api.request('https://app.c.nf.migu.cn/MIGUM2.0/v1.0/content/search_all.do', "GET", params)
res_data = response.get('songResultData', {}).get("resultList", [])
for items in res_data:
for item in items:
singers = [s.get("name", "") for s in item.get('singers')]
print(singers, item.get('name'))
rate_list = item.get('rateFormats', [])
for x in rate_list:
if len(x.get('url', "")) > 0:
print(x.get('formatType'),
x.get('url').replace('ftp://218.200.160.122:21', 'http://freetyst.nf.migu.cn'))
migu_search("一生所爱")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment