Skip to content

Commit eb03055

Browse files
Merge pull request #3251 from MediaBrowser/dev
update image refresh
2 parents a8529ef + ec528d6 commit eb03055

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+786
-118
lines changed

Emby.Server.Implementations/ApplicationHost.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ protected void RegisterResources()
990990
var newsService = new Emby.Server.Implementations.News.NewsService(ApplicationPaths, JsonSerializer);
991991
RegisterSingleInstance<INewsService>(newsService);
992992

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

996996
SubtitleManager = new SubtitleManager(LogManager.GetLogger("SubtitleManager"), FileSystemManager, LibraryMonitor, MediaSourceManager, ServerConfigurationManager, LocalizationManager);

Emby.Server.Implementations/Library/MediaSourceManager.cs

+151-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
using MediaBrowser.Model.Threading;
2020
using MediaBrowser.Model.Dlna;
2121
using MediaBrowser.Model.Globalization;
22+
using System.IO;
23+
using System.Globalization;
24+
using MediaBrowser.Common.Configuration;
2225

2326
namespace Emby.Server.Implementations.Library
2427
{
@@ -36,8 +39,9 @@ public class MediaSourceManager : IMediaSourceManager, IDisposable
3639
private readonly ITimerFactory _timerFactory;
3740
private readonly Func<IMediaEncoder> _mediaEncoder;
3841
private ILocalizationManager _localizationManager;
42+
private IApplicationPaths _appPaths;
3943

40-
public MediaSourceManager(IItemRepository itemRepo, ILocalizationManager localizationManager, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem, IUserDataManager userDataManager, ITimerFactory timerFactory, Func<IMediaEncoder> mediaEncoder)
44+
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)
4145
{
4246
_itemRepo = itemRepo;
4347
_userManager = userManager;
@@ -49,6 +53,7 @@ public MediaSourceManager(IItemRepository itemRepo, ILocalizationManager localiz
4953
_timerFactory = timerFactory;
5054
_mediaEncoder = mediaEncoder;
5155
_localizationManager = localizationManager;
56+
_appPaths = applicationPaths;
5257
}
5358

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

504+
public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken)
505+
{
506+
var originalRuntime = mediaSource.RunTimeTicks;
507+
508+
var now = DateTime.UtcNow;
509+
510+
MediaInfo mediaInfo = null;
511+
var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "mediainfo", cacheKey.GetMD5().ToString("N") + ".json");
512+
513+
if (!string.IsNullOrEmpty(cacheKey))
514+
{
515+
try
516+
{
517+
mediaInfo = _jsonSerializer.DeserializeFromFile<MediaInfo>(cacheFilePath);
518+
519+
//_logger.Debug("Found cached media info");
520+
}
521+
catch (Exception ex)
522+
{
523+
}
524+
}
525+
526+
if (mediaInfo == null)
527+
{
528+
if (addProbeDelay)
529+
{
530+
var delayMs = mediaSource.AnalyzeDurationMs ?? 0;
531+
delayMs = Math.Max(3000, delayMs);
532+
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
533+
}
534+
535+
if (isLiveStream)
536+
{
537+
mediaSource.AnalyzeDurationMs = 3000;
538+
}
539+
540+
mediaInfo = await _mediaEncoder().GetMediaInfo(new MediaInfoRequest
541+
{
542+
MediaSource = mediaSource,
543+
MediaType = isAudio ? DlnaProfileType.Audio : DlnaProfileType.Video,
544+
ExtractChapters = false
545+
546+
}, cancellationToken).ConfigureAwait(false);
547+
548+
if (cacheFilePath != null)
549+
{
550+
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
551+
_jsonSerializer.SerializeToFile(mediaInfo, cacheFilePath);
552+
553+
//_logger.Debug("Saved media info to {0}", cacheFilePath);
554+
}
555+
}
556+
557+
var mediaStreams = mediaInfo.MediaStreams;
558+
559+
if (isLiveStream && !string.IsNullOrEmpty(cacheKey))
560+
{
561+
var newList = new List<MediaStream>();
562+
newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Video).Take(1));
563+
newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Audio).Take(1));
564+
565+
foreach (var stream in newList)
566+
{
567+
stream.Index = -1;
568+
stream.Language = null;
569+
}
570+
571+
mediaStreams = newList;
572+
}
573+
574+
_logger.Info("Live tv media info probe took {0} seconds", (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture));
575+
576+
mediaSource.Bitrate = mediaInfo.Bitrate;
577+
mediaSource.Container = mediaInfo.Container;
578+
mediaSource.Formats = mediaInfo.Formats;
579+
mediaSource.MediaStreams = mediaStreams;
580+
mediaSource.RunTimeTicks = mediaInfo.RunTimeTicks;
581+
mediaSource.Size = mediaInfo.Size;
582+
mediaSource.Timestamp = mediaInfo.Timestamp;
583+
mediaSource.Video3DFormat = mediaInfo.Video3DFormat;
584+
mediaSource.VideoType = mediaInfo.VideoType;
585+
586+
mediaSource.DefaultSubtitleStreamIndex = null;
587+
588+
if (isLiveStream)
589+
{
590+
// Null this out so that it will be treated like a live stream
591+
if (!originalRuntime.HasValue)
592+
{
593+
mediaSource.RunTimeTicks = null;
594+
}
595+
}
596+
597+
var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
598+
599+
if (audioStream == null || audioStream.Index == -1)
600+
{
601+
mediaSource.DefaultAudioStreamIndex = null;
602+
}
603+
else
604+
{
605+
mediaSource.DefaultAudioStreamIndex = audioStream.Index;
606+
}
607+
608+
var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
609+
if (videoStream != null)
610+
{
611+
if (!videoStream.BitRate.HasValue)
612+
{
613+
var width = videoStream.Width ?? 1920;
614+
615+
if (width >= 3000)
616+
{
617+
videoStream.BitRate = 30000000;
618+
}
619+
620+
else if (width >= 1900)
621+
{
622+
videoStream.BitRate = 20000000;
623+
}
624+
625+
else if (width >= 1200)
626+
{
627+
videoStream.BitRate = 8000000;
628+
}
629+
630+
else if (width >= 700)
631+
{
632+
videoStream.BitRate = 2000000;
633+
}
634+
}
635+
636+
// This is coming up false and preventing stream copy
637+
videoStream.IsAVC = null;
638+
}
639+
640+
if (isLiveStream)
641+
{
642+
mediaSource.AnalyzeDurationMs = 3000;
643+
}
644+
645+
// Try to estimate this
646+
mediaSource.InferTotalBitrate(true);
647+
}
648+
499649
public async Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> GetLiveStreamWithDirectStreamProvider(string id, CancellationToken cancellationToken)
500650
{
501651
if (string.IsNullOrEmpty(id))

MediaBrowser.Controller/Library/IMediaSourceManager.cs

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public interface IMediaSourceManager
8585
MediaProtocol GetPathProtocol(string path);
8686

8787
void SetDefaultAudioAndSubtitleStreamIndexes(BaseItem item, MediaSourceInfo source, User user);
88+
89+
Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken);
8890
}
8991

