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;
|
2024-06-29 18:29:40 +02:00
|
|
|
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;
|
2024-06-29 18:29:40 +02:00
|
|
|
private readonly ILibraryManager _libraryManager;
|
|
|
|
private readonly IUserManager _userManager;
|
|
|
|
|
2024-06-27 01:47:44 +02:00
|
|
|
public GeneratePlaylist(
|
2024-06-29 18:29:40 +02:00
|
|
|
ILogger<Plugin> logger,
|
|
|
|
ILibraryManager libraryManager,
|
|
|
|
IUserManager userManager
|
2024-06-27 01:47:44 +02:00
|
|
|
) {
|
|
|
|
_logger = logger;
|
2024-06-29 18:29:40 +02:00
|
|
|
_libraryManager = libraryManager;
|
|
|
|
_userManager = userManager;
|
2024-06-27 01:47:44 +02:00
|
|
|
}
|
2024-06-29 18:29:40 +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-29 18:29:40 +02:00
|
|
|
|
2024-06-27 01:47:44 +02:00
|
|
|
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers() {
|
|
|
|
return new[] {
|
|
|
|
new TaskTriggerInfo {
|
|
|
|
IntervalTicks = TimeSpan.FromMinutes(1).Ticks,
|
|
|
|
Type = TaskTriggerInfo.TriggerInterval,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-06-29 18:29:40 +02:00
|
|
|
|
|
|
|
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");
|
2024-06-29 18:29:40 +02:00
|
|
|
GetUsers();
|
2024-06-27 01:47:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|