Skip to content

Commit

Permalink
fix(download): fix migu and qq
Browse files Browse the repository at this point in the history
  • Loading branch information
jadepeng committed Aug 17, 2020
1 parent 7bf619c commit d58ca07
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 42 deletions.
44 changes: 23 additions & 21 deletions XMusicDownloader/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 29 additions & 4 deletions XMusicDownloader/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using XMusicDownloader.Domain;
using XMusicDownloader.Http;
using System.IO;
using System.Runtime.InteropServices;

namespace XMusicDownloader
{
Expand All @@ -27,12 +28,23 @@ public Form1()
{
InitializeComponent();
}


[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, IntPtr hToken, out string pszPath);

string target = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Download\\";
static readonly string configFile = "config.conf";

private void Form1_Load(object sender, EventArgs e)
{
textBox2.Text = target;
this.cbRate.SelectedIndex = 2;
if (File.Exists(configFile))
{
// TODO
target = File.ReadAllText(configFile,Encoding.UTF8);
}
this.txtDownloadPath.Text = target;
}

//浏览
Expand All @@ -41,8 +53,9 @@ private void pathBtn_Click(object sender, EventArgs e)
FolderBrowserDialog ofd = new FolderBrowserDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
textBox2.Text = ofd.SelectedPath + "\\";
target = textBox2.Text;
txtDownloadPath.Text = ofd.SelectedPath + "\\";
target = txtDownloadPath.Text;
File.WriteAllText(configFile, target, Encoding.UTF8);
}
}

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


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

songs.ForEach(item =>
{
Expand Down Expand Up @@ -281,5 +294,17 @@ private void cbSelectAll_CheckedChanged(object sender, EventArgs e)
item.Checked = cbSelectAll.Checked;
}
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter){
searchBtn_Click(this, e);
}
}

private void txtSearchBox_TextChanged(object sender, EventArgs e)
{

}
}
}
18 changes: 15 additions & 3 deletions XMusicDownloader/Provider/MiguProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ public class MiguProvider : IMusicProvider
{
static HttpConfig DEFAULT_CONFIG = new HttpConfig
{
Referer = "http://m.music.migu.cn/",

Referer = "http://music.migu.cn/",
UserAgent= "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"
};

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

public static string UrlEncode(string str)
{
StringBuilder sb = new StringBuilder();
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
for (int i = 0; i < byStr.Length; i++)
{
sb.Append(@"%" + Convert.ToString(byStr[i], 16));
}

return sb.ToString().ToUpper();
}

public List<Song> SearchSongs(string keyword, int page, int pageSize)
{
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);
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);
var searchResult = HttpHelper.GET(searchUrl, DEFAULT_CONFIG);
var result = new List<Song>();
try
{
Expand Down
84 changes: 70 additions & 14 deletions XMusicDownloader/Provider/QQProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,7 @@ public List<Song> SearchSongs(string keyword, int page, int pageSize)

public string getDownloadUrl(Song song)
{
var guid = new Random().Next(1000000000, 2000000000);

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;
foreach (var prefix in prefixes)
{

var musicUrl = string.Format("http://dl.stream.qqmusic.qq.com/{0}{1}.mp3?vkey={2}&guid={3}&fromtag=1", prefix, song.id, key, guid);
if (HttpHelper.GetUrlContentLength(musicUrl) > 0)
{
return musicUrl;
}
}

return null;
return getMusicUrl(song.id,"320");

}

Expand Down Expand Up @@ -248,5 +235,74 @@ public string getDownloadUrl(string id, string rate)
{
return HttpHelper.DetectLocationUrl("https://v1.itooi.cn/tencent/url?id=" + id + "&quality=" + rate, DEFAULT_CONFIG);
}

private string GetOggVkey(string songmid)
{
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\"}}}";
string result = HttpHelper.POST("https://u.y.qq.com/cgi-bin/musicu.fcg", param, DEFAULT_CONFIG);
return (string)JObject.Parse(result)["queryvkey"]["data"]["midurlinfo"][1]["purl"];
}

double getGuid()
{
return new Random().Next(1000000000, 2000000000);
}

string getPurl(string songmid)
{
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}}";
string url = "https://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=5381&format=json&inCharset=utf8&outCharset=utf-8&data=" + paramStr;
var response = HttpHelper.GET(url, DEFAULT_CONFIG);

JObject result = JObject.Parse(response);
string vkey = (string)result["req_0"]["data"]["midurlinfo"][0]["purl"];
if(vkey.Length == 0)
{
return null;
}

return (string)result["req_0"]["data"]["sip"][0] + vkey;
}

public string getMusicUrl(string songmid, string size)
{

return getPurl(songmid);

//string vkey = GetOggVkey(songmid);

//if(vkey.Length == 0)
//{
// size = "128";
//}


//string[] prefix = {
//"http://124.89.197.14/amobile.music.tc.qq.com/",
//"http://124.89.197.15/amobile.music.tc.qq.com/",
//"http://isure.stream.qqmusic.qq.com/",
//"http://ws.stream.qqmusic.qq.com/",
//"http://183.240.120.28/amobile.music.tc.qq.com"
//};

//// 选择不同音质
//switch (size)
//{
// case "flac":
// return string.Format("{0}F000{1}.flac?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=53", prefix[1], songmid, vkey);
// case "ape":
// return string.Format("{0}A000{1}.ape?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=8", prefix[1], songmid, vkey);
// case "320":
// return string.Format("{0}M800{1}.mp3?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=30", prefix[1], songmid, vkey);
// case "mgg":
// return string.Format("{0}O6M0{1}.mgg?guid=CD2594E1E7AD35046B95E7E1482E074B&vkey={2}&uin=0&fromtag=77", prefix[1], songmid, vkey);
// case "128":
// {

// }
// default:
// return string.Format("{0}{1}", prefix[3], getPurl(songmid));
//}
}
}
}
Binary file modified XMusicDownloader/bin/Release/XMusicDownloader.exe
Binary file not shown.

0 comments on commit d58ca07

Please sign in to comment.