added subtitle parsing stubs

This commit is contained in:
Luke Pulverenti 2014-05-05 10:45:45 -04:00
parent 28f7aa5b5e
commit e1dd361c7b
8 changed files with 96 additions and 8 deletions

View File

@ -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<string, string> ProviderIds { get; set; }
public SubtitleRequest()
{
ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
}
}

View File

@ -61,6 +61,10 @@
<Compile Include="Encoder\InternalEncodingTaskFactory.cs" />
<Compile Include="Encoder\MediaEncoder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Subtitles\ISubtitleParser.cs" />
<Compile Include="Subtitles\SrtParser.cs" />
<Compile Include="Subtitles\SsaParser.cs" />
<Compile Include="Subtitles\SubtitleInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj">
@ -79,6 +83,7 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@ -0,0 +1,9 @@
using System.IO;
namespace MediaBrowser.MediaEncoding.Subtitles
{
public interface ISubtitleParser
{
SubtitleInfo Parse(Stream stream);
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace MediaBrowser.MediaEncoding.Subtitles
{
public class SubtitleInfo
{
public List<SubtitleTrackEvent> TrackEvents { get; set; }
public SubtitleInfo()
{
TrackEvents = new List<SubtitleTrackEvent>();
}
}
public class SubtitleTrackEvent
{
public string Id { get; set; }
public string Text { get; set; }
public long StartPositionTicks { get; set; }
public long EndPositionTicks { get; set; }
}
}

View File

@ -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

View File

@ -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<SubtitleResponse> GetSubtitles(SubtitleRequest request, CancellationToken cancellationToken)
{
return GetMediaSubtitleSubtitles(request, cancellationToken);
return GetSubtitlesInternal(request, cancellationToken);
}
public async Task<SubtitleResponse> GetMediaSubtitleSubtitles(SubtitleRequest request, CancellationToken cancellationToken)
private async Task<SubtitleResponse> 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))