Merge pull request #1638 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2016-04-08 14:59:12 -04:00
commit d9a68205ed
22 changed files with 206 additions and 73 deletions

View File

@ -1,11 +0,0 @@
using MediaBrowser.Controller.Entities;
namespace MediaBrowser.Controller.Channels
{
public interface IChannelItem : IHasImages, IHasTags
{
string ChannelId { get; set; }
string ExternalId { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using MediaBrowser.Model.Channels;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Channels
{
public interface IChannelMediaItem : IChannelItem
{
long? RunTimeTicks { get; set; }
string MediaType { get; }
ChannelMediaContentType ContentType { get; set; }
ExtraType? ExtraType { get; set; }
List<ChannelMediaInfo> ChannelMediaSources { get; set; }
}
}

View File

@ -412,6 +412,9 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember]
public DateTime DateLastRefreshed { get; set; }
[IgnoreDataMember]
public DateTime? DateModifiedDuringLastRefresh { get; set; }
/// <summary>
/// The logger
/// </summary>

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.Providers;
using System;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Threading;
@ -206,6 +207,8 @@ namespace MediaBrowser.Controller.Entities
/// <param name="image">The image.</param>
/// <param name="index">The index.</param>
void SetImage(ItemImageInfo image, int index);
DateTime? DateModifiedDuringLastRefresh { get; set; }
}
public static class HasImagesExtensions

View File

@ -25,6 +25,8 @@ namespace MediaBrowser.Controller.Entities
/// <value>The date last saved.</value>
DateTime DateLastSaved { get; set; }
SourceType SourceType { get; set; }
/// <summary>
/// Gets or sets the date last refreshed.
/// </summary>

View File

@ -85,10 +85,8 @@
<Compile Include="Channels\ChannelSearchInfo.cs" />
<Compile Include="Channels\ChannelVideoItem.cs" />
<Compile Include="Channels\IChannel.cs" />
<Compile Include="Channels\IChannelItem.cs" />
<Compile Include="Channels\IChannelManager.cs" />
<Compile Include="Channels\Channel.cs" />
<Compile Include="Channels\IChannelMediaItem.cs" />
<Compile Include="Channels\IHasCacheKey.cs" />
<Compile Include="Channels\IIndexableChannel.cs" />
<Compile Include="Channels\InternalAllChannelMediaQuery.cs" />

View File

@ -8,9 +8,8 @@ namespace MediaBrowser.Controller.Providers
/// Determines whether the specified item has changed.
/// </summary>
/// <param name="item">The item.</param>
/// <param name="status">The status.</param>
/// <param name="directoryService">The directory service.</param>
/// <returns><c>true</c> if the specified item has changed; otherwise, <c>false</c>.</returns>
bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService);
bool HasChanged(IHasMetadata item, IDirectoryService directoryService);
}
}

View File

