Skip to content

Commit d58ca07

Browse files
author
jadepeng
committed
fix(download): fix migu and qq
1 parent 7bf619c commit d58ca07

File tree

5 files changed

+137
-42
lines changed

5 files changed

+137
-42
lines changed

XMusicDownloader/Form1.Designer.cs

Lines changed: 23 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

XMusicDownloader/Form1.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using XMusicDownloader.Domain;
1616
using XMusicDownloader.Http;
1717
using System.IO;
18+
using System.Runtime.InteropServices;
1819

1920
namespace XMusicDownloader
2021
{
@@ -27,12 +28,23 @@ public Form1()
2728
{
2829
InitializeComponent();
2930
}
31+
32+
33+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
34+
static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string pszPath);
35+
3036
string target = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Download\\";
37+
static readonly string configFile = "config.conf";
3138

3239
private void Form1_Load(object sender, EventArgs e)
3340
{
34-
textBox2.Text = target;
3541
this.cbRate.SelectedIndex = 2;
42+
if (File.Exists(configFile))
43+
{
44+
// TODO
45+
target = File.ReadAllText(configFile,Encoding.UTF8);
46+
}
47+
this.txtDownloadPath.Text = target;
3648
}
3749

3850
//浏览
@@ -41,8 +53,9 @@ private void pathBtn_Click(object sender, EventArgs e)
4153
FolderBrowserDialog ofd = new FolderBrowserDialog();
4254
if (ofd.ShowDialog() == DialogResult.OK)
4355
{
44-
textBox2.Text = ofd.SelectedPath + "\\";
45-
target = textBox2.Text;
56+
txtDownloadPath.Text = ofd.SelectedPath + "\\";
57+
target = txtDownloadPath.Text;
58+
File.WriteAllText(configFile, target, Encoding.UTF8);
4659
}
4760
}
4861

@@ -115,7 +128,7 @@ private void GetList(int page)
115128
List<ListViewItem> listViewItems = new List<ListViewItem>();
116129

117130

118-
var songs = tblSearch.SelectedIndex == 0 ? provider.SearchSongs(textBox1.Text, page, 20) : provider.SearchSongsList(txtSongListUrl.Text);
131+
var songs = tblSearch.SelectedIndex == 0 ? provider.SearchSongs(txtSearchBox.Text, page, 20) : provider.SearchSongsList(txtSongListUrl.Text);
119132

120133
songs.ForEach(item =>
121134
{
@@ -281,5 +294,17 @@ private void cbSelectAll_CheckedChanged(object sender, EventArgs e)
281294
item.Checked = cbSelectAll.Checked;
282295
}
283296
}
297+
298+
private void textBox1_KeyDown(object sender, KeyEventArgs e)
299+
{
300+
if(e.KeyCode == Keys.Enter){
301+
searchBtn_Click(this, e);
302+
}
303+
}
304+
305+
private void txtSearchBox_TextChanged(object sender, EventArgs e)
306+
{
307+
308+
}
284309
}
285310
}

