async Task read(int index) { danmaku.ClearDanmu(); media.Visibility = Visibility.Collapsed; grid_status.Visibility = Visibility.Visible; cid = infos[index].Cid; aid = infos[0].Title; status.Text = "获取视频地址..."; URL = await ContentServ.GetVedioURL(cid, quality, format); status.Text += (URL == null) ? "失败" : $"{URL.Ps.Count}个{format}分段"; if (URL == null) { return; } status.Text += Environment.NewLine + "加载弹幕数据..."; try { DanmuPool = await GetDanmu(cid); } catch (Exception e) { status.Text += "失败" + e.Message; } if (format == VideoFormat.mp4) { // MP4只有一个分段(根据经验( ̄▽ ̄)") media.Source = new Uri(URL.Ps[0].Url); } else if (format == VideoFormat.flv) { // 先读第一个分段 SetFFmpegSource(URL.Ps[0].Url); } if (URL.Ps.Count > 1) { // Flag该立的时候也得立啊 // GetFlags(); } _currentP = URL.Ps[0]; txt_title.Text = infos[index].Title; if (URL.Acceptquality.Contains("1")) { q1.Visibility = Visibility.Visible; } if (URL.Acceptquality.Contains("2")) { q2.Visibility = Visibility.Visible; } if (URL.Acceptquality.Contains("3")) { q3.Visibility = Visibility.Visible; } status.Text += Environment.NewLine + "正在缓冲视频..."; loading.Visibility = Visibility.Visible; }
/// <summary> /// 开始下载 /// </summary> private async void Btn_ok_Click(object sender, RoutedEventArgs e) { int i = 0; flyout_download.Hide(); foreach (Pages item in ReadyList.SelectedItems) { try { cid = item.Cid; VideoURL url = await ContentServ.GetVedioURL(cid, quality, format); string name = StringDeal.RemoveSpecial(title.Text); string part = StringDeal.RemoveSpecial(item.Part); StorageFolder folder = await DownloadHelper.GetMyFolderAsync(); StorageFolder f1 = await folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists); List <DownloadOperation> list = new List <DownloadOperation>(); for (int j = 0; j < url.Ps.Count; j++) { list.Add(await DownloadHelper.Download(url.Ps[j].Url, $"{part}_{j}.{format.ToString()}", f1)); } // 如果await,那么执行完第一个StartAsync()后即退出循环.GetCurrentDownloadsAsync()方法同样会遇到此问题.(Download页) IAsyncOperationWithProgress <DownloadOperation, DownloadOperation> start; for (int k = 0; k < list.Count; k++) { start = list[k].StartAsync(); } i++; await DownloadHelper.AddVideoInfo(part, cid, details.Sid); await popup.Show(i.ToString() + "个视频已加入下载队列"); if (SettingHelper.ContainsKey("_downdanmu")) { if ((bool)SettingHelper.GetValue("_downdanmu") == false) { continue; } } await DownloadHelper.DownloadDanmakuAsync(cid, part, f1); } catch (Exception err) { await popup.Show(err.Message); } } SwitchCommandBar(false); }
async Task read(int index) { danmaku.ClearDanmu(); media.Visibility = Visibility.Collapsed; status.Visibility = Visibility.Visible; cid = infos[index].Cid; aid = infos[0].Title; status.Text = "获取视频地址..."; int quality = 2; if (SettingHelper.ContainsKey("_quality")) { quality = int.Parse(SettingHelper.GetValue("_quality").ToString()); } URL = await ContentServ.GetVedioURL(cid, quality, VideoFormat.mp4); string url = URL.Url; status.Text += (URL == null) ? "失败" : "完毕"; if (URL == null) { return; } status.Text += Environment.NewLine + "加载弹幕数据..."; try { DanmuPool = await GetDanmu(cid); status.Text += "完毕"; } catch { status.Text += "失败"; } media.Source = new Uri(url); txt_title.Text = infos[index].Title; status.Text += Environment.NewLine + "正在缓冲视频..."; loading.Visibility = Visibility.Visible; }
private async void btn_ok_Click(object sender, RoutedEventArgs e) { int i = 0; foreach (Pages item in ReadyList.SelectedItems) { try { cid = item.Cid; VideoURL url = await ContentServ.GetVedioURL(cid, 2, VideoFormat.mp4); string name = StringDeal.RemoveSpecial(title.Text); string part = StringDeal.RemoveSpecial(item.Part); StorageFolder folder = await KnownFolders.VideosLibrary.CreateFolderAsync("哔哩哔哩", CreationCollisionOption.OpenIfExists); StorageFolder f1 = await folder.CreateFolderAsync(name, CreationCollisionOption.OpenIfExists); var download = await DownloadHelper.Download(url.Url, part + ".mp4", f1); if (SettingHelper.ContainsKey("_downdanmu")) { if ((bool)SettingHelper.GetValue("_downdanmu") == true) { string xml = await BaseService.SentGetAsync("http://comment.bilibili.com/" + cid + ".xml"); StorageFile file = await f1.CreateFileAsync(part + ".xml"); using (Stream file0 = await file.OpenStreamForWriteAsync()) { using (StreamWriter writer = new StreamWriter(file0)) { writer.Write(xml); } } } } else { string xml = await BaseService.SentGetAsync("http://comment.bilibili.com/" + cid + ".xml"); StorageFile file = await f1.CreateFileAsync(name + ".xml"); using (Stream file0 = await file.OpenStreamForWriteAsync()) { using (StreamWriter writer = new StreamWriter(file0)) { writer.Write(xml); } } } //如果await,那么执行完第一个StartAsync()后即退出循环.GetCurrentDownloadsAsync()方法同样会遇到此问题.(Download页) IAsyncOperationWithProgress <DownloadOperation, DownloadOperation> start = download.StartAsync(); i++; messagepop.Show(i.ToString() + "个视频已加入下载队列"); } catch (Exception err) { messagepop.Show(err.Message); } } }