remove <br/> from parsed subtitles

This commit is contained in:
Luke Pulverenti 2014-06-13 10:24:14 -04:00
parent 14216d1089
commit 6186618f3e
9 changed files with 44 additions and 14 deletions

View File

@ -216,7 +216,8 @@ namespace MediaBrowser.Api
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = ImageRefreshMode.FullRefresh,
ReplaceAllMetadata = true
ReplaceAllMetadata = true,
ReplaceAllImages = true
}, CancellationToken.None);

View File

@ -491,6 +491,7 @@ namespace MediaBrowser.Api.Playback
assSubtitleParam = GetTextSubtitleParam(state, cancellationToken);
copyTsParam = " -copyts";
}
//copyTsParam = " -copyts";
// If fixed dimensions were supplied
if (request.Width.HasValue && request.Height.HasValue)

View File

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Providers
{
@ -23,9 +25,20 @@ namespace MediaBrowser.Controller.Providers
public ImageRefreshMode ImageRefreshMode { get; set; }
public IDirectoryService DirectoryService { get; set; }
public bool ReplaceAllImages { get; set; }
public List<ImageType> ReplaceImages { get; set; }
public ImageRefreshOptions()
{
ImageRefreshMode = ImageRefreshMode.Default;
ReplaceImages = new List<ImageType>();
}
public bool IsReplacingImage(ImageType type)
{
return ReplaceAllImages || ReplaceImages.Contains(type);
}
}

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
@ -54,7 +53,6 @@ namespace MediaBrowser.MediaEncoding.Subtitles
subEvent.Text = Regex.Replace(subEvent.Text, "<", "&lt;", RegexOptions.IgnoreCase);
subEvent.Text = Regex.Replace(subEvent.Text, ">", "&gt;", RegexOptions.IgnoreCase);
subEvent.Text = Regex.Replace(subEvent.Text, "&lt;(\\/?(font|b|u|i|s))((\\s+(\\w|\\w[\\w\\-]*\\w)(\\s*=\\s*(?:\\\".*?\\\"|'.*?'|[^'\\\">\\s]+))?)+\\s*|\\s*)(\\/?)&gt;", "<$1$3$7>", RegexOptions.IgnoreCase);
subEvent.Text = Regex.Replace(subEvent.Text, @"\\N", "<br />",RegexOptions.IgnoreCase);
trackInfo.TrackEvents.Add(subEvent);
}
}

View File

@ -43,7 +43,6 @@ namespace MediaBrowser.MediaEncoding.Subtitles
subEvent.EndPositionTicks = GetTicks(sections[headers["End"]]);
subEvent.Text = string.Join(",", sections.Skip(headers["Text"]));
subEvent.Text = Regex.Replace(subEvent.Text, @"\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}", string.Empty, RegexOptions.IgnoreCase);
subEvent.Text = Regex.Replace(subEvent.Text, @"\\N", "<br />", RegexOptions.IgnoreCase);
trackInfo.TrackEvents.Add(subEvent);
}

View File

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
namespace MediaBrowser.MediaEncoding.Subtitles
@ -19,7 +20,10 @@ namespace MediaBrowser.MediaEncoding.Subtitles
cancellationToken.ThrowIfCancellationRequested();
writer.WriteLine(@"{0:hh\:mm\:ss\.fff} --> {1:hh\:mm\:ss\.fff}", TimeSpan.FromTicks(trackEvent.StartPositionTicks), TimeSpan.FromTicks(trackEvent.EndPositionTicks));
writer.WriteLine(trackEvent.Text);
var text = Regex.Replace(trackEvent.Text, @"\\N", "<br />", RegexOptions.IgnoreCase);
writer.WriteLine(text);
writer.WriteLine(string.Empty);
}
}

View File

