public async Task Refresh() { App.DebugLog(""); await _libraryUpdater.UpdateAsync(); var videos = await _database.GetAsync <VideoFileTable>(e => e.VideoId, e => !e.IsDeleted); var subtitles = await _database.GetAsync <SubtitleFileTable>(x => x.VideoId); var groupedSubtitles = subtitles.ToLookup(x => x.VideoId); _videoItems.Clear(); foreach (var videoRow in videos) { var video = videoRow.ToVideoItem(); if (groupedSubtitles.Contains(videoRow.VideoId)) { video.SubtitleFiles.AddRange(groupedSubtitles[videoRow.VideoId] .Select(x => new SubtitleFile(x.FilePath, videoRow.VideoId) { Delay = x.Delay, IsSelected = x.IsSelected, Encoding = PlayerControls.LibVlcOptions.Encoding.UTF8, })); } _videoItems.Add(video); } RefreshFolders(); }
public async Task Refresh() { await libraryUpdater.UpdateAsync(); var videos = await database.GetAsync <VideoFileTable>(e => e.VideoId, e => !e.IsDeleted); videoItems.Clear(); foreach (var video in videos) { videoItems.Add(video.ToVideoItem()); } RefreshFolders(); }
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"); }