Skip to content

Commit

Permalink
Merge pull request #3251 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
update image refresh
  • Loading branch information
LukePulverenti authored Apr 28, 2018
2 parents a8529ef + ec528d6 commit eb03055
Show file tree
Hide file tree
Showing 53 changed files with 786 additions and 118 deletions.
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ protected void RegisterResources()
var newsService = new Emby.Server.Implementations.News.NewsService(ApplicationPaths, JsonSerializer);
RegisterSingleInstance<INewsService>(newsService);

MediaSourceManager = new MediaSourceManager(ItemRepository, LocalizationManager, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager, UserDataManager, TimerFactory, () => MediaEncoder);
MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager, UserDataManager, TimerFactory, () => MediaEncoder);
RegisterSingleInstance(MediaSourceManager);

SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, MediaSourceManager, ServerConfigurationManager, LocalizationManager);
Expand Down
152 changes: 151 additions & 1 deletion Emby.Server.Implementations/Library/MediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
using MediaBrowser.Model.Threading;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Globalization;
using System.IO;
using System.Globalization;
using MediaBrowser.Common.Configuration;

namespace Emby.Server.Implementations.Library
{
Expand All @@ -36,8 +39,9 @@ public class MediaSourceManager : IMediaSourceManager, IDisposable
private readonly ITimerFactory _timerFactory;
private readonly Func<IMediaEncoder> _mediaEncoder;
private ILocalizationManager _localizationManager;
private IApplicationPaths _appPaths;

public MediaSourceManager(IItemRepository itemRepo, ILocalizationManager localizationManager, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem, IUserDataManager userDataManager, ITimerFactory timerFactory, Func<IMediaEncoder> mediaEncoder)
public MediaSourceManager(IItemRepository itemRepo, IApplicationPaths applicationPaths, ILocalizationManager localizationManager, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem, IUserDataManager userDataManager, ITimerFactory timerFactory, Func<IMediaEncoder> mediaEncoder)
{
_itemRepo = itemRepo;
_userManager = userManager;
Expand All @@ -49,6 +53,7 @@ public MediaSourceManager(IItemRepository itemRepo, ILocalizationManager localiz
_timerFactory = timerFactory;
_mediaEncoder = mediaEncoder;
_localizationManager = localizationManager;
_appPaths = applicationPaths;
}

public void AddParts(IEnumerable<IMediaSourceProvider> providers)
Expand Down Expand Up @@ -496,6 +501,151 @@ public async Task<MediaSourceInfo> GetLiveStreamMediaInfo(string id, Cancellatio
return mediaSource;
}

public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken)
{
var originalRuntime = mediaSource.RunTimeTicks;

var now = DateTime.UtcNow;

MediaInfo mediaInfo = null;
var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "mediainfo", cacheKey.GetMD5().ToString("N") + ".json");

if (!string.IsNullOrEmpty(cacheKey))
{
try
{
mediaInfo = _jsonSerializer.DeserializeFromFile<MediaInfo>(cacheFilePath);

//_logger.Debug("Found cached media info");
}
catch (Exception ex)
{
}
}

if (mediaInfo == null)
{
if (addProbeDelay)
{
var delayMs = mediaSource.AnalyzeDurationMs ?? 0;
delayMs = Math.Max(3000, delayMs);
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
}

if (isLiveStream)
{
mediaSource.AnalyzeDurationMs = 3000;
}

mediaInfo = await _mediaEncoder().GetMediaInfo(new MediaInfoRequest
{
MediaSource = mediaSource,
MediaType = isAudio ? DlnaProfileType.Audio : DlnaProfileType.Video,
ExtractChapters = false

}, cancellationToken).ConfigureAwait(false);

if (cacheFilePath != null)
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
_jsonSerializer.SerializeToFile(mediaInfo, cacheFilePath);

//_logger.Debug("Saved media info to {0}", cacheFilePath);
}
}

var mediaStreams = mediaInfo.MediaStreams;

