Solving bug with tracks

This commit is contained in:
Zoe Roux 2020-06-08 21:48:00 +02:00
parent 538bc06597
commit b0eab43d52
5 changed files with 26 additions and 16 deletions

View File

@ -87,25 +87,25 @@ namespace Kyoo.Models
} }
} }
public string Link public string Slug
{ {
get get
{ {
if (Type != StreamType.Subtitle) if (Type != StreamType.Subtitle)
return null; return null;
string link = "/subtitle/" + Episode.Slug + "." + Language; string slug = $"/subtitle/{Episode.Slug}.{Language ?? ID.ToString()}";
if (IsForced) if (IsForced)
link += "-forced"; slug += "-forced";
switch (Codec) switch (Codec)
{ {
case "ass": case "ass":
link += ".ass"; slug += ".ass";
break; break;
case "subrip": case "subrip":
link += ".srt"; slug += ".srt";
break; break;
} }
return link; return slug;
} }
} }
@ -127,11 +127,13 @@ namespace Kyoo.Models
} }
//Converting mkv track language to c# system language tag. //Converting mkv track language to c# system language tag.
public static string GetLanguage(string mkvLanguage) private static string GetLanguage(string mkvLanguage)
{ {
if (mkvLanguage == "fre") return mkvLanguage switch
return "fra"; {
return mkvLanguage; "fre" => "fra",
_ => mkvLanguage
};
} }
} }
} }

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Kyoo.Models.Watch;
namespace Kyoo.Models namespace Kyoo.Models
{ {
@ -14,7 +15,7 @@ namespace Kyoo.Models
public int SeasonNumber; public int SeasonNumber;
public int EpisodeNumber; public int EpisodeNumber;
public string Title; public string Title;
public string Link; public string Slug;
public DateTime? ReleaseDate; public DateTime? ReleaseDate;
[JsonIgnore] public string Path; [JsonIgnore] public string Path;
public Episode PreviousEpisode; public Episode PreviousEpisode;
@ -47,7 +48,7 @@ namespace Kyoo.Models
Path = path; Path = path;
Container = Path.Substring(Path.LastIndexOf('.') + 1); Container = Path.Substring(Path.LastIndexOf('.') + 1);
Link = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber); Slug = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber);
} }
public WatchItem(int episodeID, public WatchItem(int episodeID,
@ -59,11 +60,13 @@ namespace Kyoo.Models
DateTime? releaseDate, DateTime? releaseDate,
string path, string path,
IEnumerable<Track> audios, IEnumerable<Track> audios,
IEnumerable<Track> subtitles) IEnumerable<Track> subtitles,
Track video)
: this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path) : this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path)
{ {
Audios = audios; Audios = audios;
Subtitles = subtitles; Subtitles = subtitles;
Video = video;
} }
public WatchItem(Episode episode) public WatchItem(Episode episode)
@ -74,7 +77,10 @@ namespace Kyoo.Models
episode.EpisodeNumber, episode.EpisodeNumber,
episode.Title, episode.Title,
episode.ReleaseDate, episode.ReleaseDate,
episode.Path) episode.Path,
episode.Tracks.Where(x => x.Type == StreamType.Audio),
episode.Tracks.Where(x => x.Type == StreamType.Subtitle),
episode.Tracks.FirstOrDefault(x => x.Type == StreamType.Video))
{ {
if (EpisodeNumber > 1) if (EpisodeNumber > 1)
PreviousEpisode = episode.Season.Episodes.FirstOrDefault(x => x.EpisodeNumber == EpisodeNumber - 1); PreviousEpisode = episode.Season.Episodes.FirstOrDefault(x => x.EpisodeNumber == EpisodeNumber - 1);

View File

@ -70,6 +70,9 @@ namespace Kyoo.Controllers
if (obj.ExternalIDs != null) if (obj.ExternalIDs != null)
foreach (MetadataID entry in obj.ExternalIDs) foreach (MetadataID entry in obj.ExternalIDs)
_database.Entry(entry).State = EntityState.Added; _database.Entry(entry).State = EntityState.Added;
if (obj.Tracks != null)
foreach (Track entry in obj.Tracks)
_database.Entry(entry).State = EntityState.Added;
await _database.SaveChangesAsync(); await _database.SaveChangesAsync();
return obj.ID; return obj.ID;
} }

View File

@ -52,7 +52,6 @@ namespace Kyoo.Controllers
if (obj.EpisodeID <= 0) if (obj.EpisodeID <= 0)
throw new InvalidOperationException($"Can't store a track not related to any episode (episodeID: {obj.EpisodeID})."); throw new InvalidOperationException($"Can't store a track not related to any episode (episodeID: {obj.EpisodeID}).");
obj.Episode = null;
await _database.Tracks.AddAsync(obj); await _database.Tracks.AddAsync(obj);
await _database.SaveChangesAsync(); await _database.SaveChangesAsync();
return obj.ID; return obj.ID;

@ -1 +1 @@
Subproject commit c34f62601a0561d0c35edec87f952d7ff6521e68 Subproject commit fffb6690fc5db161767753d1fc554be04eb732d4