Add control page for downloads
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.SRFPlay.Api;
|
||||
using Jellyfin.Plugin.SRFPlay.Api.Models;
|
||||
using Jellyfin.Plugin.SRFPlay.Constants;
|
||||
using Jellyfin.Plugin.SRFPlay.Services.Interfaces;
|
||||
using Jellyfin.Plugin.SRFPlay.Utilities;
|
||||
@@ -15,6 +16,7 @@ using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Channels;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.SRFPlay.Channels;
|
||||
@@ -30,6 +32,7 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
private readonly IMediaSourceFactory _mediaSourceFactory;
|
||||
private readonly ICategoryService? _categoryService;
|
||||
private readonly ISRFApiClientFactory _apiClientFactory;
|
||||
private readonly IRecordingService _recordingService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SRFPlayChannel"/> class.
|
||||
@@ -40,13 +43,15 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
/// <param name="mediaSourceFactory">The media source factory.</param>
|
||||
/// <param name="categoryService">The category service (optional).</param>
|
||||
/// <param name="apiClientFactory">The API client factory.</param>
|
||||
/// <param name="recordingService">The recording service.</param>
|
||||
public SRFPlayChannel(
|
||||
ILoggerFactory loggerFactory,
|
||||
IContentRefreshService contentRefreshService,
|
||||
IStreamUrlResolver streamResolver,
|
||||
IMediaSourceFactory mediaSourceFactory,
|
||||
ICategoryService? categoryService,
|
||||
ISRFApiClientFactory apiClientFactory)
|
||||
ISRFApiClientFactory apiClientFactory,
|
||||
IRecordingService recordingService)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<SRFPlayChannel>();
|
||||
_contentRefreshService = contentRefreshService;
|
||||
@@ -54,6 +59,7 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
_mediaSourceFactory = mediaSourceFactory;
|
||||
_categoryService = categoryService;
|
||||
_apiClientFactory = apiClientFactory;
|
||||
_recordingService = recordingService;
|
||||
|
||||
if (_categoryService == null)
|
||||
{
|
||||
@@ -170,6 +176,7 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
"latest" => await GetLatestVideosAsync(cancellationToken).ConfigureAwait(false),
|
||||
"trending" => await GetTrendingVideosAsync(cancellationToken).ConfigureAwait(false),
|
||||
"live_sports" => await GetLiveSportsAsync(cancellationToken).ConfigureAwait(false),
|
||||
"recordings" => GetRecordingItems(),
|
||||
_ when folderId.StartsWith("category_", StringComparison.Ordinal) => await GetCategoryVideosAsync(folderId, cancellationToken).ConfigureAwait(false),
|
||||
_ => new List<ChannelItemInfo>()
|
||||
};
|
||||
@@ -181,7 +188,8 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
{
|
||||
CreateFolder("latest", "Latest Videos"),
|
||||
CreateFolder("trending", "Trending Videos"),
|
||||
CreateFolder("live_sports", "Live Sports & Events")
|
||||
CreateFolder("live_sports", "Live Sports & Events"),
|
||||
CreateFolder("recordings", "Recordings")
|
||||
};
|
||||
|
||||
// Add category folders if enabled
|
||||
@@ -296,6 +304,58 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<ChannelItemInfo> GetRecordingItems()
|
||||
{
|
||||
var items = new List<ChannelItemInfo>();
|
||||
var recordings = _recordingService.GetRecordings(RecordingState.Completed);
|
||||
|
||||
foreach (var recording in recordings)
|
||||
{
|
||||
if (string.IsNullOrEmpty(recording.OutputPath) || !System.IO.File.Exists(recording.OutputPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var fileInfo = new System.IO.FileInfo(recording.OutputPath);
|
||||
var itemId = $"recording_{recording.Id}";
|
||||
|
||||
var mediaSource = new MediaSourceInfo
|
||||
{
|
||||
Id = itemId,
|
||||
Name = recording.Title,
|
||||
Path = recording.OutputPath,
|
||||
Protocol = MediaProtocol.File,
|
||||
Container = "mkv",
|
||||
SupportsDirectPlay = true,
|
||||
SupportsDirectStream = true,
|
||||
SupportsTranscoding = true,
|
||||
IsRemote = false,
|
||||
Size = fileInfo.Length,
|
||||
Type = MediaSourceType.Default
|
||||
};
|
||||
|
||||
var item = new ChannelItemInfo
|
||||
{
|
||||
Id = itemId,
|
||||
Name = recording.Title,
|
||||
Overview = recording.Description,
|
||||
Type = ChannelItemType.Media,
|
||||
ContentType = ChannelMediaContentType.Movie,
|
||||
MediaType = ChannelMediaType.Video,
|
||||
DateCreated = recording.RecordingStartedAt,
|
||||
ImageUrl = !string.IsNullOrEmpty(recording.ImageUrl)
|
||||
? CreateProxiedImageUrl(recording.ImageUrl, _mediaSourceFactory.GetServerBaseUrl())
|
||||
: CreatePlaceholderImageUrl(recording.Title, _mediaSourceFactory.GetServerBaseUrl()),
|
||||
MediaSources = new List<MediaSourceInfo> { mediaSource }
|
||||
};
|
||||
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Returning {Count} completed recordings as channel items", items.Count);
|
||||
return items;
|
||||
}
|
||||
|
||||
private async Task<List<ChannelItemInfo>> GetCategoryVideosAsync(string folderId, CancellationToken cancellationToken)
|
||||
{
|
||||
var items = new List<ChannelItemInfo>();
|
||||
@@ -411,7 +471,8 @@ public class SRFPlayChannel : IChannel, IHasCacheKey
|
||||
var timeBucket = new DateTime(now.Year, now.Month, now.Day, now.Hour, (now.Minute / 15) * 15, 0);
|
||||
var timeKey = timeBucket.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture);
|
||||
|
||||
return $"{config?.BusinessUnit}_{config?.EnableLatestContent}_{config?.EnableTrendingContent}_{config?.EnableCategoryFolders}_{enabledTopics}_{timeKey}";
|
||||
var recordingCount = _recordingService.GetRecordings(RecordingState.Completed).Count;
|
||||
return $"{config?.BusinessUnit}_{config?.EnableLatestContent}_{config?.EnableTrendingContent}_{config?.EnableCategoryFolders}_{enabledTopics}_{timeKey}_rec{recordingCount}";
|
||||
}
|
||||
|
||||
private async Task<List<ChannelItemInfo>> ConvertUrnsToChannelItems(List<string> urns, CancellationToken cancellationToken)
|
||||
|
||||
Reference in New Issue
Block a user