Exemplo n.º 1
0
 private async void GetDownOk_New()
 {
     try
     {
         list_Downed.ItemsSource = null;
         DownloadManage.Downloaded.Clear();
         await Task.Run(async() =>
         {
             StorageFolder DownFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("Bili-Down", CreationCollisionOption.OpenIfExists);
             List <DownloadManage.FolderModel> list = new List <DownloadManage.FolderModel>();
             foreach (var item in await DownFolder.GetFoldersAsync())
             {
                 DownloadManage.FolderModel model = new DownloadManage.FolderModel()
                 {
                     title       = item.Name,
                     count       = 0,
                     downedCount = 0,
                 };
                 List <DownloadManage.DownModel> list_file = new List <DownloadManage.DownModel>();
                 foreach (var item1 in await item.GetFoldersAsync())
                 {
                     foreach (var item2 in await item1.GetFilesAsync())
                     {
                         try
                         {
                             if (item2.FileType == ".json")
                             {
                                 StorageFile files = item2;
                                 string json       = await FileIO.ReadTextAsync(item2);
                                 DownloadManage.DownModel model123 = JsonConvert.DeserializeObject <DownloadManage.DownModel>(json);
                                 if (model123.downloaded == true)
                                 {
                                     list_file.Add(model123);
                                     model.downedCount++;
                                     DownloadManage.Downloaded.Add(model123.mid);
                                 }
                                 model.IsBangumi = model123.isBangumi;
                                 model.aid       = model123.aid;
                             }
                         }
                         catch (Exception)
                         {
                         }
                     }
                     model.count++;
                 }
                 model.path      = item.Path;
                 model.downModel = list_file;
                 list.Add(model);
             }
             await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { list_Downed.ItemsSource = list; });
         });
     }
     catch (Exception ex)
     {
         messShow.Show("读取已下载失败\r\n" + ex.Message, 2000);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 监视指定的后台下载任务
        /// </summary>
        /// <param name="download">后台下载任务</param>
        private async Task HandleDownloadAsync(DownloadManage.HandleModel model)
        {
            try
            {
                DownloadProgress(model.downOp);
                //进度监控
                Progress <DownloadOperation> progressCallback = new Progress <DownloadOperation>(DownloadProgress);
                await model.downOp.AttachAsync().AsTask(model.cts.Token, progressCallback);

                //保存任务信息
                //  StorageFolder folder = ApplicationData.Current.LocalFolder;
                StorageFolder DowFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("Bili-Down", CreationCollisionOption.OpenIfExists);

                StorageFile file = await DowFolder.GetFileAsync(model.Guid + ".bili");

                //用Url编码是因为不支持读取中文名
                //含会出现:在多字节的目标代码页中,没有此 Unicode 字符可以映射到的字符。错误
                string        path   = WebUtility.UrlDecode(await FileIO.ReadTextAsync(file));
                StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path);

                StorageFile files = await folder.CreateFileAsync(model.Guid + ".json", CreationCollisionOption.OpenIfExists); //await StorageFile.GetFileFromPathAsync(path+@"\" + model.Guid + ".json");

                string json = await FileIO.ReadTextAsync(files);

                DownloadManage.DownModel info = JsonConvert.DeserializeObject <DownloadManage.DownModel>(json);
                info.downloaded = true;
                string      jsonInfo  = JsonConvert.SerializeObject(info);
                StorageFile fileWrite = await folder.CreateFileAsync(info.Guid + ".json", CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(fileWrite, jsonInfo);

                //移除正在监控
                HandleList.Remove(model.downModel.Guid);
                GetDownOk_New();
            }
            catch (TaskCanceledException)
            {
                //取消通知
                //ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
                //XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
                //XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                //IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                //((XmlElement)toastNode).SetAttribute("duration", "short");
                //toastTextElements[0].AppendChild(toastXml.CreateTextNode(String.Format("取消任务{0}", model.downModel.title)));
                //ToastNotification toast = new ToastNotification(toastXml);
                //ToastNotificationManager.CreateToastNotifier().Show(toast);
            }
            catch (Exception ex)
            {
                WebErrorStatus error = BackgroundTransferError.GetStatus(ex.HResult);
                return;
            }
            finally
            {
                list_Downing.Items.Remove(model);
            }
        }
        private async void btn_Ok_Click(object sender, RoutedEventArgs e)
        {
            using (DownloadManage wc = new DownloadManage())
            {
                if (Video_List.SelectedItems.Count != 0)
                {
                    //循环读取全部选中的项目
                    foreach (VideoModel item in Video_List.SelectedItems)
                    {
                        int quality = cb_Qu.SelectedIndex + 1;//清晰度1-3
                        if (DownloadManage.Downloaded.Contains(item.cid))
                        {
                            break;
                        }
                        string Downurl = await wc.GetVideoUri(item.cid, quality);//取得视频URL

                        if (Downurl != null)
                        {
                            DownloadManage.DownModel model = new DownloadManage.DownModel()
                            {
                                mid        = item.cid,
                                title      = Video_Title.Text,
                                part       = item.page,
                                url        = Downurl,
                                aid        = item.aid,
                                danmuUrl   = "http://comment.bilibili.com/" + item.cid + ".xml",
                                quality    = quality,
                                downloaded = false,
                                partTitle  = item.part,
                                isBangumi  = false
                            };
                            wc.StartDownload(model);
                            //StartDownload(model);
                        }
                        else
                        {
                            MessageDialog md = new MessageDialog(item.title + "\t视频地址获取失败");
                            await md.ShowAsync();
                        }
                    }
                    messShow.Show("任务已加入下载队列", 3000);
                    Video_List.SelectionMode      = ListViewSelectionMode.None;
                    Video_List.IsItemClickEnabled = true;
                    Down_ComBar.Visibility        = Visibility.Collapsed;
                    com_bar.Visibility            = Visibility.Visible;
                }
                else
                {
                    Video_List.SelectionMode      = ListViewSelectionMode.None;
                    Video_List.IsItemClickEnabled = true;
                    Down_ComBar.Visibility        = Visibility.Collapsed;
                    com_bar.Visibility            = Visibility.Visible;
                }
            }
        }
Exemplo n.º 4
0
        private async void btn_OK_Click(object sender, RoutedEventArgs e)
        {
            using (DownloadManage wc = new DownloadManage())
            {
                if (list_E.SelectedItems.Count != 0)
                {
                    //循环读取全部选中的项目
                    foreach (BangumiInfoModel item in list_E.SelectedItems)
                    {
                        int    quality = cb_Qu.SelectedIndex + 1;                                //清晰度1-3
                        string Downurl = await wc.GetVideoUri(item.danmaku.ToString(), quality); //取得视频URL

                        if (Downurl != null)
                        {
                            DownloadManage.DownModel model = new DownloadManage.DownModel()
                            {
                                mid        = item.danmaku.ToString(),
                                title      = "【番剧】" + txt_Name.Text,
                                part       = item.index,
                                url        = Downurl,
                                aid        = banID,
                                danmuUrl   = "http://comment.bilibili.com/" + item.danmaku + ".xml",
                                quality    = quality,
                                downloaded = false,
                                partTitle  = item.index_title ?? "",
                                isBangumi  = true
                            };
                            wc.StartDownload(model);
                            //StartDownload(model);
                        }
                        else
                        {
                            MessageDialog md = new MessageDialog(item.title + "\t视频地址获取失败");
                            await md.ShowAsync();
                        }
                    }
                    messShow.Show("任务已加入下载队列", 3000);
                    list_E.SelectionMode      = ListViewSelectionMode.None;
                    list_E.IsItemClickEnabled = true;
                    com_bar_Down.Visibility   = Visibility.Collapsed;
                    com_bar.Visibility        = Visibility.Visible;
                }
                else
                {
                    list_E.SelectionMode      = ListViewSelectionMode.None;
                    list_E.IsItemClickEnabled = true;
                    com_bar_Down.Visibility   = Visibility.Collapsed;
                    com_bar.Visibility        = Visibility.Visible;
                }
            }
        }
Exemplo n.º 5
0
        private async void btn_Download_Click(object sender, RoutedEventArgs e)
        {
            DownloadManage wc = new DownloadManage();

            if (Video_List.Items.Count == 1)
            {
                //循环读取全部选中的项目

                VideoModel item    = (VideoModel)Video_List.Items[0];
                int        quality = cb_Qu.SelectedIndex + 1;//清晰度1-3
                if (DownloadManage.Downloaded.Contains(item.cid))
                {
                    messShow.Show("已经下载过了", 200);
                    return;
                }
                string Downurl = await wc.GetVideoUri(item.cid, quality);//取得视频URL

                if (Downurl != null)
                {
                    DownloadManage.DownModel model = new DownloadManage.DownModel()
                    {
                        mid        = item.cid,
                        title      = Video_Title.Text,
                        part       = item.page,
                        url        = Downurl,
                        aid        = item.aid,
                        danmuUrl   = "http://comment.bilibili.com/" + item.cid + ".xml",
                        quality    = quality,
                        downloaded = false,
                        partTitle  = item.part,
                        isBangumi  = false
                    };
                    wc.StartDownload(model);
                    messShow.Show("任务已加入下载队列", 3000);
                }
                else
                {
                    MessageDialog md = new MessageDialog(item.title + "\t视频地址获取失败");
                    await md.ShowAsync();
                }
            }
            else
            {
                Video_List.SelectionMode      = ListViewSelectionMode.Multiple;
                Video_List.IsItemClickEnabled = false;
                messShow.Show("请选中要下载的分P视频,点击确定", 3000);
                Down_ComBar.Visibility = Visibility.Visible;
                com_bar.Visibility     = Visibility.Collapsed;
            }
        }
Exemplo n.º 6
0
 //读取完成
 public async void GetDownOk()
 {
     try
     {
         list_DownOk.Items.Clear();
         await Task.Run(async() =>
         {
             StorageFolder folder     = ApplicationData.Current.LocalFolder;
             StorageFolder DownFolder = await KnownFolders.VideosLibrary.CreateFolderAsync("Bili-Download", CreationCollisionOption.OpenIfExists);
             StorageFolder DowFolder  = await folder.CreateFolderAsync("DownLoad", CreationCollisionOption.OpenIfExists);
             foreach (var item in await DowFolder.GetFilesAsync())
             {
                 if (item.FileType == ".json")
                 {
                     StorageFile file = item;
                     string json      = await FileIO.ReadTextAsync(item);
                     DownloadManage.DownModel model = JsonConvert.DeserializeObject <DownloadManage.DownModel>(json);
                     if (model.downloaded == true)
                     {
                         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { list_DownOk.Items.Add(model); });
                     }
                 }
             }
             foreach (var item in await DownFolder.GetFilesAsync())
             {
                 if (item.FileType == ".json")
                 {
                     StorageFile file = item;
                     string json      = await FileIO.ReadTextAsync(item);
                     DownloadManage.DownModel model = JsonConvert.DeserializeObject <DownloadManage.DownModel>(json);
                     if (model.downloaded == true)
                     {
                         await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { list_DownOk.Items.Add(model); });
                     }
                 }
             }
         });
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 7
0
 //播放
 private void btn_Play_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //StorageFile file = await StorageFile.GetFileFromPathAsync(((DownMangentClass.DownModel)list_DownOk.SelectedItem).path);
         DownloadManage.DownModel model = (DownloadManage.DownModel)list_DownOk.SelectedItem;
         List <VideoModel>        ls    = new List <VideoModel>()
         {
             new VideoModel {
                 path  = model.path,
                 title = model.title ?? "",
                 cid   = model.mid,
                 IsOld = true
             }
         };
         KeyValuePair <List <VideoModel>, int> Par = new KeyValuePair <List <VideoModel>, int>(ls, 0);
         this.Frame.Navigate(typeof(PlayerPage), Par);
     }
     catch (Exception)
     {
     }
 }