吾爱破解python百度文库下载源码_python版百度音乐下载软件和源码
[Python] 純文本查看 復制代碼# -*-coding:utf-8-*-
import re
import urllib
import requests
def downmp3(url1):
try:
print("正在解析網頁,請稍后。\n")
pre_html = requests.get(url1).content.decode('utf-8')
except:
print("請檢查網絡連接是否正確。\n")
else:
print("解析完成")
key = re.findall(r'
', pre_html, re.M | re.S)url = "http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.song.play&songid=" + key[0]
html = requests.get(url).content.decode('utf-8')
dowbload_url = re.findall(r'"show_link":"(.*?)","free"', html, re.M | re.S)
mp3detail = re.findall(r'"lrclink":"(.*?)","', html, re.M | re.S)
download = dowbload_url[0].replace('\\', '')
lrc_temp = mp3detail[0].replace('\\', '')
mp3 = urllib.request.urlopen(download)
try:
print("正在下載歌曲,請稍后...\n")
output = open(key[0] + ".mp3", 'wb')
output.write(mp3.read())
output.close()
except IOError:
print("下載失敗,請確認程序是否有寫入權限!!!")
else:
print("下載歌曲成功")
lrc = requests.get(lrc_temp).content.decode('utf-8')
try:
print("正在下載歌詞,請稍后...\n")
output = open(key[0] + ".lrc", 'w')
output.write(lrc)
output.close()
except IOError:
print("下載失敗,請確認程序是否有寫入權限!!!")
else:
print("下載歌詞成功")
print("請輸入歌名或歌手")
searchmp3 = input('')
searchmp3_respons = requests.get("http://music.baidu.com/search?key=" + searchmp3).content
print(searchmp3_respons.decode('utf-8'))
ff = open("temp.tmp", 'w')
ff.write(searchmp3_respons.decode('utf-8'))
ff.close()
ff = open("temp.tmp", 'r')
sstr = ff.read()
ff.close()
searchmp3_respons1 = searchmp3_respons
tag_songid = re.findall(r'data-songdata=\'{ "id": "(.*?)" }\'', sstr, re.M | re.S)
tag_div = re.findall(
r'data-film.*?data-info=.*?\'>(.*?).*?(.*?)',
sstr, re.M | re.S)
count = 1
for line in tag_div:
a = re.sub('', '', line[0])
b = re.sub('', '', a)
e = re.sub('\t', '', b)
f = re.sub('\n', '', e)
i = re.sub(' ', '', f)
c = re.sub('\t', '', line[1])
d = re.sub('\n', '', c)
g = re.sub('', '', d)
h = re.sub('', '', g)
j = re.sub(' ', '', h)
try:
print("[" + str(count) + "]\t\t" + i + "\t\t\t" + j)
except:
print("[" + str(count) + "]\t\t字體顯示不出來,但是可以下載")
count = count + 1
print("請輸入要下載歌曲的序號或者輸入all全部下載")
input = input('')
if input == 'all':
for i in range(1, count):
str = "http://music.baidu.com/song/" + tag_songid[i - 1]
downmp3(str)
else:
urldownload = "http://music.baidu.com/song/" + tag_songid[int(input) - 1]
print(urldownload)
downmp3(urldownload)
print("\n下載完成,請按任意鍵結束...")
總結
以上是生活随笔為你收集整理的吾爱破解python百度文库下载源码_python版百度音乐下载软件和源码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 百度扩容软件V.2.3版,第四代扩容带自
- 下一篇: 爱心动画c语言,jquery+html5