@ -157,7 +157,7 @@ namespace MediaBrowser.Providers.Folders
});
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
return GetSupportedImages(item).Any(i => !item.HasImage(i));
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@ -11,8 +12,11 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.Providers;
namespace MediaBrowser.Providers.Manager
@ -68,6 +72,11 @@ namespace MediaBrowser.Providers.Manager
result.ItemDateModified = item.DateModified;
if (EnableDateLastRefreshed(item))
{
return Task.FromResult(true);
}
return ProviderRepo.SaveMetadataStatus(result, CancellationToken.None);
}
@ -83,7 +92,22 @@ namespace MediaBrowser.Providers.Manager
return new MetadataStatus { ItemId = item.Id };
}
return ProviderRepo.GetMetadataStatus(item.Id) ?? new MetadataStatus { ItemId = item.Id };
if (EnableDateLastRefreshed(item) && item.DateModifiedDuringLastRefresh.HasValue)
{
return new MetadataStatus
{
ItemId = item.Id,
DateLastImagesRefresh = item.DateLastRefreshed,
DateLastMetadataRefresh = item.DateLastRefreshed,
ItemDateModified = item.DateModifiedDuringLastRefresh.Value
};
}
var result = ProviderRepo.GetMetadataStatus(item.Id) ?? new MetadataStatus { ItemId = item.Id };
item.DateModifiedDuringLastRefresh = result.ItemDateModified;
return result;
}
public async Task<ItemUpdateType> RefreshMetadata(IHasMetadata item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
@ -119,13 +143,20 @@ namespace MediaBrowser.Providers.Manager
Item = itemOfType
};
bool hasRefreshedMetadata = false;
bool hasRefreshedImages = false;
// Next run metadata providers
if (refreshOptions.MetadataRefreshMode != MetadataRefreshMode.None)
{
var providers = GetProviders(item, refreshResult, refreshOptions)
.ToList();
if (providers.Count > 0 || !refreshResult.DateLastMetadataRefresh.HasValue)
var dateLastRefresh = EnableDateLastRefreshed(item)
? item.DateLastRefreshed
: refreshResult.DateLastMetadataRefresh ?? default(DateTime);
if (providers.Count > 0 || dateLastRefresh == default(DateTime))
{
if (item.BeforeMetadataRefresh())
{
@ -151,6 +182,7 @@ namespace MediaBrowser.Providers.Manager
if (result.Failures == 0)
{
refreshResult.SetDateLastMetadataRefresh(DateTime.UtcNow);
hasRefreshedMetadata = true;
}
else
{
@ -172,6 +204,7 @@ namespace MediaBrowser.Providers.Manager
if (result.Failures == 0)
{
refreshResult.SetDateLastImagesRefresh(DateTime.UtcNow);
hasRefreshedImages = true;
}
else
{
@ -194,9 +227,15 @@ namespace MediaBrowser.Providers.Manager
updateType = updateType | ItemUpdateType.MetadataDownload;
}
if (refreshOptions.MetadataRefreshMode >= MetadataRefreshMode.Default && refreshOptions.ImageRefreshMode >= ImageRefreshMode.Default)
if (hasRefreshedMetadata && hasRefreshedImages)
{
item.DateLastRefreshed = DateTime.UtcNow;
item.DateModifiedDuringLastRefresh = item.DateModified;
}
else
{
item.DateLastRefreshed = default(DateTime);
item.DateModifiedDuringLastRefresh = null;
}
// Save to database
@ -254,7 +293,12 @@ namespace MediaBrowser.Providers.Manager
return true;
}
if (item is BoxSet || (item is IItemByName && !(item is MusicArtist)))
if (item is BoxSet || item is IItemByName || item is Playlist)
{
return true;
}
if (item.SourceType != SourceType.Library)
{
return true;
}
@ -364,8 +408,12 @@ namespace MediaBrowser.Providers.Manager
// Get providers to refresh
var providers = ((ProviderManager)ProviderManager).GetMetadataProviders<TItemType>(item).ToList();
var dateLastRefresh = EnableDateLastRefreshed(item)
? item.DateLastRefreshed
: status.DateLastMetadataRefresh ?? default(DateTime);
// Run all if either of these flags are true
var runAllProviders = options.ReplaceAllMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || !status.DateLastMetadataRefresh.HasValue;
var runAllProviders = options.ReplaceAllMetadata || options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || dateLastRefresh == default(DateTime);
if (!runAllProviders)
{
@ -384,7 +432,7 @@ namespace MediaBrowser.Providers.Manager
var hasFileChangeMonitor = i as IHasItemChangeMonitor;
if (hasFileChangeMonitor != null)
{
return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService);
return HasChanged(item, hasFileChangeMonitor, options.DirectoryService);
}
return false;
@ -429,8 +477,12 @@ namespace MediaBrowser.Providers.Manager
// Get providers to refresh
var providers = allImageProviders.Where(i => !(i is ILocalImageProvider)).ToList();
var dateLastImageRefresh = EnableDateLastRefreshed(item)
? item.DateLastRefreshed
: status.DateLastImagesRefresh ?? default(DateTime);
// Run all if either of these flags are true
var runAllProviders = options.ImageRefreshMode == ImageRefreshMode.FullRefresh || !status.DateLastImagesRefresh.HasValue;
var runAllProviders = options.ImageRefreshMode == ImageRefreshMode.FullRefresh || dateLastImageRefresh == default(DateTime);
if (!runAllProviders)
{
@ -440,13 +492,13 @@ namespace MediaBrowser.Providers.Manager
var hasChangeMonitor = i as IHasChangeMonitor;
if (hasChangeMonitor != null)
{
return HasChanged(item, hasChangeMonitor, status.DateLastImagesRefresh.Value, options.DirectoryService);
return HasChanged(item, hasChangeMonitor, dateLastImageRefresh, options.DirectoryService);
}
var hasFileChangeMonitor = i as IHasItemChangeMonitor;
if (hasFileChangeMonitor != null)
{
return HasChanged(item, hasFileChangeMonitor, status, options.DirectoryService);
return HasChanged(item, hasFileChangeMonitor, options.DirectoryService);
}
return false;
@ -558,7 +610,7 @@ namespace MediaBrowser.Providers.Manager
if (options.MetadataRefreshMode != MetadataRefreshMode.FullRefresh)
{
// If the local provider fails don't continue with remote providers because the user's saved metadata could be lost
return refreshResult;
//return refreshResult;
}
}
}
@ -738,11 +790,11 @@ namespace MediaBrowser.Providers.Manager
}
}
private bool HasChanged(IHasMetadata item, IHasItemChangeMonitor changeMonitor, MetadataStatus status, IDirectoryService directoryService)
private bool HasChanged(IHasMetadata item, IHasItemChangeMonitor changeMonitor, IDirectoryService directoryService)
{
try
{
var hasChanged = changeMonitor.HasChanged(item, status, directoryService);
var hasChanged = changeMonitor.HasChanged(item, directoryService);
//if (hasChanged)
//{

View File

@ -159,14 +159,11 @@ namespace MediaBrowser.Providers.MediaInfo
return item.LocationType == LocationType.FileSystem && audio != null && !audio.IsArchive;
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
if (status.ItemDateModified.HasValue)
if (item.DateModifiedDuringLastRefresh.HasValue)
{
if (status.ItemDateModified.Value != item.DateModified)
{
return true;
}
return item.DateModifiedDuringLastRefresh.Value != item.DateModified;
}
return false;

View File

@ -163,11 +163,11 @@ namespace MediaBrowser.Providers.MediaInfo
return prober.Probe(item, cancellationToken);
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
if (status.ItemDateModified.HasValue)
if (item.DateModifiedDuringLastRefresh.HasValue)
{
if (status.ItemDateModified.Value != item.DateModified)
if (item.DateModifiedDuringLastRefresh.Value != item.DateModified)
{
return true;
}

View File

@ -151,11 +151,11 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
if (status.ItemDateModified.HasValue)
if (item.DateModifiedDuringLastRefresh.HasValue)
{
if (status.ItemDateModified.Value != item.DateModified)
if (item.DateModifiedDuringLastRefresh.Value != item.DateModified)
{
return true;
}

View File

@ -152,11 +152,11 @@ namespace MediaBrowser.Providers.Photos
get { return "Embedded Information"; }
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
if (status.ItemDateModified.HasValue)
if (item.DateModifiedDuringLastRefresh.HasValue)
{
return status.ItemDateModified.Value != item.DateModified;
return item.DateModifiedDuringLastRefresh.Value != item.DateModified;
}
return false;

View File

@ -332,7 +332,7 @@ namespace MediaBrowser.Providers.TV
});
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
if (!TvdbSeriesProvider.Current.GetTvDbOptions().EnableAutomaticUpdates)
{
@ -346,7 +346,7 @@ namespace MediaBrowser.Providers.TV
var fileInfo = _fileSystem.GetFileInfo(imagesXmlPath);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > (status.DateLastMetadataRefresh ?? DateTime.MinValue);
return fileInfo.Exists && _fileSystem.GetLastWriteTimeUtc(fileInfo) > item.DateLastRefreshed;
}
return false;

View File

@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.Channels
return ((ChannelManager)_channelManager).GetChannelProvider(channel);
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
return GetSupportedImages(item).Any(i => !item.HasImage(i));
}

View File

@ -1406,7 +1406,8 @@ namespace MediaBrowser.Server.Implementations.Channels
throw new ArgumentNullException("channel");
}
var result = GetAllChannels().FirstOrDefault(i => string.Equals(GetInternalChannelId(i.Name).ToString("N"), channel.ChannelId, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, channel.Name, StringComparison.OrdinalIgnoreCase));
var result = GetAllChannels()
.FirstOrDefault(i => string.Equals(GetInternalChannelId(i.Name).ToString("N"), channel.ChannelId, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, channel.Name, StringComparison.OrdinalIgnoreCase));
if (result == null)
{

View File

@ -77,7 +77,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
get { return 0; }
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
return GetSupportedImages(item).Any(i => !item.HasImage(i));
}