if (isLiveStream && !string.IsNullOrEmpty(cacheKey))
{
var newList = new List<MediaStream>();
newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Video).Take(1));
newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Audio).Take(1));

foreach (var stream in newList)
{
stream.Index = -1;
stream.Language = null;
}

mediaStreams = newList;
}

_logger.Info("Live tv media info probe took {0} seconds", (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture));

mediaSource.Bitrate = mediaInfo.Bitrate;
mediaSource.Container = mediaInfo.Container;
mediaSource.Formats = mediaInfo.Formats;
mediaSource.MediaStreams = mediaStreams;
mediaSource.RunTimeTicks = mediaInfo.RunTimeTicks;
mediaSource.Size = mediaInfo.Size;
mediaSource.Timestamp = mediaInfo.Timestamp;
mediaSource.Video3DFormat = mediaInfo.Video3DFormat;
mediaSource.VideoType = mediaInfo.VideoType;

mediaSource.DefaultSubtitleStreamIndex = null;

if (isLiveStream)
{
// Null this out so that it will be treated like a live stream
if (!originalRuntime.HasValue)
{
mediaSource.RunTimeTicks = null;
}
}

var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);

if (audioStream == null || audioStream.Index == -1)
{
mediaSource.DefaultAudioStreamIndex = null;
}
else
{
mediaSource.DefaultAudioStreamIndex = audioStream.Index;
}

var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
if (videoStream != null)
{
if (!videoStream.BitRate.HasValue)
{
var width = videoStream.Width ?? 1920;

if (width >= 3000)
{
videoStream.BitRate = 30000000;
}

else if (width >= 1900)
{
videoStream.BitRate = 20000000;
}

else if (width >= 1200)
{
videoStream.BitRate = 8000000;
}

else if (width >= 700)
{
videoStream.BitRate = 2000000;
}
}

// This is coming up false and preventing stream copy
videoStream.IsAVC = null;
}

if (isLiveStream)
{
mediaSource.AnalyzeDurationMs = 3000;
}

// Try to estimate this
mediaSource.InferTotalBitrate(true);
}

public async Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> GetLiveStreamWithDirectStreamProvider(string id, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(id))
Expand Down
2 changes: 2 additions & 0 deletions MediaBrowser.Controller/Library/IMediaSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public interface IMediaSourceManager
MediaProtocol GetPathProtocol(string path);

void SetDefaultAudioAndSubtitleStreamIndexes(BaseItem item, MediaSourceInfo source, User user);

Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken);
}

public interface IDirectStreamProvider
Expand Down
4 changes: 3 additions & 1 deletion MediaBrowser.Providers/Manager/ItemImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public bool ValidateImages(BaseItem item, IEnumerable<IImageProvider> providers,
return hasChanges;
}

