新年快乐,上班第一天分享一个python源码,功能比较简单,就是实现酷狗音乐的音乐文件(包含付费音乐)和所有评论回复的下载。

以 米津玄師 - Lemon 为例, 以下为效果图:

1、根据关键词搜索指定音乐,发现是下载是付费的

2、点击进入评论,可以看到有很多的评论,评论底下也有很多的回复

3、执行代码下载音乐、评论回复

3.1、输入关键词搜索音乐,根据歌曲名称和时长,选择目标歌曲,根据提示下载音乐文件

3.2、下载评论回复

3.3、下载结果,评论回复较多,作为例子只下载了一部分

最后附上源码:

import requests
import json# 写到文档
def write(path, text):with open(path, 'a', encoding='utf-8') as f:f.write(text+'\n')# 时间转换
def get_time(duration):second = duration % 60minuter = int(duration / 60)hour = int(minuter / 60)minuter = int(minuter % 60) if hour > 0 else minutertime = []for i in [hour, minuter, second]:i = str(i) if i >= 10 else '0'+str(i)time.append(i)return ':'.join(time)# 下载音乐
def down(filehash):hash_url = "http://www.kugou.com/yy/index.php?r=play/getdata&hash={0}".format(filehash)hash_content = requests.get(hash_url).textdt = json.loads(hash_content)audio_name = dt['data']['audio_name']audio_url = dt['data']['play_url']with open(audio_name + ".mp3", "wb")as fp:fp.write(requests.get(audio_url).content)print("音乐下载完成:{0}".format(audio_name + ".mp3"))# 下载所有回复
def get_reply(path, special_child_id, tid, pagesize=10, pageindex=1):url = ('http://comment.service.kugou.com/index.php?''r=commentsv2/getReplyWithLike''&code=fc4be23b4e972707f36b8a828a93ba8a''&p={0}''&pagesize={1}''&ver=1.01''&clientver=8323''&kugouid=998708111''&clienttoken=8048d52b7884b9e9e606d0a06a6a5ec7b2ad556931dcedc14d9cd3247bf3ee4d''&appid=1001''&childrenid={2}''&tid={3}'.format(pageindex, pagesize, special_child_id, tid))response = requests.get(url)response = json.loads(response.text)if response.get('list'):for comment in response['list']: # 回复content = comment.get('content')user_name = comment.get('user_name')extdata = comment.get('extdata').replace('null', '\'\'')city = eval(extdata).get('city')city = '(' + city + ')' if city else ''content = '【回复 {1}{0}】{2}'.format(user_name, city, content)write(path, content)if response.get('list'): # 列表有值,请求下一页get_reply(path, special_child_id, tid, pagesize, pageindex + 1)# 下载所有评论、回复
def get_comment(path, filehash, pagesize=10, pageindex=1):url = ('http://comment.service.kugou.com/index.php?''&r=commentsv2/getCommentWithLike''&code=fc4be23b4e972707f36b8a828a93ba8a''&extdata={0}' '&pagesize={1}''&ver=1.01''&clientver=8323''&kugouid=998708111''&clienttoken=8048d52b7884b9e9e606d0a06a6a5ec7b2ad556931dcedc14d9cd3247bf3ee4d''&appid=1001''&p={2}'.format(filehash, pagesize, pageindex))response = requests.get(url)response = json.loads(response.text)if response['message'] == 'success':for index, comment in enumerate(response['list'],1): # 评论content = comment.get('content')user_name = comment.get('user_name')extdata = comment.get('extdata').replace('null','\'\'')city = eval(extdata).get('city')city = '('+ city +')' if city else ''content = '【{0}_{1}评论 {4}{3}】{2}'.format(pageindex, index, content, user_name, city)write(path, content)tid = comment.get('id')special_child_id = comment.get('special_child_id')get_reply(path, special_child_id, tid) #回复print("第{0}页下载完成".format(pageindex))if response.get('list'): # 列表有值,请求下一页get_comment(path, filehash, pagesize, pageindex + 1)# 搜索歌曲
def search(keyword, pagesize=10):search_url = ('http://songsearch.kugou.com/song_search_v2?callback=jQuery112407470964083509348_1534929985284&keyword={0}&''page=1&pagesize={1}&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filte''r=0'.format(keyword, pagesize))response = requests.get(search_url).textjs = json.loads(response[response.index('(') + 1:-2])data = js['data']['lists']songs = [['序号', '时长' + ' ' * 4, '歌曲名称']]print('  >>>  '.join(songs[0]))for index, song in enumerate(data, 1):filename = song.get('FileName')filename = filename.replace('<em>', '').replace('</em>', '') if filename else ''filehash = song.get('FileHash')duration = song.get('Duration', 0)duration = get_time(duration)index = str(index) + (4 - len(str(index))) * ' 'item = [index, duration, filename, filehash]songs.append(item)print('  >>>  '.join(item[:-1]))return songsif __name__ == '__main__':keyword = input("请输入搜索歌曲名称:")songs = search(keyword)while True:index = 0while True:index = input("请输入歌曲序号:")if index.isdigit() and int(index) < len(songs):breakelse:print("请输入有效的歌曲序号, 再进行下载选择!")type = 0while True:type = input("下载类型:\n【1】下载音乐\n【2】下载歌曲的所有评论回复\n【-1】退出程序\n请输入下载类型:")if type.isdigit() and type in ['1', '2', '-1']:breakelse:print("请输入有效的下载类型, 再进行下载选择!")song = songs[int(index)]filename = song[-2]filehash = song[-1]if type == '1':down(filehash)elif type == '2':get_comment(filename+'.txt', filehash)elif type == '-1':exit()next = input("请选择继续操作类型:\n【1】重新搜索\n【2】继续下载\n【-1】退出程序\n请输入:")if next == '1':keyword = input("请输入搜索歌曲名称:")songs = search(keyword)elif next == '2':continueelif next == '-1':exit()

