吾爱破解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下载完成,请按任意键结束...")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值