Lancc 发表于 2022-6-27 09:46

酷狗音乐下载器---.NET6+Furion

本帖最后由 Lancc 于 2022-7-6 11:43 编辑

2022-07-06 : V1.1版本应大家的要求,增加了批量下载和翻页功能.
kugoudownload-v1.1





https://static.52pojie.cn/static/image/hrline/line4.png

参照另外一个大佬的python做的.
酷狗音乐歌曲爬取
using Furion;
using Furion.ClayObject;
using Furion.DataEncryption;
using Furion.JsonSerialization;
using Furion.RemoteRequest.Extensions;
using Furion.Templates;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using StackExchange.Profiling.Data;
using System.Security.Cryptography.Xml;
using System.Text;


var services = Inject.Create();
// 注册服务
services.AddRemoteRequest();
services.Build();

var searchKeyWord = string.Empty;
int writeIndex = 0;


var versionInfo = TP.Wrapper("酷狗音乐下载器",
    "[作者] cc",
    "[时间] 2022-06-24"
    );
Console.WriteLine(versionInfo);



Console.WriteLine("输入关键词:");
searchKeyWord = Console.ReadLine();
string t = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds.ToString();
var headers = new Dictionary<string, object> {
      { "User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36" }
    };

string[] sign_params = {"NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt", "bitrate=0", "callback=callback123",
                     "clienttime=" + t, "clientver=2000", "dfid=-", "inputtype=0", "iscorrection=1",
                     "isfuzzy=0",
                     "keyword=" + searchKeyWord, "mid=" + t, "page=" + 1, "pagesize=30",
                     "platform=WebFilter", "privilege_filter=0", "srcappid=2919", "token=", "userid=0",
                     "uuid=" + t, "NVPh5oo715z5DIWAeQlhMDsWXXQV4hwt" };
varsign_paramStr = string.Join("", sign_params);
var signature= MD5Encryption.Encrypt(sign_paramStr);

var response =await "https://complexsearch.kugou.com/v2/search/song"
    .SetHeaders(headers)
    .SetQueries(new Dictionary<string, object> {
    {"callback","callback123"},
    {"page",1},
    {"keyword",searchKeyWord??""},
    {"pagesize","30"},
    {"bitrate","0"},
    {"isfuzzy","0"},
    {"inputtype","0"},
    {"platform","WebFilter"},
    {"userid","0"},
    {"clientver","2000"},
    {"iscorrection","1"},
    {"privilege_filter","0"},
    {"token",""},
    {"srcappid","2919"},
    {"clienttime",t},
    {"mid",t},
    {"uuid",t},
    {"dfid","-"},
    {"signature",signature}
}).GetAsStringAsync();

//返回值为JsonpCallback
var responseJson = response;

var clay = Clay.Parse(responseJson);

List<dynamic> singerlist = new List<dynamic>();
Console.WriteLine("序号   FileName");

int index = 0;
foreach (var item in clay.data.lists)
{
    index++;
    singerlist.Add(item);
    Console.WriteLine($"{index.ToString().PadLeft(2,'0')}{item.FileName}");
}

Console.WriteLine("请输入序号:");
string userInput= Console.ReadLine();
writeIndex = int.Parse(userInput);

var song_info = singerlist;

//获取文件下载路径
var responFileInfo = await "https://wwwapi.kugou.com/yy/index.php"
    .SetHeaders(headers)
    .SetQueries(new Dictionary<string, object>
    {
      {"r", "play/getdata" },
      {"callback", "jQuery191035601158181920933_1653052693184" },
      {"hash", song_info.FileHash },
      {"dfid", "2mSZvv2GejpK2VDsgh0K7U0O" },
      {"appid", "1014" },
      {"mid", "c18aeb062e34929c6e90e3af8f7e2512" },
      {"platid", "4" },
      {"album_id", song_info.AlbumID },
      {"_", "1653050047389" }
    }).GetAsStringAsync();

var responFileInfoJson = responFileInfo;
clay = Clay.Parse(responFileInfoJson);
string fileUrl = clay.data.play_url;

//下载文件
var bytes= await fileUrl.SetHeaders(headers).GetAsByteArrayAsync();

if (!Directory.Exists("./music"))
{
    Directory.CreateDirectory("./music");
}
Console.WriteLine($"{clay.data.audio_name} 下载中,请稍等....");
using (FileStream fs = new FileStream($"./music/{clay.data.audio_name}.mp3", FileMode.Create, FileAccess.Write))
{
    fs.Write(bytes, 0, bytes.Length);
}
Console.WriteLine("下载完成,按任意键退出.........");
Console.ReadKey();

.NET6是真好用,但是打包文件太大了,有能力的自己打包,或者移步码云酷狗音乐下载器

Lancc 发表于 2022-12-12 15:06

更新了一版,主要是改成。NET7的AOT发布,缩减了文件体积。

richie600 发表于 2022-12-12 20:55

Lancc 发表于 2022-12-12 15:06
更新了一版,主要是改成。NET7的AOT发布,缩减了文件体积。

非常感谢楼主用心制作分享一直在用v1.1.1 目前发现1.1.1 和1.2都有些歌曲不能下载(只是个别歌曲 尤其是刚发的新歌) v1.2 显示为以下提示 Object reference not set to an instance of an object.   v1.1.1则直接显示好几行提示 然后窗口就闪退了 希望楼主有时间的时候可以看下 截图如下

hanghangasde 发表于 2022-6-27 11:13

赞一个,下载看看

7115 发表于 2022-6-27 11:21

先看看再说吧

w4541682 发表于 2022-6-27 11:24

只能一首一首的下载吗??能不能直接全下啊

china08 发表于 2022-6-27 11:42

谢谢分享

Lancc 发表于 2022-6-27 11:47

w4541682 发表于 2022-6-27 11:24
只能一首一首的下载吗??能不能直接全下啊

原版的python就是全下载的.

ytdzjun 发表于 2022-6-27 11:59

感谢分享~登录后可以下载源码~

chentzz 发表于 2022-6-27 12:21

128 kb/s,音质一般

venusli168 发表于 2022-6-27 12:35

大牛啊,非常专业,值得收藏

gxjk5888 发表于 2022-6-27 13:03

谢谢楼主分享
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 酷狗音乐下载器---.NET6+Furion