/// <summary> /// 有加密 才会进入的函数 /// </summary> private void GetAES() { string url = aesConf.uri; //请求获取key string key = new WebApiInvoker().InvokeWebAPI(url); aesConf.key = Encoding.UTF8.GetBytes(key); DownloadTS(); }
/// <summary> /// 多线程下载 /// </summary> private void MutiDownloadTS() { index = 0; //List<Task> tasks = new List<Task>(); List <Action> actions = new List <Action>(); TsPaths.ForEach(tsPath => { int curIndex = index++; actions.Add(() => { try { string tsUrl = ApplyURL(tsPath, M3U8Url); Logger.LogDebug($"请求file:{curIndex}"); byte[] file = new WebApiInvoker().RequestFile(tsUrl); Logger.LogDebug($"请求file:{curIndex}结束"); //var res = ByteHelper.WriteByteToFile(file, @"C:/temp/Test2/v1.ts"); file = DealTS(file, curIndex); //解密 如果有就解密 没有就原样返回 if (file == default) { return; } string dicTsPath = GetTSDic(); string tsName = $"__{curIndex.ToString().PadLeft(5, '0')}"; if (outFileConfig.saveAsEncrpy) //需要加密保存 { file = TsEncrypt(file, curIndex); } ByteHelper.WriteByteToFile(file, GetTsPath(tsName)); OutConfigSave(tsName, curIndex, GetTsPath(tsName)); } catch (Exception ex) { TsBadDownloadUrl.Add(tsPath); //IsComplete = false; Logger.LogError("下载失败:" + tsPath + "::" + ex.Message); } }); }); Logger.LogDebug("开启下载"); //给定下载的延迟 不然有时候waitall并不退出 时间是timer * action的个数 DownloadExitSafe(actions, 5 * actions.Count); Logger.LogDebug("下载结束"); //Task.WaitAll(tasks.ToArray()); }
/// <summary> /// 单线程下载 /// </summary> private void SingleDownloadTS() { Logger.LogDebug("开启下载"); TsPaths.ForEach(tsPath => { int curIndex = index++; try { string tsUrl = ApplyURL(tsPath, M3U8Url); Logger.LogDebug("请求file"); byte[] file = new WebApiInvoker().RequestFile(tsUrl); Logger.LogDebug("请求file结束"); //var res = ByteHelper.WriteByteToFile(file, @"C:/temp/Test2/v1.ts"); file = DealTS(file, curIndex); //解密 如果有就解密 没有就原样返回 if (file == default) { return; } if (outFileConfig.saveAsEncrpy) //需要加密保存 { file = TsEncrypt(file, curIndex); } string dicTsPath = GetTSDic(); string tsName = $"__{curIndex.ToString().PadLeft(5, '0')}"; ByteHelper.WriteByteToFile(file, GetTsPath(tsName)); OutConfigSave(tsName, curIndex, GetTsPath(tsName)); } catch (Exception ex) { TsBadDownloadUrl.Add(tsPath); //IsComplete = false; Logger.LogError(ex.Message); } }); Logger.LogDebug("下载结束"); //Task.WaitAll(tasks.ToArray()); }
public ApiTestsBase() { ApiInvoker = new WebApiInvoker(ApiBaseAddress); }
/// <summary> /// 请求M3U8 /// </summary> /// <param name="url">互联网上 M3U8的地址</param> /// <returns></returns> private string RequestM3U8(string url) { WebApiInvoker webApiInvoker = new WebApiInvoker(); return(webApiInvoker.InvokeWebAPI(url)); }