Exemplo n.º 1
0
        public static async Task LoadDowned()
        {
            var folder = await DownloadHelper2.GetDownloadFolder();

            try
            {
                foreach (var item in await folder.GetFoldersAsync())
                {
                    if (await DownloadHelper2.ExistsFile(item.Path + @"\info.json"))
                    {
                        var file = await item.GetFileAsync("info.json");

                        var data = await FileIO.ReadTextAsync(file);

                        DownloadVideonInfoModel downloadVideonInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadVideonInfoModel>(data);
                        var video = new VideoDiaplayModel()
                        {
                            id        = downloadVideonInfoModel.id,
                            mode      = downloadVideonInfoModel.type,
                            title     = downloadVideonInfoModel.title,
                            videolist = new List <PartDiaplayModel>()
                        };
                        if (await DownloadHelper2.ExistsFile(item.Path + @"\thumb.jpg"))
                        {
                            video.thumb = item.Path + "/thumb.jpg";
                        }
                        else
                        {
                            video.thumb = downloadVideonInfoModel.thumb;
                        }
                        foreach (var item1 in await item.GetFoldersAsync())
                        {
                            if (await DownloadHelper2.ExistsFile(item1.Path + @"\info.json"))
                            {
                                List <bool> check = new List <bool>();
                                var         files = await item1.GetFilesAsync();

                                foreach (var item2 in files)
                                {
                                    if (item2.FileType == ".mp4" || item2.FileType == ".flv")
                                    {
                                        if (await DownloadHelper2.GetFileSize(item2.Path) == 0)
                                        {
                                            check.Add(false);
                                        }
                                        else
                                        {
                                            check.Add(true);
                                        }
                                    }
                                }
                                if (!check.Contains(false))
                                {
                                    var file1 = await item1.GetFileAsync("info.json");

                                    var data1 = await FileIO.ReadTextAsync(file1);

                                    DownloadPartnInfoModel downloadPartnInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadPartnInfoModel>(data1);
                                    var part = new PartDiaplayModel()
                                    {
                                        cid     = downloadPartnInfoModel.cid,
                                        eptitle = downloadPartnInfoModel.title,
                                        path    = item1.Path,
                                        index   = downloadPartnInfoModel.index,
                                        id      = video.id,
                                        mode    = video.mode,
                                        title   = video.title,
                                        epid    = downloadPartnInfoModel.epid
                                    };
                                    if (!downloadeds.ContainsKey(downloadPartnInfoModel.cid))
                                    {
                                        downloadeds.Add(downloadPartnInfoModel.cid, item1.Path);
                                    }

                                    video.videolist.Add(part);
                                }
                            }
                        }

                        if (video.videolist.Count != 0)
                        {
                            video.videolist = video.videolist.OrderBy(x => x.index).ToList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await new MessageDialog("无法读取已经下载完成的视频").ShowAsync();
            }
        }
Exemplo n.º 2
0
        public static async Task LoadDowned()
        {
            Dictionary <string, string> valuePairs = new Dictionary <string, string>();
            var folder = await DownloadHelper2.GetDownloadFolder();

            try
            {
                foreach (var item in await folder.GetFoldersAsync())
                {
                    if (await DownloadHelper2.ExistsFile(item.Path + @"\info.json"))
                    {
                        var file = await item.GetFileAsync("info.json");

                        var data = await FileIO.ReadTextAsync(file);

                        DownloadVideonInfoModel downloadVideonInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadVideonInfoModel>(data);
                        var video = new VideoDiaplayModel()
                        {
                            id        = downloadVideonInfoModel.id,
                            mode      = downloadVideonInfoModel.type,
                            title     = downloadVideonInfoModel.title,
                            videolist = new List <PartDiaplayModel>()
                        };
                        if (await DownloadHelper2.ExistsFile(item.Path + @"\thumb.jpg"))
                        {
                            video.thumb = item.Path + "/thumb.jpg";
                        }
                        else
                        {
                            video.thumb = downloadVideonInfoModel.thumb;
                        }
                        foreach (var item1 in await item.GetFoldersAsync())
                        {
                            if (await DownloadHelper2.ExistsFile(item1.Path + @"\info.json"))
                            {
                                var flag  = false;
                                var files = (await item1.GetFilesAsync()).Where(x => x.FileType == ".mp4" || x.FileType == ".flv");
                                if (files.Count() != 0)
                                {
                                    //DownloadHelper2.GetFileSize(x.Path).Result
                                    foreach (var subfile in files)
                                    {
                                        if (await DownloadHelper2.GetFileSize(subfile.Path) == 0)
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (flag)
                                    {
                                        break;
                                    }
                                    var file1 = await item1.GetFileAsync("info.json");

                                    var data1 = await FileIO.ReadTextAsync(file1);

                                    DownloadPartnInfoModel downloadPartnInfoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <DownloadPartnInfoModel>(data1);
                                    var part = new PartDiaplayModel()
                                    {
                                        cid     = downloadPartnInfoModel.cid,
                                        eptitle = downloadPartnInfoModel.title,
                                        path    = item1.Path,
                                        index   = downloadPartnInfoModel.index,
                                        id      = video.id,
                                        mode    = video.mode,
                                        title   = video.title
                                    };
                                    if (!valuePairs.ContainsKey(downloadPartnInfoModel.cid))
                                    {
                                        valuePairs.Add(downloadPartnInfoModel.cid, item1.Path);
                                    }
                                    video.videolist.Add(part);
                                }
                            }
                        }

                        if (video.videolist.Count != 0)
                        {
                            video.videolist = video.videolist.OrderBy(x => x.index).ToList();
                        }
                    }
                }
                downloadeds = valuePairs;
            }
            catch (Exception ex)
            {
                await new MessageDialog("无法读取已经下载完成的视频").ShowAsync();
            }
        }