public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress) { cancellationToken.ThrowIfCancellationRequested(); await Tracking.Track(_httpClient, _appHost, _serverConfigurationManager, "start", "syncplayed", cancellationToken).ConfigureAwait(false); var config = Plugin.Instance.Configuration; BlurNItems items = new BlurNItems(); string dataPath = Path.Combine(_appPaths.PluginConfigurationsPath, "MediaBrowser.Channels.BlurN.Data.json"); if (_fileSystem.FileExists(dataPath)) { items.List = _json.DeserializeFromFile <List <BlurNItem> >(dataPath); } var users = _userManager.Users.ToList(); Plugin.DebugLogger($"Syncing played status of {users.Count} users to library."); for (int u = 0; u < users.Count; u++) { User user = users[u]; Dictionary <string, BaseItem> libDict = Library.BuildLibraryDictionary(cancellationToken, _libraryManager, new InternalItemsQuery() { HasAnyProviderId = new[] { "Imdb" }, User = user, IsPlayed = false, //SourceTypes = new SourceType[] { SourceType.Library } }); Plugin.DebugLogger($"User {user.Name} has {libDict.Count} unplayed movies in library."); for (int i = 0; i < items.List.Count; i++) { BlurNItem blurNItem = items.List[i]; BaseItem libraryItem; if (libDict.TryGetValue(blurNItem.ImdbId, out libraryItem)) { UserItemData uid = _userDataManager.GetAllUserData(user.InternalId).FirstOrDefault(aud => aud.Key == $"{config.ChannelRefreshCount}-{blurNItem.ImdbId}"); if (uid != default(UserItemData)) { if (uid.Played) { libraryItem.MarkPlayed(user, uid.LastPlayedDate, true); Plugin.DebugLogger($"Marked {blurNItem.Title} as watched in movie library."); } } } progress.Report(((u + ((i + 1) / items.List.Count)) / users.Count) * 100); } } await Tracking.Track(_httpClient, _appHost, _serverConfigurationManager, "end", "syncplayed", cancellationToken).ConfigureAwait(false); progress.Report(100); return; }