private Collection GetSeason(string directory, Parent parent) { var season = new Collection { Id = Guid.NewGuid(), Name = directory.Split('\\').Last(), Parent = parent }; parent.SeasonId = season.Id; LogMessage.AppendLine($" {season.Name}"); season.Videos = new System.ComponentModel.BindingList <Video>(); var files = Directory.GetFiles(directory); LogMessage.AppendLine($" :"); foreach (var path in files) { var properties = new FileInfo(path); if (AllowedExtension.Contains(properties.Extension.ToUpper())) { season.Videos.Add(new Models.Video() { Id = Guid.NewGuid(), Name = properties.Name, Path = path, TimeSkips = new List <Models.SignificantMoment>(), Parent = parent }); LogMessage.AppendLine($" {properties.Name},"); } } return(season); }
private async Task GatherSubFolderAndFiles(StorageFolder folder, Directory parent, bool singleVideo = false) { LogMessage.AppendLine($"***********************"); LogMessage.AppendLine($"Folder: {folder.Name}"); bool folderHasImage = false; foreach (var file in await folder.GetFilesAsync()) { if (ImageExtensions.Contains(file.FileType.ToUpper()) && !folderHasImage) { var copy = await file.CopyAsync(await Cache.GetThumbnailFolder()); await copy.RenameAsync(Cache.GetName(parent.Id.Value)); folderHasImage = true; } if (AllowedExtension.Contains(file.FileType.ToUpper())) { LogMessage.AppendLine($" {file.Name}"); VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync(); var title = videoProperties.Title; var fileName = string.IsNullOrEmpty(title) ? file.Name : title; var video = new Video() { Name = file.DisplayName, Parent = parent, Path = file.Path, FileName = fileName, ParentDirId = parent.Id.Value, Id = Guid.NewGuid(), Markers = new List <Markers>(), }; var thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView); using (var reader = new DataReader(thumbnail.GetInputStreamAt(0))) { await reader.LoadAsync((uint)thumbnail.Size); var buffer = new byte[(int)thumbnail.Size]; reader.ReadBytes(buffer); Cache.SaveThumbnail(buffer, video.Id.Value); } parent.Videos.Add(video); if (singleVideo) { return; } } } foreach (var subFolder in await folder.GetFoldersAsync()) { if (subFolder.Name.ToLower() == "sample" || subFolder.Name.ToLower() == "subtitles" || subFolder.Name.ToLower() == "subs") { continue; } var directory = new Directory() { Name = subFolder.Name, Parent = parent, Path = subFolder.Path, Id = Guid.NewGuid(), ParentDirId = parent.Id.Value }; parent.Directories.Add(directory); await GatherSubFolderAndFiles(subFolder, directory); } }