@ -78,7 +78,7 @@ namespace MediaBrowser.Providers.Manager
if (dynamicImageProvider != null)
{
await RefreshFromProvider(item, dynamicImageProvider, savedOptions, result, cancellationToken).ConfigureAwait(false);
await RefreshFromProvider(item, dynamicImageProvider, refreshOptions, savedOptions, result, cancellationToken).ConfigureAwait(false);
providerIds.Add(provider.GetType().FullName.GetMD5());
}
}
@ -93,11 +93,17 @@ namespace MediaBrowser.Providers.Manager
/// </summary>
/// <param name="item">The item.</param>
/// <param name="provider">The provider.</param>
/// <param name="refreshOptions">The refresh options.</param>
/// <param name="savedOptions">The saved options.</param>
/// <param name="result">The result.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
private async Task RefreshFromProvider(IHasImages item, IDynamicImageProvider provider, MetadataOptions savedOptions, RefreshResult result, CancellationToken cancellationToken)
private async Task RefreshFromProvider(IHasImages item,
IDynamicImageProvider provider,
ImageRefreshOptions refreshOptions,
MetadataOptions savedOptions,
RefreshResult result,
CancellationToken cancellationToken)
{
try
{
@ -105,7 +111,8 @@ namespace MediaBrowser.Providers.Manager
foreach (var imageType in images)
{
if (!item.HasImage(imageType) && savedOptions.IsEnabled(imageType))
if (savedOptions.IsEnabled(imageType) &&
(!item.HasImage(imageType) || refreshOptions.IsReplacingImage(imageType)))
{
_logger.Debug("Running {0} for {1}", provider.GetType().Name, item.Path ?? item.Name);

View File

@ -240,11 +240,18 @@ namespace MediaBrowser.Providers.MediaInfo
if (options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh ||
options.MetadataRefreshMode == MetadataRefreshMode.EnsureMetadata)
{
var remoteChapters = await DownloadChapters(video, chapters, cancellationToken).ConfigureAwait(false);
if (remoteChapters.Count > 0)
try
{
chapters = remoteChapters;
var remoteChapters = await DownloadChapters(video, chapters, cancellationToken).ConfigureAwait(false);
if (remoteChapters.Count > 0)
{
chapters = remoteChapters;
}
}
catch (Exception ex)
{
_logger.ErrorException("Error downloading chapters", ex);
}
if (chapters.Count == 0 && mediaStreams.Any(i => i.Type == MediaStreamType.Video))

View File

@ -733,7 +733,7 @@
"OptionReportByteRangeSeekingWhenTranscodingHelp": "This is required for some devices that don't time seek very well.",
"HeaderSubtitleDownloadingHelp": "When Media Browser scans your video files it can search for missing subtitles, and download them using a subtitle provider such as OpenSubtitles.org.",
"HeaderDownloadSubtitlesFor": "Download subtitles for:",
"MessageNoChapterProviders": "Install a chapter provider plugin such as ChapterDb or tagChimp to enable additional chapter options.",
"MessageNoChapterProviders": "Install a chapter provider plugin such as ChapterDb to enable additional chapter options.",
"LabelSkipIfGraphicalSubsPresent": "Skip if the video already contains graphical subtitles",
"LabelSkipIfGraphicalSubsPresentHelp": "Keeping text versions of subtitles will result in more efficient delivery to mobile clients.",
"TabSubtitles": "Subtitles",
@ -741,7 +741,7 @@
"HeaderDownloadChaptersFor": "Download chapter names for:",
"LabelOpenSubtitlesUsername": "Open Subtitles username:",
"LabelOpenSubtitlesPassword": "Open Subtitles password:",
"HeaderChapterDownloadingHelp": "When Media Browser scans your video files it can download friendly chapter names from the internet using chapter plugins such as ChapterDb and tagChimp.",
"HeaderChapterDownloadingHelp": "When Media Browser scans your video files it can download friendly chapter names from the internet using chapter plugins such as ChapterDb.",
"LabelPlayDefaultAudioTrack": "Play default audio track regardless of language",
"LabelSubtitlePlaybackMode": "Subtitle mode:",
"LabelDownloadLanguages": "Download languages:",