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

Keywords: Python Anaconda Pycharm Windows

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 gathers hundreds of millions of audio such as audio novels, audio books, audio books, bedtime stories of children, crosstalk sketches, ghost stories, etc 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 batch download"""

# Block annotation
"""Using the interface to input audio id Get the download address of 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
    """according to 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(sond_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('<div class="text _c2"><a title="(.*?)" href="/youshengshu/16411402/(\d+)">', response.text)
    for i in name_url:
        print(i[0], i[1])
        download_media(i[1], i[0])

Posted by PcGeniusProductions on Sun, 10 Nov 2019 10:11:01 -0800