Commit e2d7a01f authored by 黄奎's avatar 黄奎

下载修改

parent 55717a45
......@@ -16,6 +16,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace Edu.WebApi.Controllers.Course
......@@ -1371,21 +1372,20 @@ namespace Edu.WebApi.Controllers.Course
foreach (Match subItem in iframe_matchs)
{
string newUrl = "";
var tempArray = subItem.Value.Split(new char[] { ' ', ' ' });
foreach (var tItem in tempArray)
if (subItem.Value.Contains("src"))
{
if (tItem.IndexOf("src") != -1)
var srcArray = subItem.Value.Split(new string[] { "url=" }, StringSplitOptions.None);
if (srcArray != null && srcArray.Length > 0 && srcArray.Length == 2)
{
var imageArray = tItem.Split(new string[] { "url=" }, StringSplitOptions.None);
if (imageArray != null && imageArray.Length > 0 && imageArray.Length == 2)
var sourceArray = srcArray[1].Split(new string[] { ".mp3" }, StringSplitOptions.None);
if (sourceArray != null && sourceArray.Length > 0)
{
string tempUrl = imageArray[1].Substring(0, imageArray[1].Length - 1);
var tempUrl = sourceArray[0] + ".mp3";
newUrl = System.Web.HttpUtility.UrlDecode(tempUrl);
}
}
}
string key = "[音频" + index + "]";
fileList.Add(new FileItem()
{
FileName = key,
......@@ -1412,17 +1412,17 @@ namespace Edu.WebApi.Controllers.Course
MatchCollection iframe_matchs = Regex.Matches(newSubTitle, iframeRule);
foreach (Match iframeItem in iframe_matchs)
{
string newUrl = "";
var tempArray = iframeItem.Value.Split(new char[] { ' ', ' ' });
foreach (var tItem in tempArray)
string newUrl1 = "";
if (iframeItem.Value.Contains("src"))
{
if (tItem.IndexOf("src") != -1)
var srcArray1 = iframeItem.Value.Split(new string[] { "url=" }, StringSplitOptions.None);
if (srcArray1 != null && srcArray1.Length > 0 && srcArray1.Length == 2)
{
var imageArray = tItem.Split(new string[] { "url=" }, StringSplitOptions.None);
if (imageArray != null && imageArray.Length > 0 && imageArray.Length == 2)
var sourceArray1 = srcArray1[1].Split(new string[] { ".mp3" }, StringSplitOptions.None);
if (sourceArray1 != null && sourceArray1.Length > 0)
{
string tempUrl = imageArray[1].Substring(0, imageArray[1].Length - 1);
newUrl = System.Web.HttpUtility.UrlDecode(tempUrl);
var tempUrl = sourceArray1[0] + ".mp3";
newUrl1 = System.Web.HttpUtility.UrlDecode(tempUrl);
}
}
}
......@@ -1431,7 +1431,7 @@ namespace Edu.WebApi.Controllers.Course
fileList.Add(new FileItem()
{
FileName = key,
FileUrl = newUrl,
FileUrl = newUrl1,
});
index++;
}
......@@ -1448,15 +1448,23 @@ namespace Edu.WebApi.Controllers.Course
}
var wordFile = Common.Plugin.WordTemplateHelper.UrlToWordFile(url, path_server, savePath, fileName);
foreach (var item in fileList)
var tasks = new List<Task>();
for (int index = 0; index < fileList.Count; index++)
{
if (!string.IsNullOrEmpty(item.FileUrl))
if (!string.IsNullOrEmpty(fileList[index].FileUrl))
{
WebClient mywebclient = new WebClient();
mywebclient.DownloadFile(item.FileUrl, savePath + item.FileName + ".mp3");
mywebclient.Dispose();
tasks.Add(Task.Factory.StartNew(o =>
{
int value = (int)o;
DownLoadFile(fileList[value], savePath);
}, index));
Thread.Sleep(500);
}
}
if (tasks != null && tasks.Count > 0)
{
Task.WaitAll(tasks.ToArray());
}
Common.Plugin.ZipHelper.Zip(savePath, savePath2 + zipFileName, ref messageTip);
}
catch (Exception ex)
......@@ -1465,5 +1473,12 @@ namespace Edu.WebApi.Controllers.Course
}
return ApiResult.Success(data: fileUrl);
}
private void DownLoadFile(FileItem item,string savePath)
{
WebClient mywebclient = new WebClient();
mywebclient.DownloadFile(item.FileUrl, savePath + item.FileName + ".mp3");
mywebclient.Dispose();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment