Skip to content

Commit 4e3f3ab

Browse files
author
jadepeng
committed
2 parents 9a98a39 + db035bf commit 4e3f3ab

File tree

1 file changed

+173
-6
lines changed

1 file changed

+173
-6
lines changed

README.md

Lines changed: 173 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,179 @@
22

33
XMusicDownloader,一款 支持从百度、网易、qq和酷狗等音乐网站搜索并下载歌曲的程序。
44

5-
## 更新说明
6-
- 2019.8 V1.1.0 发布,支持歌单、专辑、歌手歌曲下载,支持无损下载
7-
+ 支持歌单、专辑、歌手歌曲下载(腾讯、网易)
8-
+ 支持flac无损、320,128 码率下载
9-
+ 截图
10-
![预览](./v1.1.png)
5+
开源音乐下载神器XMusicDownloader更新啦,新增网易、腾讯音乐歌单歌曲、歌手歌曲、专辑歌曲一键下载,同时支持下载flac无损音乐。
6+
7+
## 功能
8+
9+
V1.0 功能[开源工具软件XMusicDownloader——音乐下载神器](https://www.cnblogs.com/xiaoqi/p/xmusicdownloader.html)
10+
* 聚合搜索多家音乐网站
11+
* 支持音乐批量下载
12+
* 搜索结果综合排序
13+
* 可以编写Provider程序,支持其他音乐网站
14+
15+
V1.1 新增功能支持歌单、专辑、歌手歌曲下载,支持无损下载
16+
+ 支持歌单、专辑、歌手歌曲下载(腾讯、网易)
17+
+ 支持flac无损、320,128 码率下载
18+
19+
![V1.1截图](https://github.com/jadepeng/XMusicDownloader/raw/master/v1.1.png)
20+
21+
22+
## 扩展功能说明
23+
24+
主要是调用了一个[[第三方接口](https://www.bzqll.com/2019/04/318.html) 实现歌单、歌手和专辑歌曲读取,以及获取真实下载地址。
25+
26+
### 扩展provider接口,增加获取歌曲列表接口
27+
28+
增加Support接口判断url地址是否是歌单地址,增加GetSongList用于获取歌单的歌曲列表,增加getDownloadUrl(string id, string rate)获取歌曲下载地址。
29+
30+
```
31+
public interface IMusicProvider
32+
{
33+
string Name { get; }
34+
35+
string getDownloadUrl(Song song);
36+
List<Song> SearchSongs(string keyword, int page, int pageSize);
37+
38+
// 歌单
39+
bool Support(string url);
40+
List<Song> GetSongList(string url);
41+
/// <summary>
42+
/// 获取下载地址
43+
/// </summary>
44+
/// <param name="id">歌曲id</param>
45+
/// <param name="rate">码率,音质 如果最大音质获取出错则自动转其他音质 </param>
46+
/// <returns>歌曲下载地址</returns>
47+
string getDownloadUrl(string id, string rate);
48+
}
49+
```
50+
51+
### 实现provider
52+
53+
以QQ为例:
54+
55+
先判断是否是支持的url,主要是判断是否符合歌单、专辑、歌手的url格式。
56+
57+
```
58+
// 歌单: https://y.qq.com/n/yqq/playsquare/6924336223.html#stat=y_new.playlist.dissname
59+
// 专辑 https://y.qq.com/n/yqq/album/00153q8l2vldMz.html
60+
// 歌手 https://y.qq.com/n/yqq/singer/000CK5xN3yZDJt.html
61+
62+
Regex regex = new Regex("\\/(\\w+).html");
63+
public bool Support(string url)
64+
{
65+
if (url == null)
66+
{
67+
return false;
68+
}
69+
70+
if (!regex.IsMatch(url))
71+
{
72+
return false;
73+
}
74+
75+
return url.StartsWith("https://y.qq.com/n/yqq/playsquare") || url.StartsWith("https://y.qq.com/n/yqq/album") || url.StartsWith("https://y.qq.com/n/yqq/singer");
76+
}
77+
78+
```
79+
80+
然后调用itooi.cn的api获取歌曲
81+
82+
- 歌单接口 `https://v1.itooi.cn/tencent/songList?id=`
83+
- 歌手歌曲接口 `https://v1.itooi.cn/tencent/song/artist?id=`
84+
- 专辑歌曲接口 `https://v1.itooi.cn/tencent/album?id=`
85+
86+
```
87+
public List<Song> GetSongList(string url)
88+
{
89+
var isSongList = url.StartsWith("https://y.qq.com/n/yqq/playsquare");
90+
91+
var id = regex.Match(url).Groups[1].Value;
92+
93+
var result = new List<Song>();
94+
95+
if (isSongList)
96+
{
97+
GetSongListDetail(id, result);
98+
}
99+
else if (url.StartsWith("https://y.qq.com/n/yqq/albu"))
100+
{
101+
GetAlbum(id, result);
102+
}
103+
else
104+
{
105+
GetSingerSong(id, result);
106+
}
107+
108+
109+
return result;
110+
111+
}
112+
113+
private void GetSongListDetail(string id, List<Song> result)
114+
{
115+
var requestUrl = "https://v1.itooi.cn/tencent/songList?id=" + id;
116+
var searchResult = HttpHelper.GET(requestUrl, DEFAULT_CONFIG);
117+
118+
var songList = JObject.Parse(searchResult)["data"][0]["songlist"];
119+
var index = 1;
120+
121+
foreach (var songItem in songList)
122+
{
123+
var song = new Song
124+
{
125+
id = (string)songItem["songmid"],
126+
name = (string)songItem["title"],
127+
album = (string)songItem["album"]["name"],
128+
rate = 320,
129+
index = index++,
130+
size = (double)songItem["file"]["size_320mp3"],
131+
source = Name,
132+
//singer = (string)songItem["author"],
133+
duration = (double)songItem["interval"]
134+
};
135+
if (song.size == 0d)
136+
{
137+
song.size = (double)songItem["file"]["size_128mp3"];
138+
song.rate = 128;
139+
}
140+
song.singer = "";
141+
foreach (var ar in songItem["singer"])
142+
{
143+
song.singer += ar["name"] + " ";
144+
}
145+
result.Add(song);
146+
147+
}
148+
}
149+
```
150+
151+
最后获取下载地址,接口地址是`https://v1.itooi.cn/tencent/url?id=${id}&quality=[128,320,flac]`
152+
153+
```
154+
public string getDownloadUrl(string id, string rate)
155+
{
156+
return HttpHelper.DetectLocationUrl("https://v1.itooi.cn/tencent/url?id=" + id + "&quality=" + rate, DEFAULT_CONFIG);
157+
}
158+
```
159+
160+
这里要检测下真实url,递归检测302跳转:
161+
162+
```
163+
public static string DetectLocationUrl(string url, HttpConfig config)
164+
{
165+
if (config == null) config = new HttpConfig();
166+
using (HttpWebResponse response = GetResponse(url, "GET", null, config))
167+
{
168+
string detectUrl = response.GetResponseHeader("Location");
169+
if(detectUrl.Length == 0)
170+
{
171+
return url;
172+
}
173+
// 递归获取
174+
return DetectLocationUrl(detectUrl, config);
175+
}
176+
}
177+
```
11178

12179

13180

0 commit comments

Comments
 (0)