mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
127 lines
3.8 KiB
C#
127 lines
3.8 KiB
C#
using Kyoo.Models.Watch;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Kyoo.Models
|
|
{
|
|
namespace Watch
|
|
{
|
|
public enum StreamType
|
|
{
|
|
Unknow = 0,
|
|
Video = 1,
|
|
Audio = 2,
|
|
Subtitle = 3
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
public class Stream
|
|
{
|
|
public string Title { get; set; }
|
|
public string Language { get; set; }
|
|
public string Codec { get; set; }
|
|
[MarshalAs(UnmanagedType.I1)] public bool isDefault;
|
|
[MarshalAs(UnmanagedType.I1)] public bool isForced;
|
|
[JsonIgnore] public string Path { get; set; }
|
|
[JsonIgnore] public StreamType Type { get; set; }
|
|
|
|
public Stream() {}
|
|
|
|
public Stream(string title, string language, string codec, bool isDefault, bool isForced, string path, StreamType type)
|
|
{
|
|
Title = title;
|
|
Language = language;
|
|
Codec = codec;
|
|
this.isDefault = isDefault;
|
|
this.isForced = isForced;
|
|
Path = path;
|
|
Type = type;
|
|
}
|
|
|
|
public Stream(Stream stream)
|
|
{
|
|
Title = stream.Title;
|
|
Language = stream.Language;
|
|
isDefault = stream.isDefault;
|
|
isForced = stream.isForced;
|
|
Codec = stream.Codec;
|
|
Path = stream.Path;
|
|
Type = stream.Type;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Track : Stream
|
|
{
|
|
public int ID { get; set; }
|
|
[JsonIgnore] public long EpisodeID { get; set; }
|
|
public bool IsDefault
|
|
{
|
|
get => isDefault;
|
|
set => isDefault = value;
|
|
}
|
|
public bool IsForced
|
|
{
|
|
get => isForced;
|
|
set => isForced = value;
|
|
}
|
|
public string DisplayName;
|
|
public string Link;
|
|
|
|
[JsonIgnore] public bool IsExternal { get; set; }
|
|
public virtual Episode Episode { get; set; }
|
|
|
|
public Track() { }
|
|
|
|
public Track(StreamType type, string title, string language, bool isDefault, bool isForced, string codec, bool isExternal, string path)
|
|
: base(title, language, codec, isDefault, isForced, path, type)
|
|
{
|
|
IsExternal = isExternal;
|
|
}
|
|
|
|
public Track(Stream stream)
|
|
: base(stream)
|
|
{
|
|
IsExternal = false;
|
|
}
|
|
|
|
public Track SetLink(string episodeSlug)
|
|
{
|
|
if (Type == StreamType.Subtitle)
|
|
{
|
|
string language = Language;
|
|
//Converting mkv track language to c# system language tag.
|
|
if (language == "fre")
|
|
language = "fra";
|
|
|
|
DisplayName = CultureInfo.GetCultures(CultureTypes.NeutralCultures).FirstOrDefault(x => x.ThreeLetterISOLanguageName == language)?.EnglishName ?? language;
|
|
Link = "/subtitle/" + episodeSlug + "." + Language;
|
|
|
|
if (IsForced)
|
|
{
|
|
DisplayName += " Forced";
|
|
Link += "-forced";
|
|
}
|
|
|
|
if (Title != null && Title.Length > 1)
|
|
DisplayName += " - " + Title;
|
|
|
|
switch (Codec)
|
|
{
|
|
case "ass":
|
|
Link += ".ass";
|
|
break;
|
|
case "subrip":
|
|
Link += ".srt";
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
Link = null;
|
|
return this;
|
|
}
|
|
}
|
|
} |