9092
public interface IDirectStreamProvider

MediaBrowser.Providers/Manager/ItemImageProvider.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public bool ValidateImages(BaseItem item, IEnumerable<IImageProvider> providers,
6262
return hasChanges;
6363
}
6464

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

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

78-
var typeOptions = libraryOptions.GetTypeOptions(item.GetType().Name);
79+
var typeName = item.GetType().Name;
80+
var typeOptions = libraryOptions.GetTypeOptions(typeName) ?? _defaultTypeOptions;
7981

8082
// In order to avoid duplicates, only download these if there are none already
8183
var backdropLimit = typeOptions.GetLimit(ImageType.Backdrop);

MediaBrowser.WebDashboard/dashboard-ui/strings/ar.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
99
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
1010
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
11+
"General": "General",
12+
"HeaderScreenSavers": "Screen Savers",
13+
"Sync": "Sync",
14+
"Notifications": "Notifications",
15+
"Metadata": "Metadata",
16+
"Channels": "Channels",
17+
"Reporting": "Reporting",
18+
"NextUp": "Next Up",
19+
"ShowAdvancedSettings": "Show advanced settings",
20+
"HeaderEmbyServer": "Emby Server",
21+
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
22+
"HeaderTypeImageFetchers": "{0} Image Fetchers",
1123
"LabelPrevious": "\u0627\u0644\u0633\u0627\u0628\u0642",
1224
"LabelFinish": "\u0627\u0646\u0647\u0627\u0621",
1325
"LabelNext": "\u0627\u0644\u062a\u0627\u0644\u064a",
@@ -723,7 +735,7 @@
723735
"LabelProtocolInfo": "\u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0627\u0644\u0628\u0631\u0648\u062a\u0648\u0643\u0648\u0644:",
724736
"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.",
725737
"TabNfoSettings": "\u0623\u0639\u062f\u0627\u062f\u0627\u062a Nfo",
726-
"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.",
738+
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
727739
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
728740
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
729741
"LabelKodiMetadataDateFormat": "\u062a\u0646\u0633\u064a\u0642 \u062a\u0627\u0631\u064a\u062e \u0627\u0644\u0625\u0635\u062f\u0627\u0631:",

