From e1dd361c7bf05af49d9210ab679e85fa00870990 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 5 May 2014 10:45:45 -0400 Subject: [PATCH] added subtitle parsing stubs --- .../Providers/ISubtitleProvider.cs | 15 ++++++++++--- .../MediaBrowser.MediaEncoding.csproj | 5 +++++ .../Subtitles/ISubtitleParser.cs | 9 ++++++++ .../Subtitles/SrtParser.cs | 17 ++++++++++++++ .../Subtitles/SsaParser.cs | 17 ++++++++++++++ .../Subtitles/SubtitleInfo.cs | 22 +++++++++++++++++++ .../Movies/MovieDbProvider.cs | 2 -- .../Subtitles/OpenSubtitleDownloader.cs | 17 +++++++++++--- 8 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs create mode 100644 MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs create mode 100644 MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs create mode 100644 MediaBrowser.MediaEncoding/Subtitles/SubtitleInfo.cs diff --git a/MediaBrowser.Controller/Providers/ISubtitleProvider.cs b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs index adefea84d2..09ca27e307 100644 --- a/MediaBrowser.Controller/Providers/ISubtitleProvider.cs +++ b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using MediaBrowser.Model.Entities; +using System; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -41,7 +43,7 @@ namespace MediaBrowser.Controller.Providers public Stream Stream { get; set; } } - public class SubtitleRequest + public class SubtitleRequest : IHasProviderIds { public string Language { get; set; } @@ -51,7 +53,14 @@ namespace MediaBrowser.Controller.Providers public string SeriesName { get; set; } public string Name { get; set; } public int? IndexNumber { get; set; } + public int? IndexNumberEnd { get; set; } public int? ParentIndexNumber { get; set; } - public long ImdbId { get; set; } + public int? ProductionYear { get; set; } + public Dictionary ProviderIds { get; set; } + + public SubtitleRequest() + { + ProviderIds = new Dictionary(StringComparer.OrdinalIgnoreCase); + } } } diff --git a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj index e129468d39..291bb0222f 100644 --- a/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj +++ b/MediaBrowser.MediaEncoding/MediaBrowser.MediaEncoding.csproj @@ -61,6 +61,10 @@ + + + + @@ -79,6 +83,7 @@ + diff --git a/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs new file mode 100644 index 0000000000..5e7ad6699a --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/ISubtitleParser.cs @@ -0,0 +1,9 @@ +using System.IO; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public interface ISubtitleParser + { + SubtitleInfo Parse(Stream stream); + } +} diff --git a/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs new file mode 100644 index 0000000000..af0009a82e --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/SrtParser.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class SrtParser + { + public SubtitleInfo Parse(Stream stream) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs new file mode 100644 index 0000000000..e134416b13 --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/SsaParser.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class SsaParser + { + public SubtitleInfo Parse(Stream stream) + { + throw new NotImplementedException(); + } + } +} diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleInfo.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleInfo.cs new file mode 100644 index 0000000000..812b0c7d4c --- /dev/null +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleInfo.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; + +namespace MediaBrowser.MediaEncoding.Subtitles +{ + public class SubtitleInfo + { + public List TrackEvents { get; set; } + + public SubtitleInfo() + { + TrackEvents = new List(); + } + } + + public class SubtitleTrackEvent + { + public string Id { get; set; } + public string Text { get; set; } + public long StartPositionTicks { get; set; } + public long EndPositionTicks { get; set; } + } +} diff --git a/MediaBrowser.Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Providers/Movies/MovieDbProvider.cs index c83e127ae5..d812abe9f6 100644 --- a/MediaBrowser.Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbProvider.cs @@ -356,8 +356,6 @@ namespace MediaBrowser.Providers.Movies await Task.Delay(Convert.ToInt32(diff), cancellationToken).ConfigureAwait(false); } - _lastRequestDate = DateTime.Now; - return await _httpClient.Get(options).ConfigureAwait(false); } finally diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 6025493e79..7309513d63 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; using OpenSubtitlesHandler; @@ -37,13 +38,23 @@ namespace MediaBrowser.Providers.Subtitles public Task GetSubtitles(SubtitleRequest request, CancellationToken cancellationToken) { - return GetMediaSubtitleSubtitles(request, cancellationToken); + return GetSubtitlesInternal(request, cancellationToken); } - public async Task GetMediaSubtitleSubtitles(SubtitleRequest request, CancellationToken cancellationToken) + private async Task GetSubtitlesInternal(SubtitleRequest request, + CancellationToken cancellationToken) { var response = new SubtitleResponse(); + var imdbIdText = request.GetProviderId(MetadataProviders.Imdb); + long imdbId; + + if (string.IsNullOrWhiteSpace(imdbIdText) || + long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId)) + { + return response; + } + switch (request.ContentType) { case SubtitleMediaType.Episode: @@ -102,7 +113,7 @@ namespace MediaBrowser.Providers.Subtitles x => request.ContentType == SubtitleMediaType.Episode ? int.Parse(x.SeriesSeason) == request.ParentIndexNumber && int.Parse(x.SeriesEpisode) == request.IndexNumber - : long.Parse(x.IDMovieImdb) == request.ImdbId; + : long.Parse(x.IDMovieImdb) == imdbId; var results = ((MethodResponseSubtitleSearch)result).Results; var bestResult = results.Where(x => x.SubBad == "0" && mediaFilter(x))