public async Task UpdateVideoItemPreferences(VideoItem videoItem) { App.DebugLog(""); var videoFileTable = await _database.GetFirstAsync <VideoFileTable>(e => e.VideoId == videoItem.VideoId); videoFileTable.Position = videoItem.Position; videoFileTable.IsNew = false; videoFileTable.SelectedSubtitles = videoItem.SelectedSubtitlesId; videoFileTable.EmbeddedSubtitlesDelay = videoItem.EmbeddedSubtitlesDelay; var subtileFileTable = await _database.GetAsync <SubtitleFileTable>(o => o.FilePath, c => c.VideoId == videoItem.VideoId); var updatedFileSubtitles = new List <SubtitleFileTable>(); var newFileSubtitles = new List <SubtitleFileTable>(); foreach (var sub in videoItem.SubtitleFiles) { var subTable = subtileFileTable.Find(x => x.FilePath == sub.FilePath); if (subTable == null) { newFileSubtitles.Add(new SubtitleFileTable() { Delay = sub.Delay, FilePath = sub.FilePath, VideoId = videoItem.VideoId, IsSelected = sub.IsSelected, Encoding = sub.Encoding, }); } else { if (subTable.Delay != sub.Delay || subTable.IsSelected != sub.IsSelected || subTable.Encoding != sub.Encoding) { subTable.Delay = sub.Delay; subTable.IsSelected = sub.IsSelected; subTable.Encoding = sub.Encoding; updatedFileSubtitles.Add(subTable); } subtileFileTable.Remove(subTable); } } await _database.UpdateAsync(videoFileTable); await _database.UpdateAllAsync(subtileFileTable); await _database.InsertAllAsync(newFileSubtitles); foreach (var sub in subtileFileTable) { await _database.DeleteAsync(sub); } }
public async Task UpdateAsync() { App.DebugLog("1"); await semaphore.WaitAsync(); App.DebugLog("2"); var videoSources = await mediaScanner.ScanVideosAsync(); var oldVideos = (await database.GetAsync <VideoFileTable>(v => v.MediaStoreId)).ToDictionary(e => e.MediaStoreId); bool notFirstScan = oldVideos.Count > 0; var idsToDelete = oldVideos.ToDictionary(e => e.Key, e => true); var newVideos = new List <VideoFileTable>(); foreach (var source in videoSources) { if (oldVideos.ContainsKey(source.MediaStoreId)) { idsToDelete[source.MediaStoreId] = false; if (source.FilePath != oldVideos[source.MediaStoreId].FilePath) { } } else { newVideos.Add(new VideoFileTable() { DateAdded = source.DateAdded, DateModified = source.DateModified, Directory = source.Directory, Duration = source.Duration, FileName = source.FileName, FilePath = source.FilePath, IsDeleted = false, IsNew = true && notFirstScan, MediaStoreId = source.MediaStoreId, Position = TimeSpan.Zero, SizeInBytes = (int)source.SizeInBytes, Title = source.Title, SelectedSubtitles = -1, }); } } var videosToDelete = oldVideos.Where(e => idsToDelete[e.Key]).Select(e => e.Value); foreach (var video in videosToDelete) { video.IsDeleted = true; } await database.InsertAllAsync(newVideos); await database.UpdateAllAsync(videosToDelete); semaphore.Release(); App.DebugLog("3"); }
public async Task SaveFavoriteScenes(int videoId, IEnumerable <FavoriteScene> scenes) { await database.DeleteAsync <FavoriteSceneTable>(s => s.VideoId == videoId); var list = scenes.Select(s => new FavoriteSceneTable() { Position = s.Position, ThumbnailPath = s.ThumbnailPath, VideoId = videoId }); await database.InsertAllAsync(list); }