private static TypeOptions _defaultTypeOptions = new TypeOptions();
public async Task<RefreshResult> RefreshImages(BaseItem item, LibraryOptions libraryOptions, List<IImageProvider> providers, ImageRefreshOptions refreshOptions, MetadataOptions savedOptions, CancellationToken cancellationToken)
{
if (refreshOptions.IsReplacingImage(ImageType.Backdrop))
Expand All @@ -75,7 +76,8 @@ public async Task<RefreshResult> RefreshImages(BaseItem item, LibraryOptions lib

var result = new RefreshResult { UpdateType = ItemUpdateType.None };

var typeOptions = libraryOptions.GetTypeOptions(item.GetType().Name);
var typeName = item.GetType().Name;
var typeOptions = libraryOptions.GetTypeOptions(typeName) ?? _defaultTypeOptions;

// In order to avoid duplicates, only download these if there are none already
var backdropLimit = typeOptions.GetLimit(ImageType.Backdrop);
Expand Down
14 changes: 13 additions & 1 deletion MediaBrowser.WebDashboard/dashboard-ui/strings/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
"General": "General",
"HeaderScreenSavers": "Screen Savers",
"Sync": "Sync",
"Notifications": "Notifications",
"Metadata": "Metadata",
"Channels": "Channels",
"Reporting": "Reporting",
"NextUp": "Next Up",
"ShowAdvancedSettings": "Show advanced settings",
"HeaderEmbyServer": "Emby Server",
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
"HeaderTypeImageFetchers": "{0} Image Fetchers",
"LabelPrevious": "\u0627\u0644\u0633\u0627\u0628\u0642",
"LabelFinish": "\u0627\u0646\u0647\u0627\u0621",
"LabelNext": "\u0627\u0644\u062a\u0627\u0644\u064a",
Expand Down Expand Up @@ -723,7 +735,7 @@
"LabelProtocolInfo": "\u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0648\u062a\u0648\u0643\u0648\u0644:",
"LabelProtocolInfoHelp": "\u0627\u0644\u0642\u064a\u0645\u0629 \u0627\u0644\u062a\u064a \u0633\u062a\u0633\u062a\u062e\u062f\u0645 \u0639\u0646\u062f \u0627\u0644\u0631\u062f \u0639\u0644\u0649 \u0637\u0644\u0628 GetProtocolInfo \u0645\u0646 \u0627\u0644\u062c\u0647\u0627\u0632.",
"TabNfoSettings": "\u0623\u0639\u062f\u0627\u062f\u0627\u062a Nfo",
"HeaderKodiMetadataHelp": "Emby includes native support for Nfo metadata files. To enable or disable Nfo metadata, use the Metadata tab to configure options for your media types.",
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
"LabelKodiMetadataDateFormat": "\u062a\u0646\u0633\u064a\u0642 \u062a\u0627\u0631\u064a\u062e \u0627\u0644\u0625\u0635\u062f\u0627\u0631:",
Expand Down
18 changes: 15 additions & 3 deletions MediaBrowser.WebDashboard/dashboard-ui/strings/be-BY.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
"General": "General",
"HeaderScreenSavers": "Screen Savers",
"Sync": "Sync",
"Notifications": "Notifications",
"Metadata": "Metadata",
"Channels": "Channels",
"Reporting": "Reporting",
"NextUp": "Next Up",
"ShowAdvancedSettings": "Show advanced settings",
"HeaderEmbyServer": "Emby Server",
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
"HeaderTypeImageFetchers": "{0} Image Fetchers",
"LabelPrevious": "\u041f\u0430\u043f\u044f\u0440\u044d\u0434\u043d\u044f\u0435",
"LabelFinish": "\u0413\u0430\u0442\u043e\u0432\u0430",
"LabelNext": "\u041d\u0430\u0441\u0442\u0443\u043f\u043d\u0430\u0435",
Expand Down Expand Up @@ -675,7 +687,7 @@
"LabelMessageText": "Message text:",
"LabelMessageTitle": "Message title:",
"MessageNoAvailablePlugins": "No available plugins.",
"LabelDisplayPluginsFor": "Display plugins for:",
"LabelDisplayPluginsFor": "Show plugins for:",
"PluginTabAppClassic": "Emby for Windows Media Center",
"HeaderTypeText": "Enter Text",
"LabelTypeText": "Text",
Expand Down Expand Up @@ -723,7 +735,7 @@
"LabelProtocolInfo": "Protocol info:",
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
"TabNfoSettings": "Nfo Settings",
"HeaderKodiMetadataHelp": "Emby includes native support for Nfo metadata files. To enable or disable Nfo metadata, use the Metadata tab to configure options for your media types.",
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
"LabelKodiMetadataDateFormat": "Release date format:",
Expand Down Expand Up @@ -1048,7 +1060,7 @@
"HeaderAddDevice": "Add Device",
"HeaderExternalServices": "External Services",
"LabelTunerIpAddress": "Tuner IP Address:",
"HeaderGuideProviders": "Guide Providers",
"HeaderGuideProviders": "TV Guide Data Providers",
"AddGuideProviderHelp": "Add a source for TV Guide information",
"LabelZipCode": "Zip Code:",
"GuideProviderSelectListings": "Select Listings",
Expand Down
14 changes: 13 additions & 1 deletion MediaBrowser.WebDashboard/dashboard-ui/strings/bg-BG.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
"General": "General",
"HeaderScreenSavers": "Screen Savers",
"Sync": "Sync",
"Notifications": "Notifications",
"Metadata": "Metadata",
"Channels": "Channels",
"Reporting": "Reporting",
"NextUp": "Next Up",
"ShowAdvancedSettings": "Show advanced settings",
"HeaderEmbyServer": "Emby Server",
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
"HeaderTypeImageFetchers": "{0} Image Fetchers",
"LabelPrevious": "\u041f\u0440\u0435\u0434\u0438\u0448\u0435\u043d",
"LabelFinish": "\u0413\u043e\u0442\u043e\u0432\u043e",
"LabelNext": "\u0421\u043b\u0435\u0434\u0432\u0430\u0449",
Expand Down Expand Up @@ -723,7 +735,7 @@
"LabelProtocolInfo": "Protocol info:",
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
"TabNfoSettings": "\u0424\u043e\u0440\u043c\u0430\u0442 \u0437\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u0438 .nfo",
"HeaderKodiMetadataHelp": "Emby includes native support for Nfo metadata files. To enable or disable Nfo metadata, use the Metadata tab to configure options for your media types.",
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
"LabelKodiMetadataUserHelp": "\u0420\u0430\u0437\u0440\u0435\u0448\u0435\u0442\u0435 \u0442\u043e\u0432\u0430, \u0437\u0430 \u0434\u0430 \u0437\u0430\u043f\u0430\u0437\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u0438\u0442\u0435 \u0437\u0430 \u0433\u043b\u0435\u0434\u0430\u043d\u0438\u044f\u0442\u0430 \u0432\u044a\u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u0435 Nfo \u0437\u0430 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0430 \u043e\u0442 \u0434\u0440\u0443\u0433\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u0438.",
"LabelKodiMetadataDateFormat": "\u0424\u043e\u0440\u043c\u0430\u0442 \u043d\u0430 \u0434\u0430\u0442\u0430\u0442\u0430 \u043d\u0430 \u0438\u0437\u0434\u0430\u0432\u0430\u043d\u0435:",
Expand Down
16 changes: 14 additions & 2 deletions MediaBrowser.WebDashboard/dashboard-ui/strings/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
"General": "General",
"HeaderScreenSavers": "Screen Savers",
"Sync": "Sync",
"Notifications": "Notifications",
"Metadata": "Metadata",
"Channels": "Channels",
"Reporting": "Reporting",
"NextUp": "Next Up",
"ShowAdvancedSettings": "Show advanced settings",
"HeaderEmbyServer": "Emby Server",
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
"HeaderTypeImageFetchers": "{0} Image Fetchers",
"LabelPrevious": "Anterior",
"LabelFinish": "Finalitzar",
"LabelNext": "Seg\u00fcent",
Expand Down Expand Up @@ -723,7 +735,7 @@
"LabelProtocolInfo": "Informaci\u00f3 del protocol:",
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
"TabNfoSettings": "Prefer\u00e8ncies d'Nfo",
"HeaderKodiMetadataHelp": "Emby includes native support for Nfo metadata files. To enable or disable Nfo metadata, use the Metadata tab to configure options for your media types.",
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
"LabelKodiMetadataDateFormat": "Format de la data de publicaci\u00f3:",
Expand Down Expand Up @@ -1048,7 +1060,7 @@
"HeaderAddDevice": "Afegeix Dispositiu",
"HeaderExternalServices": "External Services",
"LabelTunerIpAddress": "Tuner IP Address:",
"HeaderGuideProviders": "Guide Providers",
"HeaderGuideProviders": "TV Guide Data Providers",
"AddGuideProviderHelp": "Add a source for TV Guide information",
"LabelZipCode": "Zip Code:",
"GuideProviderSelectListings": "Select Listings",
Expand Down
Loading

0 comments on commit eb03055

Please sign in to comment.