Exemplo n.º 1
0
        /// <summary>
        /// 读取旧版下载的视频
        /// </summary>
        /// <returns></returns>
        public async Task LoadDownloadedOld()
        {
            var folder = await GetDownloadOldFolder();

            //var list = new List<DownloadedItem>();
            foreach (var item in await folder.GetFoldersAsync())
            {
                try
                {
                    //检查是否存在info.json
                    var infoFile = await item.TryGetItemAsync("info.json") as StorageFile;

                    if (infoFile == null)
                    {
                        continue;
                    }

                    var info = JObject.Parse(await FileIO.ReadTextAsync(infoFile));
                    //新版下载无thumb字段
                    if (!info.ContainsKey("thumb"))
                    {
                        continue;
                    }
                    List <DownloadedSubItem> lsEpisodes     = new List <DownloadedSubItem>();
                    DownloadedItem           downloadedItem = new DownloadedItem()
                    {
                        CoverPath  = Path.Combine(item.Path, "thumb.jpg"),
                        Epsidoes   = new ObservableCollection <DownloadedSubItem>(),
                        ID         = info["id"].ToString(),
                        Title      = info["title"].ToString(),
                        UpdateTime = infoFile.DateCreated.LocalDateTime,
                        IsSeason   = info["type"].ToString() != "video",
                        Path       = item.Path
                    };
                    var coverFile = await item.TryGetItemAsync("thumb.jpg") as StorageFile;

                    if (coverFile != null)
                    {
                        BitmapImage bitmapImage = new BitmapImage();
                        bitmapImage.SetSource(await coverFile.GetScaledImageAsThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView));
                        downloadedItem.Cover = bitmapImage;
                    }

                    foreach (var episodeItem in await item.GetFoldersAsync())
                    {
                        //检查是否存在info.json
                        var episodeInfoFile = await episodeItem.TryGetItemAsync("info.json") as StorageFile;

                        if (episodeInfoFile == null)
                        {
                            continue;
                        }
                        var files = (await episodeItem.GetFilesAsync()).Where(x => x.FileType == ".blv" || x.FileType == ".flv" || x.FileType == ".mp4" || x.FileType == ".m4s");
                        if (files.Count() == 0)
                        {
                            continue;
                        }
                        bool flag = false;
                        foreach (var subfile in files)
                        {
                            var size = (await subfile.GetBasicPropertiesAsync()).Size;
                            if (size == 0)
                            {
                                flag = true;
                                break;
                            }
                        }

                        if (flag)
                        {
                            continue;
                        }

                        var episodeInfo       = JObject.Parse(await FileIO.ReadTextAsync(episodeInfoFile));
                        var downloadedSubItem = new DownloadedSubItem()
                        {
                            AVID         = "",
                            CID          = episodeInfo["cid"].ToString(),
                            Index        = episodeInfo["index"].ToInt32(),
                            EpisodeID    = episodeInfo["epid"]?.ToString() ?? "",
                            IsDash       = await episodeItem.TryGetItemAsync("video.m4s") != null,
                            Paths        = new List <string>(),
                            Title        = episodeInfo["title"].ToString(),
                            SubtitlePath = new List <DownloadSubtitleInfo>(),
                            Path         = episodeItem.Path
                        };
                        //设置视频
                        foreach (var file in files)
                        {
                            downloadedSubItem.Paths.Add(file.Path);
                        }

                        files = null;
                        downloadedSubItem.DanmakuPath = Path.Combine(episodeItem.Path, downloadedSubItem.CID + ".xml");


                        lsEpisodes.Add(downloadedSubItem);
                    }
                    //排序
                    foreach (var episode in lsEpisodes.OrderBy(x => x.Index))
                    {
                        downloadedItem.Epsidoes.Add(episode);
                    }

                    Downloadeds.Add(downloadedItem);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    continue;
                }
            }

            // list = list.OrderByDescending(x => x.UpdateTime).ToList();

            //return list;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 读取下载的视频
        /// </summary>
        /// <returns></returns>
        public async void LoadDownloaded()
        {
            LoadingDownloaded = true;
            Downloadeds.Clear();
            var folder = await GetDownloadFolder();

            await LoadDiskSize(folder);

            // var list = new List<DownloadedItem>();
            foreach (var item in await folder.GetFoldersAsync())
            {
                try
                {
                    //检查是否存在info.json
                    var infoFile = await item.TryGetItemAsync("info.json") as StorageFile;

                    if (infoFile == null)
                    {
                        continue;
                    }
                    var info = JsonConvert.DeserializeObject <DownloadSaveInfo>(await FileIO.ReadTextAsync(infoFile));
                    //旧版无Cover字段,跳过
                    if (string.IsNullOrEmpty(info.Cover))
                    {
                        continue;
                    }
                    List <DownloadedSubItem> lsEpisodes     = new List <DownloadedSubItem>();
                    DownloadedItem           downloadedItem = new DownloadedItem()
                    {
                        CoverPath  = Path.Combine(item.Path, "cover.jpg"),
                        Epsidoes   = new ObservableCollection <DownloadedSubItem>(),
                        ID         = info.ID,
                        Title      = info.Title,
                        UpdateTime = infoFile.DateCreated.LocalDateTime,
                        IsSeason   = info.Type == DownloadType.Season,
                        Path       = item.Path
                    };
                    var coverFile = await item.TryGetItemAsync("cover.jpg") as StorageFile;

                    if (coverFile != null)
                    {
                        BitmapImage bitmapImage = new BitmapImage();
                        var         buffer      = await FileIO.ReadBufferAsync(coverFile);

                        using (IRandomAccessStream stream = new InMemoryRandomAccessStream())
                        {
                            await stream.WriteAsync(buffer);

                            stream.Seek(0);
                            bitmapImage.SetSource(stream);
                            downloadedItem.Cover = bitmapImage;
                        }
                    }

                    foreach (var episodeItem in await item.GetFoldersAsync())
                    {
                        //检查是否存在info.json
                        var episodeInfoFile = await episodeItem.TryGetItemAsync("info.json") as StorageFile;

                        if (episodeInfoFile == null)
                        {
                            continue;
                        }
                        var files = (await episodeItem.GetFilesAsync()).Where(x => x.FileType == ".blv" || x.FileType == ".mp4" || x.FileType == ".m4s");
                        if (files.Count() == 0)
                        {
                            continue;
                        }
                        bool flag = false;
                        foreach (var subfile in files)
                        {
                            var size = (await subfile.GetBasicPropertiesAsync()).Size;
                            if (size == 0)
                            {
                                flag = true;
                                break;
                            }
                        }
                        files = null;
                        if (flag)
                        {
                            continue;
                        }

                        var episodeInfo       = JsonConvert.DeserializeObject <DownloadSaveEpisodeInfo>(await FileIO.ReadTextAsync(episodeInfoFile));
                        var downloadedSubItem = new DownloadedSubItem()
                        {
                            AVID         = episodeInfo.AVID,
                            CID          = episodeInfo.CID,
                            Index        = episodeInfo.Index,
                            EpisodeID    = episodeInfo.EpisodeID,
                            IsDash       = episodeInfo.IsDash,
                            Paths        = new List <string>(),
                            Title        = episodeInfo.EpisodeTitle,
                            SubtitlePath = new List <DownloadSubtitleInfo>(),
                            Path         = episodeItem.Path
                        };
                        //设置视频
                        foreach (var path in episodeInfo.VideoPath)
                        {
                            downloadedSubItem.Paths.Add(Path.Combine(episodeItem.Path, path));
                        }
                        if (!string.IsNullOrEmpty(episodeInfo.DanmakuPath))
                        {
                            downloadedSubItem.DanmakuPath = Path.Combine(episodeItem.Path, episodeInfo.DanmakuPath);
                        }
                        if (episodeInfo.SubtitlePath != null)
                        {
                            foreach (var subtitle in episodeInfo.SubtitlePath)
                            {
                                downloadedSubItem.SubtitlePath.Add(new DownloadSubtitleInfo()
                                {
                                    Name = subtitle.Name,
                                    Url  = Path.Combine(episodeItem.Path, subtitle.Url)
                                });
                            }
                        }

                        lsEpisodes.Add(downloadedSubItem);
                    }
                    //排序
                    foreach (var episode in lsEpisodes.OrderBy(x => x.Index))
                    {
                        downloadedItem.Epsidoes.Add(episode);
                    }

                    Downloadeds.Add(downloadedItem);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    continue;
                }
            }

            // list = list.OrderByDescending(x => x.UpdateTime).ToList();
            if (SettingHelper.GetValue(SettingHelper.Download.LOAD_OLD_DOWNLOAD, false))
            {
                await LoadDownloadedOld();
            }


            //foreach (var item in list)
            //{
            //    Downloadeds.Add(item);
            //}
            LoadingDownloaded = false;
        }