View File

@ -74,7 +74,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
var liveTvItem = item as LiveTvProgram;

View File

@ -68,7 +68,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
get { return 0; }
}
public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService)
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService)
{
var liveTvItem = item as ILiveTvRecording;

View File

@ -223,6 +223,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
_connection.AddColumn(Logger, "TypedBaseItems", "TrailerTypes", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "CriticRating", "Float");
_connection.AddColumn(Logger, "TypedBaseItems", "CriticRatingSummary", "Text");
_connection.AddColumn(Logger, "TypedBaseItems", "DateModifiedDuringLastRefresh", "DATETIME");
PrepareStatements();
@ -355,7 +356,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"Studios",
"Tags",
"SourceType",
"TrailerTypes"
"TrailerTypes",
"DateModifiedDuringLastRefresh"
};
private readonly string[] _mediaStreamSaveColumns =
@ -459,7 +461,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
"SourceType",
"TrailerTypes",
"CriticRating",
"CriticRatingSummary"
"CriticRatingSummary",
"DateModifiedDuringLastRefresh"
};
_saveItemCommand = _connection.CreateCommand();
_saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (";
@ -752,7 +755,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
_saveItemCommand.GetParameter(index++).Value = item.CriticRating;
_saveItemCommand.GetParameter(index++).Value = item.CriticRatingSummary;
if (!item.DateModifiedDuringLastRefresh.HasValue || item.DateModifiedDuringLastRefresh.Value == default(DateTime))
{
_saveItemCommand.GetParameter(index++).Value = null;
}
else
{
_saveItemCommand.GetParameter(index++).Value = item.DateModifiedDuringLastRefresh.Value;
}
_saveItemCommand.Transaction = transaction;
_saveItemCommand.ExecuteNonQuery();
@ -1125,6 +1137,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
if (!reader.IsDBNull(51))
{
item.DateModifiedDuringLastRefresh = reader.GetDateTime(51).ToUniversalTime();
}
return item;
}

