using MediaBrowser.Model.Tasks; using Microsoft.Extensions.Logging; using MediaBrowser.Controller; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Jellyfin.Data.Entities; using Jellyfin.Data.Enums; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.Model.Playlists; using MediaBrowser.Model.Tasks; using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks { public class GeneratePlaylist : IScheduledTask { private readonly ILogger _logger; private readonly ILibraryManager _libraryManager; private readonly IUserManager _userManager; public GeneratePlaylist( ILogger logger, ILibraryManager libraryManager, IUserManager userManager ) { _logger = logger; _libraryManager = libraryManager; _userManager = userManager; } public string Category => "Library"; public string Name => "(re)generate Smart Playlists"; public string Description => "Generate or regenerate all Smart Playlists"; public string Key => nameof(GeneratePlaylist); public IEnumerable GetDefaultTriggers() { return new[] { new TaskTriggerInfo { IntervalTicks = TimeSpan.FromMinutes(1).Ticks, Type = TaskTriggerInfo.TriggerInterval, } }; } private void GetUsers() { foreach (var user in _userManager.Users) { _logger.LogInformation("User {0}", user); var query = new InternalItemsQuery(user) { IncludeItemTypes = new[] {BaseItemKind.Audio}, Recursive = true, }; foreach (BaseItem item in _libraryManager.GetItemsResult(query).Items) { _logger.LogInformation("Item {0}", item); } } } public async Task ExecuteAsync(IProgress progress, CancellationToken cancellationToken) { _logger.LogInformation("This is a test"); GetUsers(); } } }