public async Task SaveVideoItemPreferences(VideoItem videoItem)
        {
            var videoFileTable = await database.GetFirstAsync <VideoFileTable>(e => e.VideoId == videoItem.VideoId);

            videoFileTable.Position = videoItem.Preferences.Position;
            await database.UpdateAsync(videoFileTable);
        }
示例#2
0
        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);
            }
        }