MediaBrowser.WebDashboard/dashboard-ui/strings/be-BY.json

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
99
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
1010
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
11+
"General": "General",
12+
"HeaderScreenSavers": "Screen Savers",
13+
"Sync": "Sync",
14+
"Notifications": "Notifications",
15+
"Metadata": "Metadata",
16+
"Channels": "Channels",
17+
"Reporting": "Reporting",
18+
"NextUp": "Next Up",
19+
"ShowAdvancedSettings": "Show advanced settings",
20+
"HeaderEmbyServer": "Emby Server",
21+
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
22+
"HeaderTypeImageFetchers": "{0} Image Fetchers",
1123
"LabelPrevious": "\u041f\u0430\u043f\u044f\u0440\u044d\u0434\u043d\u044f\u0435",
1224
"LabelFinish": "\u0413\u0430\u0442\u043e\u0432\u0430",
1325
"LabelNext": "\u041d\u0430\u0441\u0442\u0443\u043f\u043d\u0430\u0435",
@@ -675,7 +687,7 @@
675687
"LabelMessageText": "Message text:",
676688
"LabelMessageTitle": "Message title:",
677689
"MessageNoAvailablePlugins": "No available plugins.",
678-
"LabelDisplayPluginsFor": "Display plugins for:",
690+
"LabelDisplayPluginsFor": "Show plugins for:",
679691
"PluginTabAppClassic": "Emby for Windows Media Center",
680692
"HeaderTypeText": "Enter Text",
681693
"LabelTypeText": "Text",
@@ -723,7 +735,7 @@
723735
"LabelProtocolInfo": "Protocol info:",
724736
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
725737
"TabNfoSettings": "Nfo Settings",
726-
"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.",
738+
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
727739
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
728740
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
729741
"LabelKodiMetadataDateFormat": "Release date format:",
@@ -1048,7 +1060,7 @@
10481060
"HeaderAddDevice": "Add Device",
10491061
"HeaderExternalServices": "External Services",
10501062
"LabelTunerIpAddress": "Tuner IP Address:",
1051-
"HeaderGuideProviders": "Guide Providers",
1063+
"HeaderGuideProviders": "TV Guide Data Providers",
10521064
"AddGuideProviderHelp": "Add a source for TV Guide information",
10531065
"LabelZipCode": "Zip Code:",
10541066
"GuideProviderSelectListings": "Select Listings",

