#35 - Make IBN path configurable
This commit is contained in:
parent
0e7ad811ac
commit
4390e2f710
|
@ -101,6 +101,14 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
|||
XmlSerializer.SerializeToFile(CommonConfiguration, CommonApplicationPaths.SystemConfigurationFilePath);
|
||||
}
|
||||
|
||||
OnConfigurationUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when [configuration updated].
|
||||
/// </summary>
|
||||
protected virtual void OnConfigurationUpdated()
|
||||
{
|
||||
EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger);
|
||||
}
|
||||
|
||||
|
@ -109,7 +117,7 @@ namespace MediaBrowser.Common.Implementations.Configuration
|
|||
/// </summary>
|
||||
/// <param name="newConfiguration">The new configuration.</param>
|
||||
/// <exception cref="System.ArgumentNullException">newConfiguration</exception>
|
||||
public void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration)
|
||||
public virtual void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration)
|
||||
{
|
||||
if (newConfiguration == null)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace MediaBrowser.Controller
|
|||
/// Gets the path to the Images By Name directory
|
||||
/// </summary>
|
||||
/// <value>The images by name path.</value>
|
||||
string ImagesByNamePath { get; }
|
||||
string ItemsByNamePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to the People directory
|
||||
|
|
|
@ -27,6 +27,11 @@ namespace MediaBrowser.Controller.Providers
|
|||
/// </summary>
|
||||
/// <value>The provider version.</value>
|
||||
public string ProviderVersion { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the custom data.
|
||||
/// </summary>
|
||||
/// <value>The custom data.</value>
|
||||
public string CustomData { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using MediaBrowser.Controller.Configuration;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using System;
|
||||
|
@ -41,6 +43,23 @@ namespace MediaBrowser.Controller.Providers
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Needses the refresh internal.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="providerInfo">The provider info.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
||||
{
|
||||
// Force a refresh if the IBN path changed
|
||||
if (!string.Equals(providerInfo.CustomData, ConfigurationManager.ApplicationPaths.ItemsByNamePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [refresh on file system stamp change].
|
||||
/// </summary>
|
||||
|
@ -80,9 +99,25 @@ namespace MediaBrowser.Controller.Providers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// The us culture
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="force">if set to <c>true</c> [force].</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{System.Boolean}.</returns>
|
||||
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await base.FetchAsync(item, force, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
BaseProviderInfo data;
|
||||
|
||||
if (item.ProviderData.TryGetValue(Id, out data))
|
||||
{
|
||||
data.CustomData = ConfigurationManager.ApplicationPaths.ItemsByNamePath;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the location.
|
||||
|
@ -91,10 +126,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
/// <returns>System.String.</returns>
|
||||
protected string GetLocation(BaseItem item)
|
||||
{
|
||||
var invalid = Path.GetInvalidFileNameChars();
|
||||
|
||||
var name = item.Name ?? string.Empty;
|
||||
name = invalid.Aggregate(name, (current, c) => current.Replace(c.ToString(UsCulture), string.Empty));
|
||||
var name = FileSystem.GetValidFilename(item.Name);
|
||||
|
||||
return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,12 @@ namespace MediaBrowser.Model.Configuration
|
|||
/// <value>The weather location.</value>
|
||||
public string WeatherLocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item by name path.
|
||||
/// </summary>
|
||||
/// <value>The item by name path.</value>
|
||||
public string ItemsByNamePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the weather unit to use when displaying weather
|
||||
/// </summary>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Common.Configuration;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Implementations.Configuration;
|
||||
using MediaBrowser.Controller;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
@ -23,6 +24,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
|||
public ServerConfigurationManager(IApplicationPaths applicationPaths, ILogManager logManager, IXmlSerializer xmlSerializer)
|
||||
: base(applicationPaths, logManager, xmlSerializer)
|
||||
{
|
||||
UpdateItemsByNamePath();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -51,5 +53,47 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
|||
{
|
||||
get { return (ServerConfiguration)CommonConfiguration; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when [configuration updated].
|
||||
/// </summary>
|
||||
protected override void OnConfigurationUpdated()
|
||||
{
|
||||
UpdateItemsByNamePath();
|
||||
|
||||
base.OnConfigurationUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the items by name path.
|
||||
/// </summary>
|
||||
private void UpdateItemsByNamePath()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Configuration.ItemsByNamePath))
|
||||
{
|
||||
ApplicationPaths.ItemsByNamePath = Configuration.ItemsByNamePath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the configuration.
|
||||
/// </summary>
|
||||
/// <param name="newConfiguration">The new configuration.</param>
|
||||
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
|
||||
public override void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration)
|
||||
{
|
||||
var newConfig = (ServerConfiguration) newConfiguration;
|
||||
|
||||
if (!string.Equals(Configuration.ItemsByNamePath, newConfig.ItemsByNamePath))
|
||||
{
|
||||
// Validate
|
||||
if (!Directory.Exists(newConfig.ItemsByNamePath))
|
||||
{
|
||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newConfig.ItemsByNamePath));
|
||||
}
|
||||
}
|
||||
|
||||
base.ReplaceConfiguration(newConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,9 +212,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
private bool _internetProvidersEnabled;
|
||||
private bool _peopleImageFetchingEnabled;
|
||||
private string _itemsByNamePath;
|
||||
|
||||
private void RecordConfigurationValues(ServerConfiguration configuration)
|
||||
{
|
||||
_itemsByNamePath = ConfigurationManager.ApplicationPaths.ItemsByNamePath;
|
||||
_internetProvidersEnabled = configuration.EnableInternetProviders;
|
||||
_peopleImageFetchingEnabled = configuration.InternetProviderExcludeTypes == null || !configuration.InternetProviderExcludeTypes.Contains(typeof(Person).Name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
@ -239,6 +241,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
refreshPeopleAfterUpdate = newConfigurationFetchesPeopleImages && !_peopleImageFetchingEnabled;
|
||||
}
|
||||
|
||||
var ibnPathChanged = !string.Equals(_itemsByNamePath, ConfigurationManager.ApplicationPaths.ItemsByNamePath);
|
||||
|
||||
if (ibnPathChanged)
|
||||
{
|
||||
_itemsByName.Clear();
|
||||
}
|
||||
|
||||
RecordConfigurationValues(config);
|
||||
|
||||
Task.Run(() =>
|
||||
|
@ -528,7 +537,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>Task{Person}.</returns>
|
||||
private Task<Person> GetPerson(string name, CancellationToken cancellationToken, bool allowSlowProviders = false, bool forceCreation = false)
|
||||
{
|
||||
return GetImagesByNameItem<Person>(ConfigurationManager.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders, forceCreation);
|
||||
return GetItemByName<Person>(ConfigurationManager.ApplicationPaths.PeoplePath, name, cancellationToken, allowSlowProviders, forceCreation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -539,7 +548,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>Task{Studio}.</returns>
|
||||
public Task<Studio> GetStudio(string name, bool allowSlowProviders = false)
|
||||
{
|
||||
return GetImagesByNameItem<Studio>(ConfigurationManager.ApplicationPaths.StudioPath, name, CancellationToken.None, allowSlowProviders);
|
||||
return GetItemByName<Studio>(ConfigurationManager.ApplicationPaths.StudioPath, name, CancellationToken.None, allowSlowProviders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -550,7 +559,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>Task{Genre}.</returns>
|
||||
public Task<Genre> GetGenre(string name, bool allowSlowProviders = false)
|
||||
{
|
||||
return GetImagesByNameItem<Genre>(ConfigurationManager.ApplicationPaths.GenrePath, name, CancellationToken.None, allowSlowProviders);
|
||||
return GetItemByName<Genre>(ConfigurationManager.ApplicationPaths.GenrePath, name, CancellationToken.None, allowSlowProviders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -574,7 +583,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>Task{Artist}.</returns>
|
||||
private Task<Artist> GetArtist(string name, CancellationToken cancellationToken, bool allowSlowProviders = false, bool forceCreation = false)
|
||||
{
|
||||
return GetImagesByNameItem<Artist>(ConfigurationManager.ApplicationPaths.ArtistsPath, name, cancellationToken, allowSlowProviders, forceCreation);
|
||||
return GetItemByName<Artist>(ConfigurationManager.ApplicationPaths.ArtistsPath, name, cancellationToken, allowSlowProviders, forceCreation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -596,13 +605,13 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
return GetImagesByNameItem<Year>(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture), CancellationToken.None, allowSlowProviders);
|
||||
return GetItemByName<Year>(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture), CancellationToken.None, allowSlowProviders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The images by name item cache
|
||||
/// </summary>
|
||||
private readonly ConcurrentDictionary<string, BaseItem> _imagesByNameItemCache = new ConcurrentDictionary<string, BaseItem>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ConcurrentDictionary<string, BaseItem> _itemsByName = new ConcurrentDictionary<string, BaseItem>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// Generically retrieves an IBN item
|
||||
|
@ -616,7 +625,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <returns>Task{``0}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// </exception>
|
||||
private async Task<T> GetImagesByNameItem<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true, bool forceCreation = false)
|
||||
private async Task<T> GetItemByName<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true, bool forceCreation = false)
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
|
@ -633,11 +642,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
BaseItem obj;
|
||||
|
||||
if (forceCreation || !_imagesByNameItemCache.TryGetValue(key, out obj))
|
||||
if (forceCreation || !_itemsByName.TryGetValue(key, out obj))
|
||||
{
|
||||
obj = await CreateImagesByNameItem<T>(path, name, cancellationToken, allowSlowProviders).ConfigureAwait(false);
|
||||
obj = await CreateItemByName<T>(path, name, cancellationToken, allowSlowProviders).ConfigureAwait(false);
|
||||
|
||||
_imagesByNameItemCache.AddOrUpdate(key, obj, (keyName, oldValue) => obj);
|
||||
_itemsByName.AddOrUpdate(key, obj, (keyName, oldValue) => obj);
|
||||
}
|
||||
|
||||
return obj as T;
|
||||
|
@ -653,7 +662,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// <param name="allowSlowProviders">if set to <c>true</c> [allow slow providers].</param>
|
||||
/// <returns>Task{``0}.</returns>
|
||||
/// <exception cref="System.IO.IOException">Path not created: + path</exception>
|
||||
private async Task<T> CreateImagesByNameItem<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true)
|
||||
private async Task<T> CreateItemByName<T>(string path, string name, CancellationToken cancellationToken, bool allowSlowProviders = true)
|
||||
where T : BaseItem, new()
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
/// Gets the path to the Images By Name directory
|
||||
/// </summary>
|
||||
/// <value>The images by name path.</value>
|
||||
public string ImagesByNamePath
|
||||
public string ItemsByNamePath
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -121,6 +121,18 @@ namespace MediaBrowser.Server.Implementations
|
|||
|
||||
return _ibnPath;
|
||||
}
|
||||
set
|
||||
{
|
||||
_ibnPath = value;
|
||||
|
||||
_peoplePath = null;
|
||||
_studioPath = null;
|
||||
_genrePath = null;
|
||||
_yearPath = null;
|
||||
_musicArtistsPath = null;
|
||||
_generalPath = null;
|
||||
_ratingsPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -137,7 +149,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_peoplePath == null)
|
||||
{
|
||||
_peoplePath = Path.Combine(ImagesByNamePath, "People");
|
||||
_peoplePath = Path.Combine(ItemsByNamePath, "People");
|
||||
if (!Directory.Exists(_peoplePath))
|
||||
{
|
||||
Directory.CreateDirectory(_peoplePath);
|
||||
|
@ -162,7 +174,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_genrePath == null)
|
||||
{
|
||||
_genrePath = Path.Combine(ImagesByNamePath, "Genre");
|
||||
_genrePath = Path.Combine(ItemsByNamePath, "Genre");
|
||||
if (!Directory.Exists(_genrePath))
|
||||
{
|
||||
Directory.CreateDirectory(_genrePath);
|
||||
|
@ -187,7 +199,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_studioPath == null)
|
||||
{
|
||||
_studioPath = Path.Combine(ImagesByNamePath, "Studio");
|
||||
_studioPath = Path.Combine(ItemsByNamePath, "Studio");
|
||||
if (!Directory.Exists(_studioPath))
|
||||
{
|
||||
Directory.CreateDirectory(_studioPath);
|
||||
|
@ -212,7 +224,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_yearPath == null)
|
||||
{
|
||||
_yearPath = Path.Combine(ImagesByNamePath, "Year");
|
||||
_yearPath = Path.Combine(ItemsByNamePath, "Year");
|
||||
if (!Directory.Exists(_yearPath))
|
||||
{
|
||||
Directory.CreateDirectory(_yearPath);
|
||||
|
@ -237,7 +249,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_generalPath == null)
|
||||
{
|
||||
_generalPath = Path.Combine(ImagesByNamePath, "General");
|
||||
_generalPath = Path.Combine(ItemsByNamePath, "General");
|
||||
if (!Directory.Exists(_generalPath))
|
||||
{
|
||||
Directory.CreateDirectory(_generalPath);
|
||||
|
@ -262,7 +274,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_ratingsPath == null)
|
||||
{
|
||||
_ratingsPath = Path.Combine(ImagesByNamePath, "Ratings");
|
||||
_ratingsPath = Path.Combine(ItemsByNamePath, "Ratings");
|
||||
if (!Directory.Exists(_ratingsPath))
|
||||
{
|
||||
Directory.CreateDirectory(_ratingsPath);
|
||||
|
@ -363,7 +375,7 @@ namespace MediaBrowser.Server.Implementations
|
|||
{
|
||||
if (_musicArtistsPath == null)
|
||||
{
|
||||
_musicArtistsPath = Path.Combine(ImagesByNamePath, "Artists");
|
||||
_musicArtistsPath = Path.Combine(ItemsByNamePath, "Artists");
|
||||
if (!Directory.Exists(_musicArtistsPath))
|
||||
{
|
||||
Directory.CreateDirectory(_musicArtistsPath);
|
||||
|
|
|
@ -222,34 +222,9 @@ namespace MediaBrowser.ServerApplication
|
|||
var url = "http://localhost:" + configurationManager.Configuration.HttpServerPortNumber + "/" +
|
||||
Kernel.Instance.WebApplicationName + "/dashboard/" + page;
|
||||
|
||||
if (loggedInUser != null)
|
||||
{
|
||||
url = AddAutoLoginToDashboardUrl(url, loggedInUser);
|
||||
}
|
||||
|
||||
OpenUrl(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the auto login to dashboard URL.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public static string AddAutoLoginToDashboardUrl(string url, User user)
|
||||
{
|
||||
if (url.IndexOf('?') == -1)
|
||||
{
|
||||
url += "?u=" + user.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
url += "&u=" + user.Id;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the URL.
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user