move desktop search

This commit is contained in:
Luke Pulverenti 2015-01-21 14:21:19 -05:00
parent 6ccd86d0c1
commit 7bc370bdc7
3 changed files with 20 additions and 2 deletions

View File

@ -1,4 +1,5 @@
using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -10,7 +11,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles
{ {
public class SrtParser : ISubtitleParser public class SrtParser : ISubtitleParser
{ {
private readonly ILogger _logger;
private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public SrtParser(ILogger logger)
{
_logger = logger;
}
public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken) public SubtitleTrackInfo Parse(Stream stream, CancellationToken cancellationToken)
{ {
var trackInfo = new SubtitleTrackInfo(); var trackInfo = new SubtitleTrackInfo();
@ -34,6 +43,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
} }
var time = Regex.Split(line, @"[\t ]*-->[\t ]*"); var time = Regex.Split(line, @"[\t ]*-->[\t ]*");
if (time.Length < 2)
{
// This occurs when subtitle text has an empty line as part of the text.
// Need to adjust the break statement below to resolve this.
_logger.Warn("Unrecognized line in srt: {0}", line);
continue;
}
subEvent.StartPositionTicks = GetTicks(time[0]); subEvent.StartPositionTicks = GetTicks(time[0]);
var endTime = time[1]; var endTime = time[1];
var idx = endTime.IndexOf(" ", StringComparison.Ordinal); var idx = endTime.IndexOf(" ", StringComparison.Ordinal);

View File

@ -270,7 +270,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase)) if (string.Equals(format, SubtitleFormat.SRT, StringComparison.OrdinalIgnoreCase))
{ {
return new SrtParser(); return new SrtParser(_logger);
} }
if (string.Equals(format, SubtitleFormat.SSA, StringComparison.OrdinalIgnoreCase)) if (string.Equals(format, SubtitleFormat.SSA, StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using MediaBrowser.MediaEncoding.Subtitles; using MediaBrowser.MediaEncoding.Subtitles;
using MediaBrowser.Model.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MediaBrowser.Tests.MediaEncoding.Subtitles namespace MediaBrowser.Tests.MediaEncoding.Subtitles
@ -92,7 +93,7 @@ namespace MediaBrowser.Tests.MediaEncoding.Subtitles
} }
}; };
var sut = new SrtParser(); var sut = new SrtParser(new NullLogger());
var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\unit.srt"); var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\unit.srt");