mirror of
https://github.com/zoriya/Kyoo.git
synced 2026-05-28 10:02:28 -04:00
Add liks in the API for videos, fonts and subtitle
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// A font of an <see cref="Episode"/>.
|
||||
/// </summary>
|
||||
public class Font
|
||||
public class Font : ILink
|
||||
{
|
||||
/// <summary>
|
||||
/// A human-readable identifier, used in the URL.
|
||||
@@ -47,6 +47,9 @@ namespace Kyoo.Abstractions.Models
|
||||
/// </summary>
|
||||
[SerializeIgnore] public string Path { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Link { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new empty <see cref="Font"/>.
|
||||
/// </summary>
|
||||
@@ -56,12 +59,14 @@ namespace Kyoo.Abstractions.Models
|
||||
/// Create a new <see cref="Font"/> from a path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the font.</param>
|
||||
public Font(string path)
|
||||
/// <param name="episodeSlug">The slug of the episode that contains this font.</param>
|
||||
public Font(string path, string episodeSlug)
|
||||
{
|
||||
Slug = Utility.ToSlug(PathIO.GetFileNameWithoutExtension(path));
|
||||
Path = path;
|
||||
File = PathIO.GetFileName(path);
|
||||
Format = PathIO.GetExtension(path).Replace(".", string.Empty);
|
||||
Link = $"/watch/{episodeSlug}/font/{Slug}.{Format}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Kyoo - A portable and vast media library solution.
|
||||
// Copyright (c) Kyoo.
|
||||
//
|
||||
// See AUTHORS.md and LICENSE file in the project root for full license information.
|
||||
//
|
||||
// Kyoo is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// Kyoo is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
namespace Kyoo.Abstractions.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// An interface to represent resources that should have a link field in their return values (like videos).
|
||||
/// </summary>
|
||||
public interface ILink
|
||||
{
|
||||
/// <summary>
|
||||
/// The link to return, in most cases this should be a string.
|
||||
/// </summary>
|
||||
public object Link { get; }
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// <summary>
|
||||
/// A video, audio or subtitle track for an episode.
|
||||
/// </summary>
|
||||
public class Track : IResource
|
||||
public class Track : IResource, ILink
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int ID { get; set; }
|
||||
@@ -66,9 +66,9 @@ namespace Kyoo.Abstractions.Models
|
||||
{
|
||||
get
|
||||
{
|
||||
string type = Type.ToString().ToLower();
|
||||
string type = Type.ToString().ToLowerInvariant();
|
||||
string index = TrackIndex != 0 ? $"-{TrackIndex}" : string.Empty;
|
||||
string episode = _episodeSlug ?? Episode?.Slug ?? EpisodeID.ToString();
|
||||
string episode = _episodeSlug ?? Episode?.Slug ?? EpisodeID.ToString(CultureInfo.InvariantCulture);
|
||||
return $"{episode}.{Language ?? "und"}{index}{(IsForced ? ".forced" : string.Empty)}.{type}";
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Kyoo.Abstractions.Models
|
||||
Language = match.Groups["lang"].Value;
|
||||
if (Language == "und")
|
||||
Language = null;
|
||||
TrackIndex = match.Groups["index"].Success ? int.Parse(match.Groups["index"].Value) : 0;
|
||||
TrackIndex = match.Groups["index"].Success ? int.Parse(match.Groups["index"].Value, CultureInfo.InvariantCulture) : 0;
|
||||
IsForced = match.Groups["forced"].Success;
|
||||
Type = Enum.Parse<StreamType>(match.Groups["type"].Value, true);
|
||||
}
|
||||
@@ -198,6 +198,9 @@ namespace Kyoo.Abstractions.Models
|
||||
/// </summary>
|
||||
[SerializeIgnore] private Episode _episode;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Link => Type == StreamType.Subtitle ? $"/subtitle/{Slug}" : null;
|
||||
|
||||
// Converting mkv track language to c# system language tag.
|
||||
private static string _GetLanguage(string mkvLanguage)
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Kyoo.Abstractions.Models
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class WatchItem : CustomTypeDescriptor, IThumbnails
|
||||
public class WatchItem : CustomTypeDescriptor, IThumbnails, ILink
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID of the episode associated with this item.
|
||||
@@ -136,6 +136,13 @@ namespace Kyoo.Abstractions.Models
|
||||
/// </summary>
|
||||
public ICollection<Chapter> Chapters { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public object Link => new
|
||||
{
|
||||
Direct = $"/video/direct/{Slug}",
|
||||
Transmux = $"/video/transmux/{Slug}/master.m3u8",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="WatchItem"/> from an <see cref="Episode"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -233,7 +233,7 @@ namespace Kyoo.Core.Controllers
|
||||
{
|
||||
string path = _files.Combine(await _files.GetExtraDirectory(episode), "Attachments");
|
||||
return (await _files.ListFiles(path))
|
||||
.Select(x => new Font(x))
|
||||
.Select(x => new Font(x, episode.Slug))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace Kyoo.Core.Controllers
|
||||
.FirstOrDefault(x => Utility.ToSlug(Path.GetFileNameWithoutExtension(x)) == slug);
|
||||
if (font == null)
|
||||
return null;
|
||||
return new Font(font);
|
||||
return new Font(font, episode.Slug);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user