[c#]喜马拉雅、蜻蜓、荔枝FM音频批量下载器V1.3 by Levme开发手记

0.前言

好久没在CSDN上写东西了,看了之前开发的下载器由于三个网站代码更新已经不能用了,应要求,重分析了三个网站播放机制,写了1.3版本的下载器,在我的资源里有下载。
贴个地址:https://download.csdn.net/download/mnikkqqw/10675530

[c#]喜马拉雅、蜻蜓、荔枝FM音频批量下载器V1.3 by Levme开发手记_第1张图片

1.代码更新

这次代码更新,引入了Newtonsoft.Json.dll解析json文件,以前那个是自己写的解析器,太麻烦,用别人现成的就行。核心业务代码基本没有变动,只是更新了分析网站资源的代码,解决了一下之前列表栏滚动条不可用的问题,工具还是有很多问题的,不影响使用没改。
分析和添加喜马拉雅音频的代码:

if (ResourceBox.Lines[i].IndexOf("ximalaya") > -1)  //处理喜马拉雅FM下载地址
{
    try
    {
        string url = ResourceBox.Lines[i];
        string html = CommonMethds.GetHttpWebRequest(url);
        if (html == "网络状况不佳!")
             html = CommonMethds.GetWebClient(url);
        Regex reg = new Regex(@"\->[1-9]\d*\", "").Replace("

分析和添加蜻蜓音频的代码:

else if (ResourceBox.Lines[i].IndexOf("qingting") > -1)  //处理蜻蜓FM下载地址
{
    try
    {
        string url = ResourceBox.Lines[i];
        string html = CommonMethds.GetHttpWebRequest(url);
        if (html == "网络状况不佳!")
              html = CommonMethds.GetWebClient(url);
        Regex reg = new Regex(@"\->[1-9]\d*\<!", RegexOptions.Multiline | RegexOptions.IgnoreCase);
        Match mc = reg.Match(html);
        string temp = mc.Groups["span"].Value.Trim();
        temp = temp.Replace("->", "").Replace("<!", "");
        int ResoucesCount = int.Parse(temp);
        int pageCount = ResoucesCount / 10 + 1;
        for (int k = 1; k <= pageCount; k++)
        {
            string tempUrl = url.Replace("http://www.qingting.fm", "http://i.qingting.fm/wapi") + "/programs/page/" + k + "/pagesize/10";
            string JsonSources = CommonMethds.GetHttpWebRequest(tempUrl);
            JObject jobj = (JObject)JsonConvert.DeserializeObject(JsonSources);
            string data = jobj["data"].ToString();
            JArray soundInfos = (JArray)JsonConvert.DeserializeObject(data);
            int count = soundInfos.Count;
            for (int j = 0; j < count; j++)
            {
				//防止datagridview假死导致滚动条不可用
				Invoke(new Action(delegate
				{
				    //绑定datagridview代码
				    JToken tempObj = soundInfos[j];
				    if (tempObj["file_path"].ToString() != "null" && tempObj["file_path"].ToString() != "")
				    {
				        int index = DownloadList.Rows.Add();
				        DownloadList.Rows[index].Cells[0].Value = true;
				        DownloadList.Rows[index].Cells[1].Value = tempObj["channel_id"].ToString();
				        DownloadList.Rows[index].Cells[2].Value = tempObj["channel_id"].ToString();
				        DownloadList.Rows[index].Cells[3].Value = "[" + ((k - 1) * 10 + j + 1) + "]" + tempObj["name"].ToString();
				        DownloadList.Rows[index].Cells[4].Value = "http://od.qingting.fm/" + tempObj["file_path"].ToString();
				        string duration = tempObj["duration"].ToString();
				        if (duration.IndexOf(".") > -1)
				                               duration = duration.Substring(0, duration.IndexOf("."));
				        DownloadList.Rows[index].Cells[5].Value = Int32.Parse(duration) / 60 + "分" + Int32.Parse(duration) % 60 + "秒";
				        DownloadList.Rows[index].Cells[6].Value = "";
				        DownloadList.Rows[index].Cells[7].Value = "";
				        DownloadList.Rows[index].Cells[8].Value = "0%";
				    }
				}));
				State.Text = "正在分析第" + (i + 1) + "个源网页下载地址,已完成" + ((k - 1) * 10 + j) + "/" + ResoucesCount + ",请稍等……";
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("请确认输入网址符合输入规则且电脑正确联网!");
    }
}

分析和添加荔枝音频的代码:

else if (ResourceBox.Lines[i].IndexOf("lizhi") > -1)   //处理荔枝FM下载地址
{
    try
    {
        string url = ResourceBox.Lines[i];
        string html = CommonMethds.GetHttpWebRequest(url);
        if (html == "网络状况不佳!")
            html = CommonMethds.GetWebClient(url);
        Regex reg = new Regex(@"\([1-9]\d*\)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
        Match mc = reg.Match(html);
        mc = reg.Match(html);
        string temp = mc.Value.Trim();
        temp = temp.Replace("(", "").Replace(")", "");
        int ResoucesCount = int.Parse(temp);
        int pageCount = ResoucesCount / 20 + 1;
        for (int k = 1; k <= pageCount; k++)
        {
            string tempUrl = url + "/p/" + k + ".html";
            string webSources = CommonMethds.GetHttpWebRequest(tempUrl);
            webSources = webSources.Substring(webSources.IndexOf(@"
    ")); //专辑编号 List radioID = CommonMethds.GetHtmlAttr(webSources, "a", "data-uid"); //专辑名称 List radioName = CommonMethds.GetHtmlAttr(webSources, "a", "data-radio-name"); //文件名称 List audioName = CommonMethds.GetHtmlAttr(webSources, "a", "data-title"); //文件编号,用于获取下载地址 List audioID = CommonMethds.GetHtmlAttr(webSources, "a", "data-id"); //文件时长 List audioDuration = CommonMethds.GetHtmlAttr(webSources, "a", "data-duration"); for (int j = 0; j < audioID.Count; j++) { //防止datagridview假死导致滚动条不可用 Invoke(new Action(delegate { string JsonUrl = "http://www.lizhi.fm/media/url/" + audioID[j]; string json = CommonMethds.GetHttpWebRequest(JsonUrl); JObject jobj = (JObject)JsonConvert.DeserializeObject(json); string data = jobj["data"].ToString(); JObject soundUrl = (JObject)JsonConvert.DeserializeObject(data); string audioUrl = soundUrl["url"].ToString(); if (audioUrl != "null" && audioUrl != "") { //绑定datagridview代码 int index = DownloadList.Rows.Add(); DownloadList.Rows[index].Cells[0].Value = true; DownloadList.Rows[index].Cells[1].Value = radioID[j]; DownloadList.Rows[index].Cells[2].Value = radioName[j]; DownloadList.Rows[index].Cells[3].Value = "[" + ((k - 1) * 20 + j + 1) + "]" + audioName[j]; DownloadList.Rows[index].Cells[4].Value = audioUrl; DownloadList.Rows[index].Cells[5].Value = Int32.Parse(audioDuration[j]) / 60 + "分" + Int32.Parse(audioDuration[j]) % 60 + "秒"; DownloadList.Rows[index].Cells[6].Value = ""; DownloadList.Rows[index].Cells[7].Value = ""; DownloadList.Rows[index].Cells[8].Value = "0%"; } })); State.Text = "正在分析第" + (i + 1) + "个源网页下载地址,已完成" + ((k - 1) * 20 + j) + "/" + ResoucesCount + ",请稍等……"; } } } catch (Exception ex) { MessageBox.Show("请确认输入网址符合输入规则且电脑正确联网!"); } }

原理几乎没有变,就是分析下载地址需要有点耐心。

2.后记

工具使用过程中因为源音频本身不存在,会出现部分音频下载失败,一直卡在那个位置,只需要取消该音频的下载继续下其他的就可以。
如工具侵犯了您的合法权益,请邮箱联系我:[email protected]

最后再贴一下下载地址:https://download.csdn.net/download/mnikkqqw/10675530

你可能感兴趣的:([c#]Winform开发)