Indicate VIP Webshare is needed in video versions. Still broken playback after choosing media source.
This commit is contained in:
@@ -14,6 +14,8 @@ using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using StreamCinema.Webshare;
|
||||
using StreamCinemaLib.API;
|
||||
|
||||
@@ -22,6 +24,8 @@ namespace Jellyfin.Plugin.StreamCinema;
|
||||
public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
{
|
||||
private const bool IsWebshareFreeAccount = true;
|
||||
private const double BitrateMargin = 0.1; // 10 %
|
||||
private const double WebshareFreeBitrate = 300000 * 8;
|
||||
|
||||
private static readonly TimeSpan VersionValidityTimeout = TimeSpan.FromMinutes(180);
|
||||
|
||||
@@ -29,9 +33,10 @@ public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
|
||||
private readonly IMediaSourceManager _inner;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IHttpContextAccessor _http;
|
||||
private readonly ConcurrentDictionary<Guid, VersionSetEntry> _videoVersions;
|
||||
|
||||
public StreamCinemaMediaSourceManager(IStreamCinemaInnerMediaSourceManager innerMediaSourceManager, ILibraryManager libraryManager, IServiceProvider svc)
|
||||
public StreamCinemaMediaSourceManager(IStreamCinemaInnerMediaSourceManager innerMediaSourceManager, ILibraryManager libraryManager, IServiceProvider svc, IHttpContextAccessor http)
|
||||
{
|
||||
if (innerMediaSourceManager == null || svc == null)
|
||||
throw new ArgumentNullException();
|
||||
@@ -42,6 +47,7 @@ public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
this._inner = inner;
|
||||
|
||||
this._libraryManager = libraryManager;
|
||||
this._http = http;
|
||||
this._videoVersions = new ConcurrentDictionary<Guid, VersionSetEntry>();
|
||||
|
||||
_instance = this;
|
||||
@@ -159,13 +165,18 @@ public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
VersionSetEntry ver = GetVersionSet(video, out BaseItem? videoPrimary, default).GetAwaiter().GetResult();
|
||||
if (ver.Versions != null)
|
||||
{
|
||||
foreach (var i in ver.Versions)
|
||||
result.Add(GetVersionInfo(video, i.Meta));
|
||||
// Make sure BaseItem exists for each version
|
||||
IEnumerable<Video> items;
|
||||
switch (video)
|
||||
{
|
||||
case StreamCinemaMovie movie: GetVideoVersionsEnumerate<StreamCinemaMovie>(movie, videoPrimary!, ver.Versions).Last(); break;
|
||||
case StreamCinemaMovie movie: items = GetVideoVersionsEnumerate<StreamCinemaMovie>(movie, videoPrimary!, ver.Versions); break;
|
||||
default: throw new NotSupportedException(string.Format("BaseItem type '{0}' not supported in CinemaMediaSources.", video.GetType().Name));
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
// Warning: We assume GetVideoVersionsEnumerate keeps the order between its input and output collections
|
||||
// Note: Also makes sure BaseItems exist for each version
|
||||
foreach (var i in items)
|
||||
result.Add(GetVersionInfo(i, ver.Versions[idx++].Meta));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -186,8 +197,24 @@ public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
|| string.IsNullOrEmpty(item.ExternalId))
|
||||
return await _inner.GetPlaybackMediaSources(item, user, allowMediaProbe, enablePathSubstitution, cancellationToken);
|
||||
|
||||
// HACK: We do not want to generate links to all media sources - just the one going
|
||||
// to be played. Unfortunately our caller MediaInfoHelper.GetPlaybackInfo and indirectly
|
||||
// from MediaInfoController.GetPostedPlaybackInfo does not pass this info to us
|
||||
// so we will grab it directly from the HttpRequest
|
||||
HttpContext? ctx = _http.HttpContext;
|
||||
StringValues mediaSourceIdS;
|
||||
string? mediaSourceId;
|
||||
if (ctx == null
|
||||
|| !ctx.Request.Path.HasValue
|
||||
|| !ctx.Request.Path.Value.EndsWith("/PlaybackInfo")
|
||||
|| (mediaSourceIdS = ctx.Request.Query["mediaSourceId"]).Count != 1
|
||||
|| string.IsNullOrEmpty(mediaSourceId = mediaSourceIdS[0]))
|
||||
throw new NotSupportedException(string.Format("Unsupported caller '{0}' of CinemaMediaSourceManager", ctx != null && ctx.Request.Path.HasValue ? ctx.Request.Path.Value : "?"));
|
||||
|
||||
BaseItem? verItem = _libraryManager.GetItemById(Guid.Parse(mediaSourceId));
|
||||
|
||||
List<MediaSourceInfo> result = new List<MediaSourceInfo>();
|
||||
switch (item)
|
||||
switch (verItem)
|
||||
{
|
||||
case Video video:
|
||||
VersionEntry? ver = await GetVersion(video, cancellationToken);
|
||||
@@ -401,7 +428,11 @@ public class StreamCinemaMediaSourceManager : IMediaSourceManager
|
||||
// Warning: We set some properties on item that get used below
|
||||
result.MediaStreams = VersionToMediaStreams(item, ver);
|
||||
|
||||
string name = $"{Math.Round((double)(ver.size ?? 0) / (1024 * 1024 * 1024), 2)} GB ({ver.date_added?.ToShortDateString()})"
|
||||
double bitRate = (ver.size ?? 0.0) * 8 / (item.RunTimeTicks ?? 1.0) * TimeSpan.TicksPerSecond;
|
||||
bool showBitrateWarning = IsWebshareFreeAccount && bitRate / (1 + BitrateMargin) > WebshareFreeBitrate;
|
||||
|
||||
string name = showBitrateWarning ? "LOGIN Webshare! " : "";
|
||||
name += $"{Math.Round((double)(ver.size ?? 0) / (1024 * 1024 * 1024), 2)} GB ({ver.date_added?.ToShortDateString()})"
|
||||
+ $" {Math.Round((item.RunTimeTicks ?? 0.0) / TimeSpan.TicksPerMinute)} min";
|
||||
MediaStream? firstVid = result.MediaStreams.Where(x => x.Type == MediaStreamType.Video).FirstOrDefault();
|
||||
if (firstVid != null)
|
||||
|
||||
Reference in New Issue
Block a user