mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
API: Fixing watch items images and previous/next handling
This commit is contained in:
parent
504bd5bca8
commit
6a3e48a1d1
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -32,7 +33,7 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// Information about tracks and display information that could be used by the player.
|
/// Information about tracks and display information that could be used by the player.
|
||||||
/// This contains mostly data from an <see cref="Episode"/> with another form.
|
/// This contains mostly data from an <see cref="Episode"/> with another form.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WatchItem
|
public class WatchItem : CustomTypeDescriptor, IThumbnails
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ID of the episode associated with this item.
|
/// The ID of the episode associated with this item.
|
||||||
@ -101,6 +102,9 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsMovie { get; set; }
|
public bool IsMovie { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Dictionary<int, string> Images { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The container of the video file of this episode.
|
/// The container of the video file of this episode.
|
||||||
/// Common containers are mp4, mkv, avi and so on.
|
/// Common containers are mp4, mkv, avi and so on.
|
||||||
@ -147,11 +151,11 @@ namespace Kyoo.Abstractions.Models
|
|||||||
if (ep.AbsoluteNumber != null)
|
if (ep.AbsoluteNumber != null)
|
||||||
{
|
{
|
||||||
previous = await library.GetOrDefault(
|
previous = await library.GetOrDefault(
|
||||||
x => x.ShowID == ep.ShowID && x.AbsoluteNumber <= ep.AbsoluteNumber,
|
x => x.ShowID == ep.ShowID && x.AbsoluteNumber < ep.AbsoluteNumber,
|
||||||
new Sort<Episode>(x => x.AbsoluteNumber, true)
|
new Sort<Episode>(x => x.AbsoluteNumber, true)
|
||||||
);
|
);
|
||||||
next = await library.GetOrDefault(
|
next = await library.GetOrDefault(
|
||||||
x => x.ShowID == ep.ShowID && x.AbsoluteNumber >= ep.AbsoluteNumber,
|
x => x.ShowID == ep.ShowID && x.AbsoluteNumber > ep.AbsoluteNumber,
|
||||||
new Sort<Episode>(x => x.AbsoluteNumber)
|
new Sort<Episode>(x => x.AbsoluteNumber)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -195,6 +199,7 @@ namespace Kyoo.Abstractions.Models
|
|||||||
Title = ep.Title,
|
Title = ep.Title,
|
||||||
ReleaseDate = ep.ReleaseDate,
|
ReleaseDate = ep.ReleaseDate,
|
||||||
Path = ep.Path,
|
Path = ep.Path,
|
||||||
|
Images = ep.Show.Images,
|
||||||
Container = PathIO.GetExtension(ep.Path)![1..],
|
Container = PathIO.GetExtension(ep.Path)![1..],
|
||||||
Video = ep.Tracks.FirstOrDefault(x => x.Type == StreamType.Video),
|
Video = ep.Tracks.FirstOrDefault(x => x.Type == StreamType.Video),
|
||||||
Audios = ep.Tracks.Where(x => x.Type == StreamType.Audio).ToArray(),
|
Audios = ep.Tracks.Where(x => x.Type == StreamType.Audio).ToArray(),
|
||||||
@ -232,5 +237,17 @@ namespace Kyoo.Abstractions.Models
|
|||||||
return Array.Empty<Chapter>();
|
return Array.Empty<Chapter>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GetClassName()
|
||||||
|
{
|
||||||
|
return nameof(Show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override string GetComponentName()
|
||||||
|
{
|
||||||
|
return ShowSlug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,13 +152,15 @@ namespace Kyoo.Core.Api
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object GetValue(object target)
|
public object GetValue(object target)
|
||||||
{
|
{
|
||||||
if (target is not (IThumbnails thumb and IResource res)
|
string slug = (target as IResource)?.Slug ?? (target as ICustomTypeDescriptor)?.GetComponentName();
|
||||||
|
if (target is not IThumbnails thumb
|
||||||
|
|| slug == null
|
||||||
|| string.IsNullOrEmpty(thumb.Images?.GetValueOrDefault(_imageIndex)))
|
|| string.IsNullOrEmpty(thumb.Images?.GetValueOrDefault(_imageIndex)))
|
||||||
return null;
|
return null;
|
||||||
string type = target is ICustomTypeDescriptor descriptor
|
string type = target is ICustomTypeDescriptor descriptor
|
||||||
? descriptor.GetClassName()
|
? descriptor.GetClassName()
|
||||||
: target.GetType().Name;
|
: target.GetType().Name;
|
||||||
return new Uri(_host, $"/api/{type}/{res.Slug}/{Images.ImageName[_imageIndex]}".ToLower())
|
return new Uri(_host, $"/api/{type}/{slug}/{Images.ImageName[_imageIndex]}".ToLower())
|
||||||
.ToString();
|
.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -75,11 +76,13 @@ namespace Kyoo.Core.Api
|
|||||||
/// <param name="extension">An optional extension for the subtitle file.</param>
|
/// <param name="extension">An optional extension for the subtitle file.</param>
|
||||||
/// <returns>The subtitle file</returns>
|
/// <returns>The subtitle file</returns>
|
||||||
/// <response code="404">No subtitle exist with the given ID or slug.</response>
|
/// <response code="404">No subtitle exist with the given ID or slug.</response>
|
||||||
[HttpGet("{identifier:id}", Order = AlternativeRoute)]
|
[HttpGet("{identifier:int}", Order = AlternativeRoute)]
|
||||||
[HttpGet("{identifier:id}.{extension}")]
|
[HttpGet("{identifier:id}.{extension}")]
|
||||||
[PartialPermission(Kind.Read)]
|
[PartialPermission(Kind.Read)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
|
[SuppressMessage("ReSharper", "RouteTemplates.ParameterTypeAndConstraintsMismatch",
|
||||||
|
Justification = "An indentifier can be constructed with an int.")]
|
||||||
public async Task<IActionResult> GetSubtitle(Identifier identifier, string extension)
|
public async Task<IActionResult> GetSubtitle(Identifier identifier, string extension)
|
||||||
{
|
{
|
||||||
Track subtitle = await identifier.Match(
|
Track subtitle = await identifier.Match(
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 7bf53b40080d1d43228f1cdcad510b302ead99ff
|
Subproject commit 846dbcb22ed29244a2384d240180c821ec18df2b
|
Loading…
x
Reference in New Issue
Block a user