go 下载qq音乐
//go下载qq音乐
package main import (
_ "fmt"
jsoniter "github.com/json-iterator/go"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
) //练习json解析
//var jsonStr = `{
//"code":0,
//"data":{
//"keyword":"桥边娘",
//"priority":0,
//"qc":[{"text":"桥边姑娘","type":1}],"semantic":{"curnum":0,"curpage":1,"list":[],"totalnum":0},
//"song":{
//"curnum":2,
//"curpage":1,
//"list":[
//{"action":{"alert":2,"icons":8527740,"msg":14,"switch":17413891},
//"album":{"id":9160555,"mid":"0037Yq3H3RznaX","name":"桥边姑娘","pmid":"0037Yq3H3RznaX_1","subtitle":"","title":"桥边姑娘","title_hilight":"<em>桥边姑娘</em>"},"chinesesinger":0,"desc":"","desc_hilight":"","docid":"126909805796459913","file":{"b_30s":0,"e_30s":60000,"media_mid":"001zLvbN1NYMuv","size_128":2931359,"size_128mp3":2931359,"size_320":7328081,"size_320mp3":7328081,"size_aac":4442882,"size_ape":0,"size_dts":0,"size_flac":20665526,"size_ogg":4495348,"size_try":960887,"strMediaMid":"001zLvbN1NYMuv","try_begin":56459,"try_end":84621},"fnote":4009,"genre":0,"grp":[],"id":244625442,"index_album":1,"index_cd":0,"interval":183,"isonly":1,"ksong":{"id":6374470,"mid":"002Rn3IH1mlv0E"},"language":0,"lyric":"","lyric_hilight":"","mid":"001zLvbN1NYMuv","mv":{"id":0,"vid":""},"name":"桥边姑娘","newStatus":1,"nt":87800508,"pay":{"pay_down":1,"pay_month":1,"pay_play":0,"pay_status":0,"price_album":0,"price_track":200,"time_free":0},"pure":0,
//"singer":[{"id":1294564,"mid":"0041vdG63lbLge","name":"海伦","title":"海伦","title_hilight":"海伦","type":0,"uin":0}],
//"status":0,"subtitle":"","t":1,"tag":11,"time_public":"2019-11-09",
//"title":"桥边姑娘",
//"title_hilight":"<em>桥边姑娘</em>",
//"type":0,
//"url":"http://stream10.qqmusic.qq.com/244625442.wma","ver":0,
//"volume":{"gain":-7.768000125885010,"lra":9.609000205993652,"peak":0.9330000281333923}},
//{"action":{"alert":11,"icons":135752,"msg":0,"switch":77587},
//"album":{"id":0,"mid":"","name":"","pmid":"","subtitle":"","title":"","title_hilight":""},
//"chinesesinger":0,"desc":"","desc_hilight":"","docid":"8751829731153775463",
//"file":
//{"b_30s":0,"e_30s":0,"media_mid":"001fkaP431i0UO","size_128":2956833,"size_128mp3":2956833,"size_320":7391798,"size_320mp3":7391798,"size_aac":4415052,"size_ape":0,"size_dts":0,"size_flac":0,"size_ogg":3851434,"size_try":0,"strMediaMid":"001fkaP431i0UO","try_begin":0,"try_end":0},
//"fnote":8013,"genre":0,"grp":[],"id":127400312,"index_album":0,"index_cd":0,"interval":184,"isonly":0,
//"ksong":{"id":0,"mid":""},
//"language":0,"lyric":"","lyric_hilight":"",
//"mid":"002rI3Yb1nZjPy",
//"mv":{"id":0,"vid":""},
//"name":"桥边姑娘","newStatus":1,"nt":1324451929,"pay":{"pay_down":0,"pay_month":0,"pay_play":0,"pay_status":0,"price_album":0,"price_track":0,"time_free":0},"pure":0,
//"singer":[{"id":3209257,"mid":"001a520s0HBgIS","name":"张茜","title":"张茜","title_hilight":"张茜","type":1,"uin":0}],"status":0,"subtitle":"","t":1,"tag":0,"time_public":"","title":"桥边姑娘","title_hilight":"<em>桥边姑娘</em>","type":0,"url":"http://stream10.qqmusic.qq.com/127400312.wma","ver":0,
//"volume":{"gain":0.0,"lra":0.0,"peak":0.0}}],"totalnum":600},"tab":0,"taglist":[],"totaltime":0,"zhida":{"type":null}},
//"message":"",
//"notice":"",
//"subcode":0,
//"time":1578533969,
//"tips":""
//}` type Datas struct {
Code int `json:"code"`
Message string `json:"message"`
Time int `json:"time"`
Data Data `json:"data"`
}
type Data struct {
Keyword string `json:"keyword"`
Song Song `json:"song"`
} type Song struct {
Curnum int `json:"curnum"`
List []List `json:"list"`
} type List struct {
Title string `json:"title"`
TimePublic string `json:"time_public"`
Mid string `json:"mid"`
Name string `json:"name"`
ID int `json:"id"`
File File `json:"file"`
Album Album `json:"album"`
Singer []Singer `json:"singer"`
} type Singer struct {
Name string `json:"name"`
} type File struct {
StrMediaMid string `json:"strMediaMid"`
} type Album struct {
Name string `json:"name"`
} type Lyric struct {
UserIp string `json:"userip"`
Data LyData `json:"data"`
}
type LyData struct {
Expiration int `json:"expiration"`
Items []Item `json:"items"`
}
type Item struct {
Vkey string `json:"vkey"`
} /**
下载QQ音乐
@param string keyword 歌曲名称关键词
@param int num 需要下载的歌曲数量
*/
func download(keyword string, num int) {
pathPwd, _ := os.Getwd()
url := "https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song" +
"&searchid=57124856116396257&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&" +
"n=" + strconv.Itoa(num) + "&w=" + keyword + "&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0"
resp, err := http.Get(url)
if err != nil {
println("get出错", err)
return
} defer resp.Body.Close()
jsonstr, err := ioutil.ReadAll(resp.Body)
if err != nil {
println(err)
return
}
jsonStr := jsonstr
strMediaMids := []string{}
songmids := []string{}
songnames := []string{}
singers := []string{}
albumns := []string{}
songid := []int{}
data := Datas{}
var json2 = jsoniter.ConfigCompatibleWithStandardLibrary
_ = json2.Unmarshal([]byte(jsonStr), &data)
//fmt.Println(data.Data.Song.List)
for _, v := range data.Data.Song.List {
strMediaMids = append(strMediaMids, v.File.StrMediaMid)
songmids = append(songmids, v.Mid)
songnames = append(songnames, v.Name)
singers = append(singers, v.Singer[0].Name)
albumns = append(albumns, v.Album.Name)
songid = append(songid, v.ID)
} for k, v := range strMediaMids {
//将strMediaMids和songmids重新组合到url中
url2 := "https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg?&jsonpCallback=MusicJsonCallback&format=json&cid=205361747&songmid=" + songmids[k] + "&filename=C400" + v + ".m4a&guid=6612300644"
println(url2)
resp, err := http.Get(url2)
if err != nil {
println("get出错", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
println("出错了", err)
return
}
var filter = Lyric{}
json2.Unmarshal([]byte(body), &filter)
vkey := filter.Data.Items[0].Vkey
//这是最终的歌曲url
song_url := "http://dl.stream.qqmusic.qq.com/C400" + v + ".m4a?vkey=" + vkey + "&guid=6612300644&uin=0&fromtag=66"
//歌词url
lyric_url := "https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric.fcg?nobase64=1&musicid=" + strconv.Itoa(songid[k]) + "&callback=jsonp1&g_tk=5381&jsonpCallback=json&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq&needNewCode=0"
client := &http.Client{}
refer := "https://y.qq.com/n/yqq/song/" + songmids[k] + ".html"
request, err := http.NewRequest("GET", lyric_url, nil)
request.Header.Add("Referer", refer)
request.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
response, err := client.Do(request)
defer response.Body.Close()
if err != nil {
return
}
body2, err := ioutil.ReadAll(response.Body)
if err != nil {
println("出错了", err)
return
}
println(string(body2))
println("正在下载--->" + songnames[k])
res, err := http.Get(song_url)
if err != nil {
panic(err)
}
//f, err := os.Create(pathPwd + "/" + songnames[k] + strconv.Itoa(k+1) + ".mp3")
f, err := os.Create(pathPwd + "/" + songnames[k] + ".mp3")
if err != nil {
panic(err)
}
io.Copy(f, res.Body)
println("下载第" + strconv.Itoa(k+1) + "首<" + songnames[k] + ">已经保存成功嘿嘿嘿~~~") }
} func main() {
//传参形式
//if len(os.Args) <= 1 {
// fmt.Println("请输入需要下载的音乐名称.")
// return
//}
//fmt.Println("音乐名称 ", os.Args[1])
//num := os.Args[2]
//println(num)
//todo:可以加入协程来耍耍
download("冯提莫", 3)
}
go版本下载qq音乐 略有粗糙 见谅 见谅
go 下载qq音乐的更多相关文章
- 亲测可用!免费下载QQ音乐大部分资源!
优化后亲测可用!免费下载QQ音乐大部分资源 通知 时间问题 博客园这边暂时停更要下载的去GitHub或者90盘 GitHub项目地址 https://github.com/TotoWang-hhh/m ...
- Python 应用爬虫下载QQ音乐
Python应用爬虫下载QQ音乐 目录: 1.简介怎样实现下载QQ音乐的过程: 2.代码 1.下载QQ音乐的过程 首先我们先来到QQ音乐的官网: https://y.qq.com/,在搜索栏上输入一首 ...
- 爬虫下载QQ音乐:获取所有歌手-每个歌手的专辑-每个专辑里的歌曲
# coding=utf-8 # !/usr/bin/env python ''' author: dangxusheng desc : 稍微有点难度,需要多次请求获取key date : 2018- ...
- JY播放器【QQ音乐破解下载】
今天给大家带来一款神器----JY播放器.可以直接下载QQ音乐的歌曲. 目前已经支持平台(蜻蜓FM.喜马拉雅FM.网易云音乐.QQ音乐) 使用方法: 在网页打开QQ音乐网站找到你要听的歌曲或歌单.复制 ...
- Deepin-安装QQ音乐(Windows程序)
打开命令行,输入: sudo apt-get install wine 安装完成后,下载QQ音乐的安装包 然后安装 示例:wine xx.exe 实例:wine QQMusic.exe 安装完成,启动 ...
- python3 爬取qq音乐作者所有单曲 并且下载歌曲
1 import requests import re import json import os # 便于存放作者的姓名 zuozhe = [] headers = {'User-Agent': ' ...
- QQ音乐MP3下载
QQ音乐MP3下载 没错本次写的内容的对象是我们熟知的QQ Music. 本篇文章涉及内容包括:Python,爬虫,json解析,request 库的使用 缘起 前几天刷B站无意中又刷到了一首神曲,“ ...
- 转发一个关于下载qq无损音乐的博客
import requests import json headers = { 'Host': 'c.y.qq.com', 'Referer': 'http://c.y.qq.com/', 'User ...
- Python Scrapy的QQ音乐爬虫 音乐下载、爬取歌曲信息、歌词、精彩评论
QQ音乐爬虫(with scrapy)/QQ Music Spider UPDATE 2019.12.23 已实现对QQ音乐文件的下载,出于版权考虑,不对此部分代码进行公开.此项目仅作为学习交流使用, ...
随机推荐
- id NSObject instanceType 区别
id 当不确定数组元素类型时,可以选择使用id NSObject和id都可以指向任何对象 NSObject使用时必须强转 instantceType 只能返回和方法所在类相同类型的对象 返回值类 ...
- UFT检查点
一.标准检查点 选择需要插入检查点的语句,点击右键,选择Insert Standard Checkpoint.... 二.图像检查点(Insert Standard Checkpoint....) 在 ...
- 关于安装python第三方库
安装python库的两种方式: 一)在线安装: 1)pip install 模块名 2)使用国内源安装:pip install 国内源地址 模块名 3)pycharm中setting-interpre ...
- vue项目实例-常用标签
感谢:https://www.jianshu.com/p/5d9b341d650f 总结: 1.<router-link to=''>主要实现跳转链接功能,属性to='/'即是跳转到pat ...
- idea 内存溢出解决方法
在Run/Debug configuration 的 vm options里面输入 -server -XX:PermSize=128M -XX:MaxPermSize=256m 具体如下图:
- toString()和强制类型转换(String)的用法
原来是String类型的才可以强转到String,不然会报 ClassCastException异常: 所有的引用类型都从Object类继承了toString方法.
- python 内置方法、数据序列化
abc(*args, **kwargs) 取绝对值 def add(a,b,f): return f(a)+f(b) res = add(3,-6,abs) print(res) all(*args, ...
- react动态添加多个输入框
let obj = {} result.forEach(item =>{ obj[item.eleId] = item }) setFieldsValue(obj)
- 算法设计与分析-Week12
题目描述 You are given coins of different denominations and a total amount of money amount. Write a func ...
- ubuntu 16 下安装 Ubuntu Make
第一步:下载安装包 地址:http://ftp.gnu.org/gnu/make/ 第二步:解压 先进入存放文件目录,图示: 进行解压,图示: 解压并copy到安装目录 第三步:编译 1.查看目录, ...