转载于:https://www.cnblogs.com/TurboWay/p/10360987.html

【python3】酷狗音乐及评论回复下载相关推荐

  1. Python从网易云音乐、QQ 音乐、酷狗音乐等搜索和下载歌曲

    music-dl 从网易云音乐.QQ音乐.酷狗音乐.百度音乐.虾米音乐等搜索和下载歌曲. Search and download music from netease, qq, kugou, baid ...

  2. Python从网易云音乐、QQ 音乐、酷狗音乐等搜索和下载歌曲!

    music-dl 从网易云音乐.QQ音乐.酷狗音乐.百度音乐.虾米音乐等搜索和下载歌曲. Search and download music from netease, qq, kugou, baid ...

  3. python自动下载酷狗音乐_使用Python下载酷狗音乐

    使用Python+Selenium+Urllib下载酷狗歌曲 最近想下载一首歌,找了各大音乐平台,觉得在酷狗上下载更容易. 首先是获取原音频地址(本文以野狼disco为例),存储在标签里的src属性中 ...

  4. 移动音乐播放平台-酷狗音乐2021提供下载

    酷狗音乐2021安卓版是一款非常受欢迎的移动音乐播放平台.酷狗音乐2021app最新版采用先进的构架设计研发,设计了高传输效果的文件下载功能,实现数据分享传输.酷狗音乐2021app拥有新歌速递.权威 ...

  5. 青龙羊毛——酷狗音乐(教程)

    都说酷狗毛毛多,昨天发了大字版教程,今天整个酷狗音乐教程! 1.下载 应用商城(或百度)-- 酷狗音乐 2.脚本 自己去前面文章找,只更新教程了! 脚本获取--哈喽,酷狗! 3.抓包 老朋友了,小黄鸟 ...

  6. 网易云音乐怎么剪辑音乐并保存,酷狗音乐怎么截取一段音乐并保存

    我们在使用音乐软件播放音乐时,听到好听的歌曲会将其下载保存到本地.但是通过音乐软件下载的歌曲多是整首音乐,若是我们需要其中的一部分,就需要用到专业的音频编辑软件了,那么下面就来给大家介绍网易云音乐怎么 ...

  7. python爬取酷狗音乐json数据为空_【Python3爬虫】下载酷狗音乐上的歌曲

    经过测试,可以下载要付费下载的歌曲(n_n) 准备工作:python3.5+pycharm 使用到的库:requests,re,json 步骤: 打开酷狗音乐的官网,输入想要搜索的歌曲(例如<天 ...

  8. 【Python3爬虫】下载酷狗音乐上的歌曲

    经过测试,可以下载要付费下载的歌曲(n_n) 准备工作:Python3.5+Pycharm 使用到的库:requests,re,json,time,fakeuseragent 步骤: 打开酷狗音乐的官 ...

  9. python爬取酷狗音乐top500_python获取酷狗音乐top500的下载地址 MP3格式

    下面先给大家介绍下python获取酷狗音乐top500的下载地址 MP3格式,具体代码如下所示: # -*- coding: utf-8 -*- # @Time : 2018/4/16 # @File ...

最新文章

  1. 教程:4、文件权限和访问方式
  2. 数组,字符串,指针,内存分配机制
  3. hadoop : hdfs的心跳时间设置及心跳检测算法
  4. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载四(使用程序载入事件)...
  5. poj3061尺取法/前缀和 二分(java)
  6. ubuntu自动提醒
  7. 安全整数和 Number.isSafeInteger()
  8. cuda与tensorflow版本对应关系
  9. MySQL 高性能索引策略和查询优化
  10. 关于解决锐捷校园网客户端与vm虚拟机网络冲突问题的方法
  11. IMO FTPC Part 3-A、B和F级分隔耐火性能测试
  12. 撰写论文时如何复制参考文献公式----Mathpix及Mathtype教程
  13. 12个同父异母的孩子都有自闭症,简历造假的捐精者吸引了全球顶级专家
  14. java 前置零_程序员面试必考题(二十二):Java中的前置条件和后置条件
  15. mysql 设置 0、1 用什么数据类型_不断精炼核心知识点,终于能把MySQL讲懂了
  16. 刀具的磨损与破损、刀具寿命及刀具状态监控
  17. Leetcode解题(第974题)
  18. Axure Chart(Axure图表)库
  19. android调用系统指纹设置页面录入指纹
  20. TCP/IP协议族(第4版)

热门文章

  1. 魅族手机可安装鸿蒙操作系统吗,国产要抱团取暖?魅族、中兴、小米等手机可能适配华为鸿蒙系统...
  2. 终于【北京大学】也成立【人工智能研究院】!盘点近20所顶尖高校的AI布局!...
  3. oracle查看sql命中率,关于Oracle检查命中率的SQL
  4. 【物理应用】基于matlab车辆二自由度悬架鲁棒控制【含Matlab源码 2324期】
  5. 【云上论肠菌】9月29日下午2点,刘双江和王婷婷教授开讲!
  6. 小米崔宝秋:长线投入、持续努力,才能保证用户安全
  7. 无人驾驶-控制-纯跟踪
  8. 郑正中:中国商业智能的应用特点
  9. 基于滴滴云搭建 Lustre 分布式文件系统
  10. 文献3 基于改进型YOLOv3的SAR图像舰船目标检测