mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 05:34:23 -04:00
Adding a subtitle extraction check.
This commit is contained in:
parent
2c1ec1812a
commit
1f5a589f96
@ -143,20 +143,60 @@ namespace Kyoo.InternalAPI
|
||||
episode.ShowID = showID;
|
||||
episode.SeasonID = seasonID;
|
||||
long episodeID = libraryManager.RegisterEpisode(episode);
|
||||
episode.id = episodeID;
|
||||
|
||||
if (episode.Path.EndsWith(".mkv"))
|
||||
{
|
||||
Track[] tracks = transcoder.ExtractSubtitles(episode.Path);
|
||||
foreach (Track track in tracks)
|
||||
if (!FindExtractedSubtitles(episode))
|
||||
{
|
||||
track.episodeID = episodeID;
|
||||
libraryManager.RegisterTrack(track);
|
||||
Track[] tracks = transcoder.ExtractSubtitles(episode.Path);
|
||||
foreach (Track track in tracks)
|
||||
{
|
||||
track.episodeID = episode.id;
|
||||
libraryManager.RegisterTrack(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool FindExtractedSubtitles(Episode episode)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(episode.Path), "Subtitles");
|
||||
if(Directory.Exists(path))
|
||||
{
|
||||
foreach (string sub in Directory.EnumerateFiles(path, "", SearchOption.AllDirectories))
|
||||
{
|
||||
string language = sub.Substring(Path.GetDirectoryName(sub).Length + Path.GetFileNameWithoutExtension(episode.Path).Length + 2, 3);
|
||||
bool isDefault = sub.Contains("default");
|
||||
bool isForced = sub.Contains("forced");
|
||||
|
||||
string codec;
|
||||
switch (Path.GetExtension(sub))
|
||||
{
|
||||
case ".ass":
|
||||
codec = "ass";
|
||||
break;
|
||||
case ".str":
|
||||
codec = "subrip";
|
||||
break;
|
||||
default:
|
||||
codec = null;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Track track = new Track(Models.Watch.StreamType.Subtitle, null, language, isDefault, isForced, codec, false, sub) { episodeID = episode.id };
|
||||
libraryManager.RegisterTrack(track);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static readonly string[] videoExtensions = { ".webm", ".mkv", ".flv", ".vob", ".ogg", ".ogv", ".avi", ".mts", ".m2ts", ".ts", ".mov", ".qt", ".asf", ".mp4", ".m4p", ".m4v", ".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".m2v", ".3gp", ".3g2" };
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace Kyoo.Models
|
||||
{
|
||||
public class Episode
|
||||
{
|
||||
[JsonIgnore] public readonly long id;
|
||||
[JsonIgnore] public long id;
|
||||
[JsonIgnore] public long ShowID;
|
||||
[JsonIgnore] public long SeasonID;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user