Python collects Himalayan audio, anytime, anywhere, listen to me

Time:2020-2-15

Preface

The text and pictures of the article are from the Internet, only for learning and communication, and do not have any commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for handling.

PS: if you need Python learning materials, you can click the link below to get them by yourself

http://note.youdao.com/noteshare?id=3054cce4add8a909e784ad934f956cef

Himalayan FM is a professional audio sharing platform, which collects audio novels, audio books and audio books, Children’s bedtime stories, crosstalk sketches, ghost stories and hundreds of millions of audio. Today we learn how to collect Himalayan audio. Anytime, anywhere, listen to me.

Development environment:

  1. Version: Anaconda 5.2.0 (Python 3.6.5)

  2. Editor: pycharm

Related modules:

import requests
import pprint
import re

Realization effect

在这里插入图片描述 在这里插入图片描述

Complete code

import requests
import pprint
import re

"" "find rules for bulk download" ""

Block notes
"" "use the ID of the incoming audio from the interface to get the download address of the audio" ""

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'
}


def download_media(song_id, sond_name):
    #Select tab Shift + tab to undo indent
    "" "based on songid name" ""
    media_url = 'https://www.ximalaya.com/revision/play/v1/audio?id=' + song_id + '&ptype=1'
    #Fake browser identity
    response = requests.get(media_url, headers=headers)
    #I was requested by Python
    # print(response.request.headers)
    #Dictionary type
    data = response.json()
    # print(data)
    # pprint.pprint(data)
    #Format and print beautiful data as long as you can use it
    # pprint.pprint(data['data'])
    mp3_url = data['data']['src']

    #Does video audio image binary need to be decoded?
    response = requests.get(mp3_url)
    #Text text content
    # print(response)
    with open(sond_name + '.m4a', 'wb') as f:
        f.write(response.content)
    Print (song_name, 'download completed')


#Song_name = 'goddess's intimate master Episode 10 real master'
# song_id = '98944395'
# download_media(song_id, sond_name)
for i in range(1, 32):
    response = requests.get('https://www.ximalaya.com/youshengshu/16411402/p'+str(i)+'/', headers=headers)
    # print(response.text)
    name_url = re.findall('', response.text)
    for i in name_url:
        print(i[0], i[1])
        download_media(i[1], i[0])