private static async Task SetVideoInfo(DownloadTaskModel m, StorageFolder folder) { try { var f = await folder.GetParentAsync(); StorageFile file = null; if (await ExistsFile(f.Path + @"/info.json")) { return; } else { file = await f.CreateFileAsync("info.json", CreationCollisionOption.OpenIfExists); } DownloadVideonInfoModel downloadVideonInfoModel = new DownloadVideonInfoModel() { thumb = m.thumb, title = m.title }; if (m.downloadMode == DownloadMode.Video) { downloadVideonInfoModel.id = m.avid; downloadVideonInfoModel.type = "video"; } else { downloadVideonInfoModel.id = m.sid; downloadVideonInfoModel.type = "anime"; } var infoJson = JsonConvert.SerializeObject(downloadVideonInfoModel); await FileIO.WriteTextAsync(file, infoJson); } catch (Exception) { } }
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(); } }