XMusicDownloader/Provider/MiguProvider.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,28 @@ public class MiguProvider : IMusicProvider
1414
{
1515
static HttpConfig DEFAULT_CONFIG = new HttpConfig
1616
{
17-
Referer = "http://m.music.migu.cn/",
18-
17+
Referer = "http://music.migu.cn/",
18+
UserAgent= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"
1919
};
2020

2121
public string Name { get; } = "咪咕";
2222

23+
public static string UrlEncode(string str)
24+
{
25+
StringBuilder sb = new StringBuilder();
26+
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
27+
for (int i = 0; i < byStr.Length; i++)
28+
{
29+
sb.Append(@"%" + Convert.ToString(byStr[i], 16));
30+
}
31+
32+
return sb.ToString().ToUpper();
33+
}
2334

2435
public List<Song> SearchSongs(string keyword, int page, int pageSize)
2536
{
26-
var searchResult = HttpHelper.GET(string.Format("http://m.music.migu.cn/migu/remoting/scr_search_tag?keyword={0}&pgc={1}&rows={2}&type=2", keyword, page, pageSize), DEFAULT_CONFIG);
37+
string searchUrl = string.Format("https://m.music.migu.cn/migu/remoting/scr_search_tag?keyword={0}&pgc={1}&rows={2}&type=2", UrlEncode(keyword), page, pageSize);
38+
var searchResult = HttpHelper.GET(searchUrl, DEFAULT_CONFIG);
2739
var result = new List<Song>();
2840
try
2941
{

XMusicDownloader/Provider/QQProvider.cs

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,7 @@ public List<Song> SearchSongs(string keyword, int page, int pageSize)
5757

5858
public string getDownloadUrl(Song song)
5959
{
60-
var guid = new Random().Next(1000000000, 2000000000);
61-
62-
var key = JsonParser.Deserialize(HttpHelper.GET(string.Format("http://base.music.qq.com/fcgi-bin/fcg_musicexpress.fcg?guid={0}&format=json&json=3", guid), DEFAULT_CONFIG)).key;
63-
foreach (var prefix in prefixes)
64-
{
65-
66-
var musicUrl = string.Format("http://dl.stream.qqmusic.qq.com/{0}{1}.mp3?vkey={2}&guid={3}&fromtag=1", prefix, song.id, key, guid);
67-
if (HttpHelper.GetUrlContentLength(musicUrl) > 0)
68-
{
69-
return musicUrl;
70-
}
71-
}
72-
73-
return null;
60+
return getMusicUrl(song.id,"320");
7461

7562
}
7663

@@ -248,5 +235,74 @@ public string getDownloadUrl(string id, string rate)
248235
{
249236
return HttpHelper.DetectLocationUrl("https://v1.itooi.cn/tencent/url?id=" + id + "&quality=" + rate, DEFAULT_CONFIG);
250237
}
238+
239+
private string GetOggVkey(string songmid)
240+
{
241+
string param = "{\"comm\":{\"ct\":\"19\",\"cv\":\"1724\",\"patch\":\"118\",\"uin\":\"0\",\"wid\":\"0\"},\"queryvkey\":{\"method\":\"CgiGetEVkey\",\"module\":\"vkey.GetEVkeyServer\",\"param\":{\"checklimit\":0,\"ctx\":1,\"downloadfrom\":0,\"filename\":[\"O6M0003uw9dp2HcDl2.mgg\",\"O6M0"+ songmid+".mgg\"],\"guid\":\"CD2594E1E7AD35046B95E7E1482E074B\",\"musicfile\":[\"O6M0003uw9dp2HcDl2.mgg\",\"O6M0"+ songmid+".mgg\"],\"nettype\":\"\",\"referer\":\"y.qq.com\",\"scene\":0,\"songmid\":[\"003uw9dp2HcDl2\",\""+ songmid+"\"],\"songtype\":[1,1],\"uin\":\"1719982754\"}}}";
242+
string result = HttpHelper.POST("https://u.y.qq.com/cgi-bin/musicu.fcg", param, DEFAULT_CONFIG);
243+
return (string)JObject.Parse(result)["queryvkey"]["data"]["midurlinfo"][1]["purl"];
244+
}
245+
246+
double getGuid()
247+
{
248+
return new Random().Next(1000000000, 2000000000);
249+
}
250+
251+
string getPurl(string songmid)
252+
{
253+
string paramStr = "{\"req\":{\"module\":\"CDN.SrfCdnDispatchServer\",\"method\":\"GetCdnDispatch\",\"param\":{\"guid\":\""+ getGuid()+"\",\"calltype\":0,\"userip\":\"\"}},\"req_0\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\""+ getGuid()+"\",\"songmid\":[\""+songmid+"\"],\"songtype\":[0],\"uin\":\"2461958018\",\"loginflag\":1,\"platform\":\"20\"}},\"comm\":{\"uin\":2461958018,\"format\":\"json\",\"ct\":24,\"cv\":0}}";
254+
string url = "https://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=5381&format=json&inCharset=utf8&outCharset=utf-8&data=" + paramStr;
255+
var response = HttpHelper.GET(url, DEFAULT_CONFIG);
256+
257+
JObject result = JObject.Parse(response);
258+
string vkey = (string)result["req_0"]["data"]["midurlinfo"][0]["purl"];
259+
if(vkey.Length == 0)
260+
{
261+
return null;
262+
}
263+
264+
return (string)result["req_0"]["data"]["sip"][0] + vkey;
265+
}
266+
267+
public string getMusicUrl(string songmid, string size)
268+
{
269+
270+
return getPurl(songmid);
271+
272+
//string vkey = GetOggVkey(songmid);
273+
274+
//if(vkey.Length == 0)
275+
//{
276+
// size = "128";
277+
//}
278+
279+
280+
//string[] prefix = {
281+
//"http://124.89.197.14/amobile.music.tc.qq.com/",
282+
//"http://124.89.197.15/amobile.music.tc.qq.com/",
283+
//"http://isure.stream.qqmusic.qq.com/",
284+
//"http://ws.stream.qqmusic.qq.com/",
285+
//"http://183.240.120.28/amobile.music.tc.qq.com"
286+
//};
287+
288+
//// 选择不同音质
289+
//switch (size)
290+
//{
291+
// case "flac":
292+
// return string.Format("{0}F000{1}.flac?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=53", prefix[1], songmid, vkey);
293+
// case "ape":
294+
// return string.Format("{0}A000{1}.ape?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=8", prefix[1], songmid, vkey);
295+
// case "320":
296+
// return string.Format("{0}M800{1}.mp3?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=30", prefix[1], songmid, vkey);
297+
// case "mgg":
298+
// return string.Format("{0}O6M0{1}.mgg?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=77", prefix[1], songmid, vkey);
299+
// case "128":
300+
// {
301+
302+
// }
303+
// default:
304+
// return string.Format("{0}{1}", prefix[3], getPurl(songmid));
305+
//}
306+
}
251307
}
252308
}
6 KB
Binary file not shown.

0 commit comments

Comments
 (0)