jellyfin-smart-playlist/Jellyfin.Plugin.SmartPlaylist/ScheduledTasks/GeneratePlaylist.cs

74 lines
2.5 KiB
C#
Raw Normal View History

2024-06-27 01:47:44 +02:00
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;
2024-06-27 01:47:44 +02:00
namespace Jellyfin.Plugin.SmartPlaylist.ScheduledTasks {
public class GeneratePlaylist : IScheduledTask {
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
private readonly IUserManager _userManager;
2024-06-27 01:47:44 +02:00
public GeneratePlaylist(
ILogger<Plugin> logger,
ILibraryManager libraryManager,
IUserManager userManager
2024-06-27 01:47:44 +02:00
) {
_logger = logger;
_libraryManager = libraryManager;
_userManager = userManager;
2024-06-27 01:47:44 +02:00
}
2024-06-27 01:47:44 +02:00
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);
2024-06-27 01:47:44 +02:00
public IEnumerable<TaskTriggerInfo> 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);
}
}
}
2024-06-27 01:47:44 +02:00
public async Task ExecuteAsync(IProgress<double> progress, CancellationToken cancellationToken) {
_logger.LogInformation("This is a test");
GetUsers();
2024-06-27 01:47:44 +02:00
}
}
}