Give a song name, search and download the song
Song site, crawl mp3 and Lyric
This article introduces the song resource path to the song site, download the song
The main differences,
- I’ll give you the name of the song, I’ll get the name of the song, I’ll search for the song ID,
Through the song ID, get lyrics, song resource path, and finally download song resources
- I’ll give you the URL of the song, the ID of the song, I need to find the name of the song,
You have the song ID, take the lyrics, the song resource path, and the song resource
Take ID from the url
info=songUrl.split("=")
song_id=info[1]
Copy the code
Use ID to get the name of the song
songInfoUrl = "http://music.x.com/api/song/detail/?id={}&ids=%5B{}%5D".format(song_id, song_id)
songInfoResponse = self.crawler.session.get(songInfoUrl)
songInfoJSON = songInfoResponse.json()
song_name = songInfoJSON['songs'][0]["name"]
Copy the code
The idea was to take the web URL of the song, download the entire page,
Find the song title from the page
no
Because some music sites, the song information is loaded later
Get the lyrics with ID
csrf = ''
lyricUrl = 'http://music.x.com/api/song/lyric/?id={}&lv=-1&csrf_token={}'.format(song_id, csrf)
lyricResponse = self.session.get(lyricUrl)
lyricJSON = lyricResponse.json()
lyrics = lyricJSON['lrc']['lyric'].split("\n")
Copy the code
Get the song resource path with ID
url = 'http://music.x.com/weapi/song/enhance/player/url?csrf_token=' csrf = '' params = {'ids': [song_id], 'br': Csrf_token: CSRF} result = self.post_request(url, params) # song_url = result['data'][0]['url']Copy the code