注意

只支持免费音频下载;

分析视频

https://www.bilibili.com/video/BV1Y44y1K7cm/
# -*- coding: utf-8 -*-
# @Author: Null119
# @Desc: { 蜻蜓FM一键下载 }
# @Date: 2022/03/11 7:28

import requests, urllib3, re, jsonpath, hmac, time, os, random

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

r = requests.session()

def downFile(path, url):
    song = r.get(url, verify=False)
    with open(path, 'wb') as f:
        f.write(song.content)

def startDown(url):
    bookid = re.search('channels/(\d+)', url).group(1)
    html = r.get(url, verify=False).text
    ver = re.search(r'"version":"(.*?)"', html).group(1)
    bookName = re.search(r'<span class="title">(.*?)<',html).group(1)
    nurl = 'https://i.qingting.fm/capi/channel/%s/programs/%s?curpage=1&pagesize=999&order=asc' % (bookid, ver)
    html = r.get(nurl, verify=False)
    sid = jsonpath.jsonpath(html.json(), '$.data.programs..id')
    title = jsonpath.jsonpath(html.json(), '$.data.programs..title')
    for i in range(len(sid)):
        s_id = sid[i]
        s_title = title[i]
        print('开始下载:%s [%d/%d]' % (s_title, i + 1, len(sid)))
        ts = str(int(time.time() * 1000))
        enstr = "/audiostream/redirect/%s/%s?access_token=&device_id=MOBILESITE&qingting_id=&t=%s" % (bookid, s_id, ts)
        key = b'fpMn12&38f_2e'
        sign = hmac.new(key, enstr.encode(), digestmod='MD5').hexdigest()
        durl = "https://audio.qtfm.cn/audiostream/redirect/%s/%s?access_token=&device_id=MOBILESITE&qingting_id=&t=%s&sign=%s" % (
        bookid, s_id, ts, sign)
        html = r.get(durl, allow_redirects=False, verify=False)
        try:
            surl = re.search('href="(.*?)"', html.text).group(1)
        except:
            print(html.json()['errormsg'])
            break
        fileTyp = re.search(r'\d+_\d+(\..*?)\?', surl).group(1)

        if not os.path.exists('./' + bookName + '/'): os.mkdir('./' + bookName + '/')
        if not os.path.isfile('./' + bookName + '/' + s_title + fileTyp):
            downFile('./' + bookName + '/' + s_title + fileTyp, surl)
            time.sleep(random.randint(1, 3))

if __name__ == '__main__':
    url = 'https://www.qingting.fm/channels/237097/'
    startDown(url)
如果觉得我的文章对你有用,请随意赞赏