Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ public static class ActionContextExtensions
"ItemID",
];

private static readonly string[] UserGuidKeys = ["userId", "UserId", "UserID"];

private static readonly string[] IdsGuidKeys = ["ids", "Ids", "IDs"];

private static readonly HashSet<string> SearchActionNames = new(
Expand Down Expand Up @@ -277,13 +279,17 @@ public static class ActionContextExtensions
)
{
"GetItems",
"GetItemById",
"GetItem",
"GetItemLegacy",
"GetItemsByUserIdLegacy",
"GetPlaybackInfo",
"GetPlaybackMediaSources",
"GetPostedPlaybackInfo",
"GetVideoStream",
"GetVideoStreamByContainer",
"GetDownload",
"GetSubtitle",
"GetSubtitleWithTicks",
};

Expand Down Expand Up @@ -347,8 +353,18 @@ public static bool IsInsertableAction(this HttpContext ctx)
);
}

public static bool IsInsertableAction(this ActionExecutingContext ctx) =>
ctx.HttpContext.IsInsertableAction();
public static bool IsInsertableAction(this ActionExecutingContext ctx)
{
var actionName = ctx.GetActionName();
if (actionName is null)
return ctx.HttpContext.IsInsertableAction();

return InsertableActionNames.Contains(actionName)
&& (
!InsertableListActionNames.Contains(actionName)
|| InsertableListActionNames.Contains(actionName) && ctx.IsSingleItemList()
);
}

public static bool IsSingleItemList(this HttpContext ctx)
{
Expand Down Expand Up @@ -448,7 +464,30 @@ public static void ReplaceGuid(this ActionExecutingContext ctx, Guid value)

public static bool TryGetUserId(this ActionExecutingContext ctx, out Guid userId)
{
return ctx.HttpContext.TryGetUserId(out userId);
if (ctx.HttpContext.TryGetUserId(out userId))
return true;

foreach (var key in UserGuidKeys)
{
if (
ctx.ActionArguments.TryGetValue(key, out var arg)
&& TryParseGuidValue(arg, out userId)
)
{
return true;
}

if (
ctx.RouteData.Values.TryGetValue(key, out var route)
&& TryParseGuidValue(route, out userId)
)
{
return true;
}
}

userId = Guid.Empty;
return false;
}

public static bool TryGetUserId(this HttpContext ctx, out Guid userId)
Expand All @@ -465,6 +504,22 @@ public static bool TryGetUserId(this HttpContext ctx, out Guid userId)
return userId != Guid.Empty;
}

private static bool TryParseGuidValue(object? raw, out Guid guid)
{
switch (raw)
{
case Guid g when g != Guid.Empty:
guid = g;
return true;
case string s when Guid.TryParse(s, out var parsed) && parsed != Guid.Empty:
guid = parsed;
return true;
default:
guid = Guid.Empty;
return false;
}
}

public static bool TryGetActionArgument<T>(
this ActionExecutingContext ctx,
string key,
Expand Down
14 changes: 8 additions & 6 deletions Decorators/DtoServiceDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ private void Patch(BaseItemDto dto, BaseItem? item, bool isList, User? user)
{
if (dto.Path is not null && dto.Path.IsUrl())
{
// dto.Path = "/stub";


dto.Path = "/stub";
}

dto.CanDownload = true;
Expand All @@ -107,9 +105,13 @@ private void Patch(BaseItemDto dto, BaseItem? item, bool isList, User? user)
{
foreach (var source in dto.MediaSources)
{
//source.Path = "/stub";
//source.IsRemote = false;
// source.Protocol = MediaProtocol.File;
source.SupportsDirectPlay = false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im hesitant on this. We dont know what clients ise this for. Maybe it will prevent them for direct playing at all wand a build a transcodee url themselves. If we just stub the path it should be enough

if (source.Path is not null && source.Path.IsUrl())
{
source.Path = "/stub";
source.IsRemote = false;
source.Protocol = MediaProtocol.File;
}
}
}
return;
Expand Down
10 changes: 7 additions & 3 deletions Decorators/MediaSourceManagerDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,14 @@ await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, ct)
}

// Stub path after probing is done so the real URL is never sent to clients.
// Force File protocol so clients proxy through Jellyfin instead of direct-playing.
if (ctx.GetActionName() == "GetPostedPlaybackInfo")
// Force File protocol so clients proxy through Jellyfin instead of direct-playing
// internal addon URLs like http://caddy:8088/...
if (ctx.GetActionName() is "GetPlaybackInfo" or "GetPostedPlaybackInfo")
{
selected.Path = "/stub";
selected.IsRemote = false;
selected.Protocol = MediaProtocol.File;
selected.SupportsDirectPlay = false;
}

return [selected];
Expand Down Expand Up @@ -525,7 +527,9 @@ private MediaSourceInfo GetVersionInfo(
Size = item.Size,
Type = type,
SupportsDirectStream = true,
SupportsDirectPlay = true,
// Never direct-play Gelato HTTP URLs from clients. They may be internal Docker
// URLs (for example http://caddy:8088/...) and must be proxied by Jellyfin.
SupportsDirectPlay = false,
// just always say yes
HasSegments = true,
//HasSegments = MediaSegmentManager.HasSegments(item.Id)
Expand Down
6 changes: 6 additions & 0 deletions Filters/SearchActionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ private List<BaseItemDto> ConvertMetasToDtos(List<StremioMeta> metas)
if (baseItem is null)
continue;

if (manager.FindExistingItem(baseItem) is { } existing)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is slow. I dont think its necessarily needed if the insert action catches all routes properly

{
dtos.Add(dtoService.GetBaseItemDto(existing, options));
continue;
}

var dto = dtoService.GetBaseItemDto(baseItem, options);
var stremioUri = StremioUri.FromBaseItem(baseItem);
dto.Id = stremioUri.ToGuid();
Expand Down