aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Providers')
-rw-r--r--MediaBrowser.Providers/MediaBrowser.Providers.csproj3
-rw-r--r--MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs19
-rw-r--r--MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs30
-rw-r--r--MediaBrowser.Providers/Subtitles/ConfigurationExtension.cs29
-rw-r--r--MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs35
-rw-r--r--MediaBrowser.Providers/Subtitles/SubtitleManager.cs69
6 files changed, 140 insertions, 45 deletions
diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
index 76a1e52f5b..66188f796a 100644
--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj
+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
@@ -152,6 +152,7 @@
<Compile Include="Manager\ProviderUtils.cs" />
<Compile Include="Studios\StudiosImageProvider.cs" />
<Compile Include="Studios\StudioMetadataService.cs" />
+ <Compile Include="Subtitles\ConfigurationExtension.cs" />
<Compile Include="Subtitles\OpenSubtitleDownloader.cs" />
<Compile Include="Subtitles\SubtitleManager.cs" />
<Compile Include="TV\EpisodeMetadataService.cs" />
@@ -213,4 +214,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project> \ No newline at end of file
diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs
index a2e1ba05a7..f48707582c 100644
--- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs
+++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs
@@ -13,10 +13,12 @@ using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Subtitles;
+using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo;
+using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
@@ -464,6 +466,11 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
+ private SubtitleOptions GetOptions()
+ {
+ return _config.GetConfiguration<SubtitleOptions>("subtitles");
+ }
+
/// <summary>
/// Adds the external subtitles.
/// </summary>
@@ -484,9 +491,11 @@ namespace MediaBrowser.Providers.MediaInfo
var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default ||
options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;
- if (enableSubtitleDownloading && (_config.Configuration.SubtitleOptions.DownloadEpisodeSubtitles &&
+ var subtitleOptions = GetOptions();
+
+ if (enableSubtitleDownloading && (subtitleOptions.DownloadEpisodeSubtitles &&
video is Episode) ||
- (_config.Configuration.SubtitleOptions.DownloadMovieSubtitles &&
+ (subtitleOptions.DownloadMovieSubtitles &&
video is Movie))
{
var downloadedLanguages = await new SubtitleDownloader(_logger,
@@ -494,9 +503,9 @@ namespace MediaBrowser.Providers.MediaInfo
.DownloadSubtitles(video,
currentStreams,
externalSubtitleStreams,
- _config.Configuration.SubtitleOptions.SkipIfGraphicalSubtitlesPresent,
- _config.Configuration.SubtitleOptions.SkipIfAudioTrackMatches,
- _config.Configuration.SubtitleOptions.DownloadLanguages,
+ subtitleOptions.SkipIfGraphicalSubtitlesPresent,
+ subtitleOptions.SkipIfAudioTrackMatches,
+ subtitleOptions.DownloadLanguages,
cancellationToken).ConfigureAwait(false);
// Rescan
diff --git a/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs b/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs
index 361cc317c2..63df3f50d5 100644
--- a/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs
+++ b/MediaBrowser.Providers/MediaInfo/SubtitleScheduledTask.cs
@@ -1,10 +1,12 @@
-using MediaBrowser.Common.ScheduledTasks;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Subtitles;
+using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
@@ -12,6 +14,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.MediaInfo
{
@@ -45,8 +48,15 @@ namespace MediaBrowser.Providers.MediaInfo
get { return "Library"; }
}
+ private SubtitleOptions GetOptions()
+ {
+ return _config.GetConfiguration<SubtitleOptions>("subtitles");
+ }
+
public async Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
+ var options = GetOptions();
+
var videos = _libraryManager.RootFolder
.RecursiveChildren
.OfType<Video>()
@@ -57,9 +67,9 @@ namespace MediaBrowser.Providers.MediaInfo
return false;
}
- return (_config.Configuration.SubtitleOptions.DownloadEpisodeSubtitles &&
+ return (options.DownloadEpisodeSubtitles &&
i is Episode) ||
- (_config.Configuration.SubtitleOptions.DownloadMovieSubtitles &&
+ (options.DownloadMovieSubtitles &&
i is Movie);
})
.ToList();
@@ -70,7 +80,7 @@ namespace MediaBrowser.Providers.MediaInfo
{
try
{
- await DownloadSubtitles(video, cancellationToken).ConfigureAwait(false);
+ await DownloadSubtitles(video, options, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -86,11 +96,11 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
- private async Task DownloadSubtitles(Video video, CancellationToken cancellationToken)
+ private async Task DownloadSubtitles(Video video, SubtitleOptions options, CancellationToken cancellationToken)
{
- if ((_config.Configuration.SubtitleOptions.DownloadEpisodeSubtitles &&
+ if ((options.DownloadEpisodeSubtitles &&
video is Episode) ||
- (_config.Configuration.SubtitleOptions.DownloadMovieSubtitles &&
+ (options.DownloadMovieSubtitles &&
video is Movie))
{
var mediaStreams = video.GetMediaSources(false).First().MediaStreams;
@@ -103,9 +113,9 @@ namespace MediaBrowser.Providers.MediaInfo
.DownloadSubtitles(video,
currentStreams,
externalSubtitleStreams,
- _config.Configuration.SubtitleOptions.SkipIfGraphicalSubtitlesPresent,
- _config.Configuration.SubtitleOptions.SkipIfAudioTrackMatches,
- _config.Configuration.SubtitleOptions.DownloadLanguages,
+ options.SkipIfGraphicalSubtitlesPresent,
+ options.SkipIfAudioTrackMatches,
+ options.DownloadLanguages,
cancellationToken).ConfigureAwait(false);
// Rescan
diff --git a/MediaBrowser.Providers/Subtitles/ConfigurationExtension.cs b/MediaBrowser.Providers/Subtitles/ConfigurationExtension.cs
new file mode 100644
index 0000000000..f520915d8b
--- /dev/null
+++ b/MediaBrowser.Providers/Subtitles/ConfigurationExtension.cs
@@ -0,0 +1,29 @@
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Model.Providers;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Providers.Subtitles
+{
+ public static class ConfigurationExtension
+ {
+ public static SubtitleOptions GetSubtitleConfiguration(this IConfigurationManager manager)
+ {
+ return manager.GetConfiguration<SubtitleOptions>("subtitles");
+ }
+ }
+
+ public class SubtitleConfigurationFactory : IConfigurationFactory
+ {
+ public IEnumerable<ConfigurationStore> GetConfigurations()
+ {
+ return new List<ConfigurationStore>
+ {
+ new ConfigurationStore
+ {
+ Key = "subtitles",
+ ConfigurationType = typeof (SubtitleOptions)
+ }
+ };
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs
index c25fbee6fb..722d0d3f3e 100644
--- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs
+++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Providers;
@@ -6,7 +7,6 @@ using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Events;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Providers;
using OpenSubtitlesHandler;
@@ -45,16 +45,21 @@ namespace MediaBrowser.Providers.Subtitles
_config = config;
_encryption = encryption;
- _config.ConfigurationUpdating += _config_ConfigurationUpdating;
+ _config.NamedConfigurationUpdating += _config_NamedConfigurationUpdating;
// Reset the count every 24 hours
_dailyTimer = new Timer(state => _dailyDownloadCount = 0, null, TimeSpan.FromHours(24), TimeSpan.FromHours(24));
}
private const string PasswordHashPrefix = "h:";
- void _config_ConfigurationUpdating(object sender, GenericEventArgs<ServerConfiguration> e)
+ void _config_NamedConfigurationUpdating(object sender, ConfigurationUpdateEventArgs e)
{
- var options = e.Argument.SubtitleOptions;
+ if (!string.Equals(e.Key, "subtitles", StringComparison.OrdinalIgnoreCase))
+ {
+ return;
+ }
+
+ var options = (SubtitleOptions)e.NewConfiguration;
if (options != null &&
!string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash) &&
@@ -85,12 +90,19 @@ namespace MediaBrowser.Providers.Subtitles
get { return "Open Subtitles"; }
}
+ private SubtitleOptions GetOptions()
+ {
+ return _config.GetSubtitleConfiguration();
+ }
+
public IEnumerable<VideoContentType> SupportedMediaTypes
{
get
{
- if (string.IsNullOrWhiteSpace(_config.Configuration.SubtitleOptions.OpenSubtitlesUsername) ||
- string.IsNullOrWhiteSpace(_config.Configuration.SubtitleOptions.OpenSubtitlesPasswordHash))
+ var options = GetOptions();
+
+ if (string.IsNullOrWhiteSpace(options.OpenSubtitlesUsername) ||
+ string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash))
{
return new VideoContentType[] { };
}
@@ -101,10 +113,11 @@ namespace MediaBrowser.Providers.Subtitles
public Task<SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken)
{
- return GetSubtitlesInternal(id, cancellationToken);
+ return GetSubtitlesInternal(id, GetOptions(), cancellationToken);
}
private async Task<SubtitleResponse> GetSubtitlesInternal(string id,
+ SubtitleOptions options,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(id))
@@ -113,7 +126,7 @@ namespace MediaBrowser.Providers.Subtitles
}
if (_dailyDownloadCount >= MaxDownloadsPerDay &&
- !_config.Configuration.SubtitleOptions.IsOpenSubtitleVipAccount)
+ !options.IsOpenSubtitleVipAccount)
{
throw new InvalidOperationException("Open Subtitle's daily download limit has been exceeded. Please try again tomorrow.");
}
@@ -167,7 +180,7 @@ namespace MediaBrowser.Providers.Subtitles
return;
}
- var options = _config.Configuration.SubtitleOptions ?? new SubtitleOptions();
+ var options = GetOptions();
var user = options.OpenSubtitlesUsername ?? string.Empty;
var password = DecryptPassword(options.OpenSubtitlesPasswordHash);
@@ -289,7 +302,7 @@ namespace MediaBrowser.Providers.Subtitles
public void Dispose()
{
- _config.ConfigurationUpdating -= _config_ConfigurationUpdating;
+ _config.NamedConfigurationUpdating -= _config_NamedConfigurationUpdating;
if (_dailyTimer != null)
{
diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs
index 34656f05bc..179ab425b6 100644
--- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs
+++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Extensions;
+using MediaBrowser.Common.Events;
+using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
@@ -28,6 +29,9 @@ namespace MediaBrowser.Providers.Subtitles
private readonly ILibraryManager _libraryManager;
private readonly IItemRepository _itemRepo;
+ public event EventHandler<SubtitleDownloadEventArgs> SubtitlesDownloaded;
+ public event EventHandler<SubtitleDownloadFailureEventArgs> SubtitleDownloadFailure;
+
public SubtitleManager(ILogger logger, IFileSystem fileSystem, ILibraryMonitor monitor, ILibraryManager libraryManager, IItemRepository itemRepo)
{
_logger = logger;
@@ -100,35 +104,63 @@ namespace MediaBrowser.Providers.Subtitles
string subtitleId,
CancellationToken cancellationToken)
{
- var response = await GetRemoteSubtitles(subtitleId, cancellationToken).ConfigureAwait(false);
+ var parts = subtitleId.Split(new[] { '_' }, 2);
+ var provider = GetProvider(parts.First());
- using (var stream = response.Stream)
+ try
{
- var savePath = Path.Combine(Path.GetDirectoryName(video.Path),
- _fileSystem.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLower());
+ var response = await GetRemoteSubtitles(subtitleId, cancellationToken).ConfigureAwait(false);
- if (response.IsForced)
+ using (var stream = response.Stream)
{
- savePath += ".forced";
- }
+ var savePath = Path.Combine(Path.GetDirectoryName(video.Path),
+ _fileSystem.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLower());
- savePath += "." + response.Format.ToLower();
+ if (response.IsForced)
+ {
+ savePath += ".forced";
+ }
- _logger.Info("Saving subtitles to {0}", savePath);
+ savePath += "." + response.Format.ToLower();
- _monitor.ReportFileSystemChangeBeginning(savePath);
+ _logger.Info("Saving subtitles to {0}", savePath);
- try
- {
- using (var fs = _fileSystem.GetFileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
+ _monitor.ReportFileSystemChangeBeginning(savePath);
+
+ try
+ {
+ using (var fs = _fileSystem.GetFileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.Read, true))
+ {
+ await stream.CopyToAsync(fs).ConfigureAwait(false);
+ }
+
+ EventHelper.FireEventIfNotNull(SubtitlesDownloaded, this, new SubtitleDownloadEventArgs
+ {
+ Item = video,
+ Format = response.Format,
+ Language = response.Language,
+ IsForced = response.IsForced,
+ Provider = provider.Name
+
+ }, _logger);
+ }
+ finally
{
- await stream.CopyToAsync(fs).ConfigureAwait(false);
+ _monitor.ReportFileSystemChangeComplete(savePath, false);
}
}
- finally
+ }
+ catch (Exception ex)
+ {
+ EventHelper.FireEventIfNotNull(SubtitleDownloadFailure, this, new SubtitleDownloadFailureEventArgs
{
- _monitor.ReportFileSystemChangeComplete(savePath, false);
- }
+ Item = video,
+ Exception = ex,
+ Provider = provider.Name
+
+ }, _logger);
+
+ throw;
}
}
@@ -267,5 +299,6 @@ namespace MediaBrowser.Providers.Subtitles
Id = GetProviderId(i.Name)
});
}
+
}
}