View File

@ -84,7 +84,7 @@ namespace MediaBrowser.Server.Implementations.Social
var externalUrl = _appHost.GetSystemInfo().WanAddress;
info.ImageUrl = externalUrl + "/Social/Shares/Public/" + info.Id + "/Image";
info.Url = externalUrl + "/web/shared.html?id=" + info.Id;
info.Url = externalUrl + "/emby/web/shared.html?id=" + info.Id;
var item = _libraryManager.GetItemById(info.ItemId);

View File

@ -256,6 +256,9 @@ namespace MediaBrowser.ServerApplication
task = InstallVcredistIfNeeded(_appHost, _logger);
Task.WaitAll(task);
task = InstallFrameworkV46IfNeeded(_logger);
Task.WaitAll(task);
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
@ -573,6 +576,93 @@ namespace MediaBrowser.ServerApplication
}
}
private static async Task InstallFrameworkV46IfNeeded(ILogger logger)
{
bool installFrameworkV46 = false;
try
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
{
if (ndpKey != null && ndpKey.GetValue("Release") != null)
{
if ((int)ndpKey.GetValue("Release") <= 393295)
{
//Found framework V4, but not yet V4.6
installFrameworkV46 = true;
}
}
else
{
//Nothing found in the registry for V4
installFrameworkV46 = true;
}
}
}
catch (Exception ex)
{
logger.ErrorException("Error getting .NET Framework version", ex);
}
_logger.Info(".NET Framework 4.6 found: {0}", !installFrameworkV46);
if (installFrameworkV46)
{
try
{
await InstallFrameworkV46().ConfigureAwait(false);
}
catch (Exception ex)
{
logger.ErrorException("Error installing .NET Framework version 4.6", ex);
}
}
}
private static async Task InstallFrameworkV46()
{
var httpClient = _appHost.HttpClient;
var tmp = await httpClient.GetTempFile(new HttpRequestOptions
{
Url = "https://github.com/MediaBrowser/Emby.Resources/raw/master/netframeworkV46/NDP46-KB3045560-Web.exe",
Progress = new Progress<double>()
}).ConfigureAwait(false);
var exePath = Path.ChangeExtension(tmp, ".exe");
File.Copy(tmp, exePath);
var startInfo = new ProcessStartInfo
{
FileName = exePath,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas",
ErrorDialog = false,
Arguments = "/q /norestart"
};
_logger.Info("Running {0}", startInfo.FileName);
using (var process = Process.Start(startInfo))
{
process.WaitForExit();
//process.ExitCode
/*
0 --> Installation completed successfully.
1602 --> The user canceled installation.
1603 --> A fatal error occurred during installation.
1641 --> A restart is required to complete the installation. This message indicates success.
3010 --> A restart is required to complete the installation. This message indicates success.
5100 --> The user's computer does not meet system requirements.
*/
}
}
private static async Task InstallVcredistIfNeeded(ApplicationHost appHost, ILogger logger)
{
try