fixed subtitle downloading

This commit is contained in:
Luke Pulverenti
2014-05-08 01:04:39 -04:00
parent 0b7e398772
commit 374dd8d441
11 changed files with 143 additions and 29 deletions

View File

@@ -14,12 +14,12 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Notifications;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Updates;
namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
{
@@ -40,6 +40,9 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
private readonly ISessionManager _sessionManager;
private readonly IServerApplicationHost _appHost;
private Timer LibraryUpdateTimer { get; set; }
private readonly object _libraryChangedSyncLock = new object();
public Notifications(IInstallationManager installationManager, IUserManager userManager, ILogger logger, ITaskManager taskManager, INotificationManager notificationManager, IServerConfigurationManager config, ILibraryManager libraryManager, ISessionManager sessionManager, IServerApplicationHost appHost)
{
_installationManager = installationManager;
@@ -210,21 +213,55 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
return null;
}
async void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
private readonly List<BaseItem> _itemsAdded = new List<BaseItem>();
void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
{
if (e.Item.LocationType == LocationType.FileSystem)
if (e.Item.LocationType == LocationType.FileSystem && !e.Item.IsFolder)
{
var type = NotificationType.NewLibraryContent.ToString();
lock (_libraryChangedSyncLock)
{
if (LibraryUpdateTimer == null)
{
LibraryUpdateTimer = new Timer(LibraryUpdateTimerCallback, null, 5000,
Timeout.Infinite);
}
else
{
LibraryUpdateTimer.Change(5000, Timeout.Infinite);
}
var item = e.Item;
_itemsAdded.Add(e.Item);
}
}
}
private async void LibraryUpdateTimerCallback(object state)
{
List<BaseItem> items;
lock (_libraryChangedSyncLock)
{
items = _itemsAdded.ToList();
_itemsAdded.Clear();
DisposeLibraryUpdateTimer();
}
var item = items.FirstOrDefault();
if (item != null)
{
var notification = new NotificationRequest
{
NotificationType = type
NotificationType = NotificationType.NewLibraryContent.ToString()
};
notification.Variables["Name"] = item.Name;
if (items.Count > 1)
{
notification.Name = items.Count + " new library items.";
}
await SendNotification(notification).ConfigureAwait(false);
}
}
@@ -313,6 +350,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
public void Dispose()
{
DisposeLibraryUpdateTimer();
_installationManager.PluginInstalled -= _installationManager_PluginInstalled;
_installationManager.PluginUpdated -= _installationManager_PluginUpdated;
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
@@ -328,5 +367,14 @@ namespace MediaBrowser.Server.Implementations.EntryPoints.Notifications
_appHost.HasUpdateAvailableChanged -= _appHost_HasUpdateAvailableChanged;
_appHost.ApplicationUpdated -= _appHost_ApplicationUpdated;
}
private void DisposeLibraryUpdateTimer()
{
if (LibraryUpdateTimer != null)
{
LibraryUpdateTimer.Dispose();
LibraryUpdateTimer = null;
}
}
}
}

View File

@@ -715,6 +715,6 @@
"LabelAudioLanguagePreferenceHelp": "If empty, the default audio track will be selected, regardless of language.",
"LabelDownloadLanguages": "Download languages:",
"ButtonRegister": "Register",
"LabelSkipIfAudioTrackPresent": "Skip if the video has an audio track with the download language",
"LabelSkipIfAudioTrackPresent": "Skip if the default audio track matches the download language",
"LabelSkipIfAudioTrackPresentHelp": "Uncheck this to ensure all videos have subtitles, regardless of audio language."
}

File diff suppressed because one or more lines are too long

View File

@@ -48,6 +48,7 @@ namespace MediaBrowser.Server.Implementations.Session
private readonly IMusicManager _musicManager;
private readonly IDtoService _dtoService;
private readonly IImageProcessor _imageProcessor;
private readonly IItemRepository _itemRepo;
/// <summary>
/// Gets or sets the configuration manager.
@@ -90,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Session
/// <param name="logger">The logger.</param>
/// <param name="userRepository">The user repository.</param>
/// <param name="libraryManager">The library manager.</param>
public SessionManager(IUserDataManager userDataRepository, IServerConfigurationManager configurationManager, ILogger logger, IUserRepository userRepository, ILibraryManager libraryManager, IUserManager userManager, IMusicManager musicManager, IDtoService dtoService, IImageProcessor imageProcessor)
public SessionManager(IUserDataManager userDataRepository, IServerConfigurationManager configurationManager, ILogger logger, IUserRepository userRepository, ILibraryManager libraryManager, IUserManager userManager, IMusicManager musicManager, IDtoService dtoService, IImageProcessor imageProcessor, IItemRepository itemRepo)
{
_userDataRepository = userDataRepository;
_configurationManager = configurationManager;
@@ -101,6 +102,7 @@ namespace MediaBrowser.Server.Implementations.Session
_musicManager = musicManager;
_dtoService = dtoService;
_imageProcessor = imageProcessor;
_itemRepo = itemRepo;
}
/// <summary>
@@ -279,7 +281,7 @@ namespace MediaBrowser.Server.Implementations.Session
if (!string.IsNullOrWhiteSpace(info.ItemId) && libraryItem != null)
{
info.Item = GetItemInfo(libraryItem, runtimeTicks);
info.Item = GetItemInfo(libraryItem, runtimeTicks, libraryItem, info.MediaSourceId);
}
session.NowPlayingItem = info.Item;
@@ -1172,9 +1174,11 @@ namespace MediaBrowser.Server.Implementations.Session
/// </summary>
/// <param name="item">The item.</param>
/// <param name="runtimeTicks">The now playing runtime ticks.</param>
/// <param name="chapterOwner">The chapter owner.</param>
/// <param name="mediaSourceId">The media source identifier.</param>
/// <returns>BaseItemInfo.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
private BaseItemInfo GetItemInfo(BaseItem item, long? runtimeTicks)
private BaseItemInfo GetItemInfo(BaseItem item, long? runtimeTicks, BaseItem chapterOwner, string mediaSourceId)
{
if (item == null)
{
@@ -1322,6 +1326,22 @@ namespace MediaBrowser.Server.Implementations.Session
info.LogoItemId = GetDtoId(logoItem);
}
if (chapterOwner != null)
{
info.ChapterImagesItemId = chapterOwner.Id.ToString("N");
info.Chapters = _itemRepo.GetChapters(chapterOwner.Id).Select(i => _dtoService.GetChapterInfoDto(i, chapterOwner)).ToList();
}
if (!string.IsNullOrWhiteSpace(mediaSourceId))
{
info.MediaStreams = _itemRepo.GetMediaStreams(new MediaStreamQuery
{
ItemId = new Guid(mediaSourceId)
}).ToList();
}
return info;
}
@@ -1347,7 +1367,7 @@ namespace MediaBrowser.Server.Implementations.Session
{
var item = _libraryManager.GetItemById(new Guid(itemId));
var info = GetItemInfo(item, item.RunTimeTicks);
var info = GetItemInfo(item, item.RunTimeTicks, null, null);
ReportNowViewingItem(sessionId, info);
}