MediaBrowser.WebDashboard/dashboard-ui/strings/bg-BG.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
99
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
1010
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
11+
"General": "General",
12+
"HeaderScreenSavers": "Screen Savers",
13+
"Sync": "Sync",
14+
"Notifications": "Notifications",
15+
"Metadata": "Metadata",
16+
"Channels": "Channels",
17+
"Reporting": "Reporting",
18+
"NextUp": "Next Up",
19+
"ShowAdvancedSettings": "Show advanced settings",
20+
"HeaderEmbyServer": "Emby Server",
21+
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
22+
"HeaderTypeImageFetchers": "{0} Image Fetchers",
1123
"LabelPrevious": "\u041f\u0440\u0435\u0434\u0438\u0448\u0435\u043d",
1224
"LabelFinish": "\u0413\u043e\u0442\u043e\u0432\u043e",
1325
"LabelNext": "\u0421\u043b\u0435\u0434\u0432\u0430\u0449",
@@ -723,7 +735,7 @@
723735
"LabelProtocolInfo": "Protocol info:",
724736
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
725737
"TabNfoSettings": "\u0424\u043e\u0440\u043c\u0430\u0442 \u0437\u0430 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u0438 .nfo",
726-
"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.",
738+
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
727739
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
728740
"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.",
729741
"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:",

MediaBrowser.WebDashboard/dashboard-ui/strings/ca.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
"InviteAnEmbyConnectUser": "Add a user by sending an email invitation.",
99
"HeaderInviteWithEmbyConnect": "Invite with Emby Connect",
1010
"HowWouldYouLikeToAddUser": "How would you like to add a user?",
11+
"General": "General",
12+
"HeaderScreenSavers": "Screen Savers",
13+
"Sync": "Sync",
14+
"Notifications": "Notifications",
15+
"Metadata": "Metadata",
16+
"Channels": "Channels",
17+
"Reporting": "Reporting",
18+
"NextUp": "Next Up",
19+
"ShowAdvancedSettings": "Show advanced settings",
20+
"HeaderEmbyServer": "Emby Server",
21+
"LabelTypeMetadataDownloaders": "{0} metadata downloaders:",
22+
"HeaderTypeImageFetchers": "{0} Image Fetchers",
1123
"LabelPrevious": "Anterior",
1224
"LabelFinish": "Finalitzar",
1325
"LabelNext": "Seg\u00fcent",
@@ -723,7 +735,7 @@
723735
"LabelProtocolInfo": "Informaci\u00f3 del protocol:",
724736
"LabelProtocolInfoHelp": "The value that will be used when responding to GetProtocolInfo requests from the device.",
725737
"TabNfoSettings": "Prefer\u00e8ncies d'Nfo",
726-
"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.",
738+
"HeaderKodiMetadataHelp": "To enable or disable Nfo metadata, edit a library in Emby library setup and locate the metadata savers section.",
727739
"LabelKodiMetadataUser": "Save user watch data to nfo's for:",
728740
"LabelKodiMetadataUserHelp": "Enable this to save watch data to Nfo files for other applications to utilize.",
729741
"LabelKodiMetadataDateFormat": "Format de la data de publicaci\u00f3:",
@@ -1048,7 +1060,7 @@
10481060
"HeaderAddDevice": "Afegeix Dispositiu",
10491061
"HeaderExternalServices": "External Services",
10501062
"LabelTunerIpAddress": "Tuner IP Address:",
1051-
"HeaderGuideProviders": "Guide Providers",
1063+
"HeaderGuideProviders": "TV Guide Data Providers",
10521064
"AddGuideProviderHelp": "Add a source for TV Guide information",
10531065
"LabelZipCode": "Zip Code:",
10541066
"GuideProviderSelectListings": "Select Listings",

0 commit comments

Comments
 (0)