diff options
| author | Techywarrior <techywarrior@gmail.com> | 2013-04-13 17:04:49 -0700 |
|---|---|---|
| committer | Techywarrior <techywarrior@gmail.com> | 2013-04-13 17:04:49 -0700 |
| commit | 419d85116798bd5e5327c41d711d6cb46d70caeb (patch) | |
| tree | b7b94ae285e70f97c09c3343be4763ac59229957 | |
| parent | 89ed33bbbcc3f47299a6104cbb1dd20ad3589510 (diff) | |
| parent | 7f1fdbf223f95dfc1435a8ff1b82fd635cc9b1d9 (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
27 files changed, 480 insertions, 106 deletions
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 8fcef654d..e644f1f31 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -110,9 +110,14 @@ namespace MediaBrowser.Api if (auth != null && auth.ContainsKey("UserId")) { - var user = UserManager.GetUserById(new Guid(auth["UserId"])); + var userId = auth["UserId"]; - UserManager.LogUserActivity(user, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty); + if (!string.IsNullOrEmpty(userId)) + { + var user = UserManager.GetUserById(new Guid(userId)); + + UserManager.LogUserActivity(user, auth["Client"], auth["DeviceId"], auth["Device"] ?? string.Empty); + } } } diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 432594842..0a2d6453a 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -70,9 +70,13 @@ namespace MediaBrowser.Api.UserLibrary items = FilterItems(request, items, user); var extractedItems = GetAllItems(request, items, user); - var ibnItemsArray = SortItems(request, extractedItems).ToArray(); - - IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> ibnItems = ibnItemsArray; + + extractedItems = FilterItems(request, extractedItems, user); + extractedItems = SortItems(request, extractedItems); + + var ibnItemsArray = extractedItems.ToArray(); + + IEnumerable<IbnStub<TItemType>> ibnItems = ibnItemsArray; var result = new ItemsResult { @@ -105,22 +109,73 @@ namespace MediaBrowser.Api.UserLibrary } /// <summary> + /// Filters the items. + /// </summary> + /// <param name="request">The request.</param> + /// <param name="items">The items.</param> + /// <param name="user">The user.</param> + /// <returns>IEnumerable{IbnStub}.</returns> + private IEnumerable<IbnStub<TItemType>> FilterItems(GetItemsByName request, IEnumerable<IbnStub<TItemType>> items, User user) + { + var filters = request.GetFilters().ToList(); + + if (filters.Count == 0) + { + return items; + } + + items = items.AsParallel(); + + if (filters.Contains(ItemFilter.Dislikes)) + { + items = items.Where(i => + { + var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result; + + return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value; + }); + } + + if (filters.Contains(ItemFilter.Likes)) + { + items = items.Where(i => + { + var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result; + + return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value; + }); + } + + if (filters.Contains(ItemFilter.IsFavorite)) + { + items = items.Where(i => + { + var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result; + + return userdata != null && userdata.Likes.HasValue && userdata.IsFavorite; + }); + } + + return items.AsEnumerable(); + } + + /// <summary> /// Sorts the items. /// </summary> /// <param name="request">The request.</param> /// <param name="items">The items.</param> /// <returns>IEnumerable{BaseItem}.</returns> - private IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> SortItems(GetItemsByName request, IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> items) + private IEnumerable<IbnStub<TItemType>> SortItems(GetItemsByName request, IEnumerable<IbnStub<TItemType>> items) { if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase)) { if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending) { - items = items.OrderByDescending(i => i.Item1); + items = items.OrderByDescending(i => i.Name); } else { - items = items.OrderBy(i => i.Item1); + items = items.OrderBy(i => i.Name); } } @@ -160,14 +215,7 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="items">The items.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns> - protected abstract IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user); - - /// <summary> - /// Gets the entity. - /// </summary> - /// <param name="name">The name.</param> - /// <returns>Task{BaseItem}.</returns> - protected abstract Task<TItemType> GetEntity(string name); + protected abstract IEnumerable<IbnStub<TItemType>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user); /// <summary> /// Gets the dto. @@ -176,17 +224,17 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="user">The user.</param> /// <param name="fields">The fields.</param> /// <returns>Task{DtoBaseItem}.</returns> - private async Task<BaseItemDto> GetDto(Tuple<string, Func<IEnumerable<BaseItem>>> stub, User user, List<ItemFields> fields) + private async Task<BaseItemDto> GetDto(IbnStub<TItemType> stub, User user, List<ItemFields> fields) { BaseItem item; try { - item = await GetEntity(stub.Item1).ConfigureAwait(false); + item = await stub.GetItem().ConfigureAwait(false); } catch (IOException ex) { - Logger.ErrorException("Error getting IBN item {0}", ex, stub.Item1); + Logger.ErrorException("Error getting IBN item {0}", ex, stub.Name); return null; } @@ -194,7 +242,7 @@ namespace MediaBrowser.Api.UserLibrary if (fields.Contains(ItemFields.ItemCounts)) { - var items = stub.Item2().ToList(); + var items = stub.Items; dto.ChildCount = items.Count; dto.RecentlyAddedItemCount = items.Count(i => i.IsRecentlyAdded(user)); @@ -216,4 +264,48 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "SortBy", Description = "Optional. Options: SortName", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string SortBy { get; set; } } + + public class IbnStub<T> + where T : BaseItem + { + private readonly Func<IEnumerable<BaseItem>> _childItemsFunction; + private List<BaseItem> _childItems; + + private readonly Func<string,Task<T>> _itemFunction; + private Task<T> _itemTask; + + public string Name; + + public BaseItem Item; + private Task<UserItemData> _userData; + + public List<BaseItem> Items + { + get { return _childItems ?? (_childItems = _childItemsFunction().ToList()); } + } + + public Task<T> GetItem() + { + return _itemTask ?? (_itemTask = _itemFunction(Name)); + } + + public async Task<UserItemData> GetUserItemData(IUserDataRepository repo, Guid userId) + { + var item = await GetItem().ConfigureAwait(false); + + if (_userData == null) + { + _userData = repo.GetUserData(userId, item.GetUserDataKey()); + } + + return await _userData.ConfigureAwait(false); + } + + public IbnStub(string name, Func<IEnumerable<BaseItem>> childItems, Func<string,Task<T>> item) + { + Name = name; + _childItemsFunction = childItems; + _itemFunction = item; + } + } } diff --git a/MediaBrowser.Api/UserLibrary/GenresService.cs b/MediaBrowser.Api/UserLibrary/GenresService.cs index e275b6ed0..87d996d50 100644 --- a/MediaBrowser.Api/UserLibrary/GenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GenresService.cs @@ -48,14 +48,14 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="items">The items.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns> - protected override IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) + protected override IEnumerable<IbnStub<Genre>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) { var itemsList = items.Where(i => i.Genres != null).ToList(); return itemsList .SelectMany(i => i.Genres) .Distinct(StringComparer.OrdinalIgnoreCase) - .Select(name => new Tuple<string, Func<IEnumerable<BaseItem>>>(name, () => itemsList.Where(i => i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)))); + .Select(name => new IbnStub<Genre>(name, () => itemsList.Where(i => i.Genres.Contains(name, StringComparer.OrdinalIgnoreCase)), GetEntity)); } /// <summary> @@ -63,7 +63,7 @@ namespace MediaBrowser.Api.UserLibrary /// </summary> /// <param name="name">The name.</param> /// <returns>Task{Genre}.</returns> - protected override Task<Genre> GetEntity(string name) + protected Task<Genre> GetEntity(string name) { return LibraryManager.GetGenre(name); } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 675ac0cd5..cd6bd7854 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -38,8 +38,8 @@ namespace MediaBrowser.Api.UserLibrary /// If the Person filter is used, this can also be used to restrict to a specific person type /// </summary> /// <value>The type of the person.</value> - [ApiMember(Name = "PersonType", Description = "Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string PersonType { get; set; } + [ApiMember(Name = "PersonTypes", Description = "Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string PersonTypes { get; set; } /// <summary> /// Search characters used to find items @@ -357,6 +357,20 @@ namespace MediaBrowser.Api.UserLibrary /// <returns>IEnumerable{BaseItem}.</returns> internal static IEnumerable<BaseItem> ApplyAdditionalFilters(GetItems request, IEnumerable<BaseItem> items) { + // Exclude item types + if (!string.IsNullOrEmpty(request.ExcludeItemTypes)) + { + var vals = request.ExcludeItemTypes.Split(','); + items = items.Where(f => !vals.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase)); + } + + // Include item types + if (!string.IsNullOrEmpty(request.IncludeItemTypes)) + { + var vals = request.IncludeItemTypes.Split(','); + items = items.Where(f => vals.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase)); + } + // Filter by Series Status if (!string.IsNullOrEmpty(request.SeriesStatus)) { @@ -434,11 +448,21 @@ namespace MediaBrowser.Api.UserLibrary // Apply person filter if (!string.IsNullOrEmpty(personName)) { - var personType = request.PersonType; + var personTypes = request.PersonTypes; - items = !string.IsNullOrEmpty(personType) - ? items.Where(item => item.People != null && item.People.Any(p => p.Name.Equals(personName, StringComparison.OrdinalIgnoreCase) && p.Type.Equals(personType, StringComparison.OrdinalIgnoreCase))) - : items.Where(item => item.People != null && item.People.Any(p => p.Name.Equals(personName, StringComparison.OrdinalIgnoreCase))); + if (string.IsNullOrEmpty(personTypes)) + { + items = items.Where(item => item.People != null && item.People.Any(p => string.Equals(p.Name, personName, StringComparison.OrdinalIgnoreCase))); + } + else + { + var types = personTypes.Split(','); + + items = items.Where(item => + item.People != null && + item.People.Any(p => + p.Name.Equals(personName, StringComparison.OrdinalIgnoreCase) && types.Contains(p.Type, StringComparer.OrdinalIgnoreCase))); + } } return items; diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index 974b8c002..fe5cf39f6 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -53,7 +53,7 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="items">The items.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns> - protected override IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) + protected override IEnumerable<IbnStub<Person>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) { var inputPersonTypes = ((GetPersons) request).PersonTypes; var personTypes = string.IsNullOrEmpty(inputPersonTypes) ? new string[] { } : inputPersonTypes.Split(','); @@ -67,7 +67,7 @@ namespace MediaBrowser.Api.UserLibrary .Select(i => i.Name) .Distinct(StringComparer.OrdinalIgnoreCase) - .Select(name => new Tuple<string, Func<IEnumerable<BaseItem>>>(name, () => + .Select(name => new IbnStub<Person>(name, () => { if (personTypes.Length == 0) { @@ -75,7 +75,7 @@ namespace MediaBrowser.Api.UserLibrary } return itemsList.Where(i => i.People.Any(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && personTypes.Contains(p.Type ?? string.Empty, StringComparer.OrdinalIgnoreCase))); - }) + }, GetEntity) ); } @@ -89,7 +89,6 @@ namespace MediaBrowser.Api.UserLibrary { var people = itemsList.SelectMany(i => i.People.OrderBy(p => p.Type)); - return personTypes.Length == 0 ? people : @@ -102,7 +101,7 @@ namespace MediaBrowser.Api.UserLibrary /// </summary> /// <param name="name">The name.</param> /// <returns>Task{Genre}.</returns> - protected override Task<Person> GetEntity(string name) + protected Task<Person> GetEntity(string name) { return LibraryManager.GetPerson(name); } diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs index 77f20d8e8..e2c1c4743 100644 --- a/MediaBrowser.Api/UserLibrary/StudiosService.cs +++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs @@ -48,14 +48,14 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="items">The items.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns> - protected override IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) + protected override IEnumerable<IbnStub<Studio>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) { var itemsList = items.Where(i => i.Studios != null).ToList(); return itemsList .SelectMany(i => i.Studios) .Distinct(StringComparer.OrdinalIgnoreCase) - .Select(name => new Tuple<string, Func<IEnumerable<BaseItem>>>(name, () => itemsList.Where(i => i.Studios.Contains(name, StringComparer.OrdinalIgnoreCase)))); + .Select(name => new IbnStub<Studio>(name, () => itemsList.Where(i => i.Studios.Contains(name, StringComparer.OrdinalIgnoreCase)), GetEntity)); } /// <summary> @@ -63,7 +63,7 @@ namespace MediaBrowser.Api.UserLibrary /// </summary> /// <param name="name">The name.</param> /// <returns>Task{Studio}.</returns> - protected override Task<Studio> GetEntity(string name) + protected Task<Studio> GetEntity(string name) { return LibraryManager.GetStudio(name); } diff --git a/MediaBrowser.Api/UserLibrary/YearsService.cs b/MediaBrowser.Api/UserLibrary/YearsService.cs index 481645c24..c7cd4ff24 100644 --- a/MediaBrowser.Api/UserLibrary/YearsService.cs +++ b/MediaBrowser.Api/UserLibrary/YearsService.cs @@ -54,14 +54,14 @@ namespace MediaBrowser.Api.UserLibrary /// <param name="items">The items.</param> /// <param name="user">The user.</param> /// <returns>IEnumerable{Tuple{System.StringFunc{System.Int32}}}.</returns> - protected override IEnumerable<Tuple<string, Func<IEnumerable<BaseItem>>>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) + protected override IEnumerable<IbnStub<Year>> GetAllItems(GetItemsByName request, IEnumerable<BaseItem> items, User user) { var itemsList = items.Where(i => i.ProductionYear != null).ToList(); return itemsList .Select(i => i.ProductionYear.Value) .Distinct() - .Select(year => new Tuple<string, Func<IEnumerable<BaseItem>>>(year.ToString(UsCulture), () => itemsList.Where(i => i.ProductionYear.HasValue && i.ProductionYear.Value == year))); + .Select(year => new IbnStub<Year>(year.ToString(UsCulture), () => itemsList.Where(i => i.ProductionYear.HasValue && i.ProductionYear.Value == year), GetEntity)); } /// <summary> @@ -69,7 +69,7 @@ namespace MediaBrowser.Api.UserLibrary /// </summary> /// <param name="name">The name.</param> /// <returns>Task{Studio}.</returns> - protected override Task<Year> GetEntity(string name) + protected Task<Year> GetEntity(string name) { return LibraryManager.GetYear(int.Parse(name, UsCulture)); } diff --git a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj index b2872e22a..79344bb0d 100644 --- a/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj +++ b/MediaBrowser.Common.Implementations/MediaBrowser.Common.Implementations.csproj @@ -35,9 +35,6 @@ <RunPostBuildEvent>Always</RunPostBuildEvent> </PropertyGroup> <ItemGroup> - <Reference Include="Mediabrowser.PluginSecurity"> - <HintPath>..\ThirdParty\PluginSecurity\Mediabrowser.PluginSecurity.dll</HintPath> - </Reference> <Reference Include="NLog"> <HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath> </Reference> @@ -79,6 +76,8 @@ <Compile Include="ScheduledTasks\Tasks\DeleteLogFileTask.cs" /> <Compile Include="ScheduledTasks\Tasks\ReloadLoggerTask.cs" /> <Compile Include="ScheduledTasks\Tasks\SystemUpdateTask.cs" /> + <Compile Include="Security\MBLicenseFile.cs" /> + <Compile Include="Security\MBRegistration.cs" /> <Compile Include="Security\PluginSecurityManager.cs" /> <Compile Include="Serialization\JsonSerializer.cs" /> <Compile Include="Serialization\XmlSerializer.cs" /> @@ -104,7 +103,6 @@ <PropertyGroup> <PostBuildEvent>if $(ConfigurationName) == Release ( xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i -xcopy "$(TargetDir)Mediabrowser.PluginSecurity.dll" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i )</PostBuildEvent> </PropertyGroup> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. diff --git a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs new file mode 100644 index 000000000..336ca78f0 --- /dev/null +++ b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs @@ -0,0 +1,106 @@ +using MediaBrowser.Common.Configuration; +using System; +using System.Collections.Generic; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace Mediabrowser.Common.Implementations.Security +{ + internal class MBLicenseFile + { + private readonly IApplicationPaths _appPaths; + + private readonly string _filename; + public string RegKey + { + get { return _regKey; } + set + { + if (value != _regKey) + { + //if key is changed - clear out our saved validations + UpdateRecords.Clear(); + _regKey = value; + } + } + } + + public string LegacyKey { get; set; } + private Dictionary<Guid, DateTime> UpdateRecords { get; set; } + private readonly object _lck = new object(); + private string _regKey; + + public MBLicenseFile(IApplicationPaths appPaths) + { + _appPaths = appPaths; + + _filename = Path.Combine(_appPaths.ConfigurationDirectoryPath, "mb.lic"); + + UpdateRecords = new Dictionary<Guid, DateTime>(); + Load(); + } + + public void AddRegCheck(string featureId) + { + using (var provider = new MD5CryptoServiceProvider()) + { + UpdateRecords[new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId)))] = DateTime.UtcNow; + Save(); + } + + } + + public DateTime LastChecked(string featureId) + { + using (var provider = new MD5CryptoServiceProvider()) + { + DateTime last; + lock(_lck) UpdateRecords.TryGetValue(new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(featureId))), out last); + return last < DateTime.UtcNow ? last : DateTime.MinValue; // guard agains people just putting a large number in the file + } + } + + private void Load() + { + string[] contents = null; + lock (_lck) + { + try + { + contents = File.ReadAllLines(_filename); + } + catch (FileNotFoundException) + { + (File.Create(_filename)).Close(); + } + } + if (contents != null && contents.Length > 0) + { + //first line is reg key + RegKey = contents[0]; + //next is legacy key + if (contents.Length > 1) LegacyKey = contents[1]; + //the rest of the lines should be pairs of features and timestamps + for (var i = 2; i < contents.Length; i = i + 2) + { + var feat = Guid.Parse(contents[i]); + UpdateRecords[feat] = new DateTime(Convert.ToInt64(contents[i + 1])); + } + } + } + + public void Save() + { + //build our array + var lines = new List<string> {RegKey, LegacyKey}; + foreach (var pair in UpdateRecords) + { + lines.Add(pair.Key.ToString()); + lines.Add(pair.Value.Ticks.ToString()); + } + + lock(_lck) File.WriteAllLines(_filename, lines); + } + } +} diff --git a/MediaBrowser.Common.Implementations/Security/MBRegistration.cs b/MediaBrowser.Common.Implementations/Security/MBRegistration.cs new file mode 100644 index 000000000..570a0429c --- /dev/null +++ b/MediaBrowser.Common.Implementations/Security/MBRegistration.cs @@ -0,0 +1,109 @@ +using Mediabrowser.Model.Entities; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Net; +using MediaBrowser.Model.Serialization; +using System; +using System.Collections.Generic; +using System.Management; +using System.Threading; +using System.Threading.Tasks; + +namespace Mediabrowser.Common.Implementations.Security +{ + public static class MBRegistration + { + + private static MBLicenseFile _licenseFile; + private const string MBValidateUrl = "http://mb3admin.com/admin/service/registration/validate"; + + private static IApplicationPaths _appPaths; + + private static MBLicenseFile LicenseFile + { + get { return _licenseFile ?? (_licenseFile = new MBLicenseFile(_appPaths)); } + } + + public static string SupporterKey + { + get { return LicenseFile.RegKey; } + set { LicenseFile.RegKey = value; LicenseFile.Save(); } + } + + public static string LegacyKey + { + get { return LicenseFile.LegacyKey; } + set { LicenseFile.LegacyKey = value; LicenseFile.Save(); } + } + + public static void Init(IApplicationPaths appPaths) + { + // Ugly alert (static init) + + _appPaths = appPaths; + } + + public static async Task<MBRegistrationRecord> GetRegistrationStatus(IHttpClient httpClient, IJsonSerializer jsonSerializer, string feature, string mb2Equivalent = null) + { + var mac = GetMacAddress(); + var data = new Dictionary<string, string> {{"feature", feature}, {"key",SupporterKey}, {"mac",mac}, {"mb2equiv",mb2Equivalent}, {"legacykey", LegacyKey} }; + + var reg = new RegRecord(); + try + { + using (var json = await httpClient.Post(MBValidateUrl, data, CancellationToken.None).ConfigureAwait(false)) + { + reg = jsonSerializer.DeserializeFromStream<RegRecord>(json); + } + + if (reg.registered) + { + LicenseFile.AddRegCheck(feature); + } + + } + catch (Exception) + { + //if we have trouble obtaining from web - allow it if we've validated in the past 30 days + reg.registered = LicenseFile.LastChecked(feature) > DateTime.UtcNow.AddDays(-30); + } + + return new MBRegistrationRecord {IsRegistered = reg.registered, ExpirationDate = reg.expDate, RegChecked = true}; + } + + /// <summary> + /// Returns MAC Address from first Network Card in Computer + /// </summary> + /// <returns>[string] MAC Address</returns> + public static string GetMacAddress() + { + var mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); + var moc = mc.GetInstances(); + var macAddress = String.Empty; + foreach (ManagementObject mo in moc) + { + if (macAddress == String.Empty) // only return MAC Address from first card + { + try + { + if ((bool)mo["IPEnabled"]) macAddress = mo["MacAddress"].ToString(); + } + catch + { + mo.Dispose(); + return ""; + } + } + mo.Dispose(); + } + + return macAddress.Replace(":", ""); + } + } + + class RegRecord + { + public string featId { get; set; } + public bool registered { get; set; } + public DateTime expDate { get; set; } + } +} diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index c7c3b3a57..c71cf3802 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -2,8 +2,8 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Security; using MediaBrowser.Model.Serialization; +using Mediabrowser.Common.Implementations.Security; using Mediabrowser.Model.Entities; -using Mediabrowser.PluginSecurity; using MediaBrowser.Common.Net; using System; using System.Threading; diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index ccaabd438..3c60d3a39 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; @@ -33,7 +32,7 @@ namespace MediaBrowser.Controller.Entities /// Gets or sets the name. /// </summary> /// <value>The name.</value> - public virtual string Name { get; set; } + public string Name { get; set; } /// <summary> /// Gets or sets the id. @@ -478,7 +477,7 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The end date.</value> public DateTime? EndDate { get; set; } - + /// <summary> /// Gets or sets the display type of the media. /// </summary> @@ -570,7 +569,7 @@ namespace MediaBrowser.Controller.Entities /// </summary> /// <value>The production locations.</value> public List<string> ProductionLocations { get; set; } - + /// <summary> /// Gets or sets the community rating. /// </summary> diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index fed6bb7de..5816b23f8 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -127,7 +127,7 @@ namespace MediaBrowser.Controller.Entities /// <returns>IEnumerable{BaseItem}.</returns> protected IEnumerable<BaseItem> GetIndexByPerformer(User user) { - return GetIndexByPerson(user, new List<string> { PersonType.Actor, PersonType.MusicArtist }, LocalizedStrings.Instance.GetString("PerformerDispPref")); + return GetIndexByPerson(user, new List<string> { PersonType.Actor, PersonType.MusicArtist, PersonType.GuestStar }, LocalizedStrings.Instance.GetString("PerformerDispPref")); } /// <summary> diff --git a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs index d539ed771..e0091cd80 100644 --- a/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs +++ b/MediaBrowser.Controller/Providers/BaseItemXmlParser.cs @@ -242,7 +242,6 @@ namespace MediaBrowser.Controller.Providers } case "Actors": - case "GuestStars": { foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.Actor })) { @@ -255,6 +254,19 @@ namespace MediaBrowser.Controller.Providers break; } + case "GuestStars": + { + foreach (var p in SplitNames(reader.ReadElementContentAsString()).Select(v => new PersonInfo { Name = v.Trim(), Type = PersonType.GuestStar })) + { + if (string.IsNullOrWhiteSpace(p.Name)) + { + continue; + } + item.AddPerson(p); + } + break; + } + case "Trailer": { var val = reader.ReadElementContentAsString(); diff --git a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs index 53ff94720..1c4c783c4 100644 --- a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs +++ b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs @@ -63,7 +63,20 @@ namespace MediaBrowser.Controller.Providers { // If the IBN location exists return the last modified date of any file in it var location = GetLocation(item); - return Directory.Exists(location) ? FileSystem.GetFiles(location).Select(f => f.CreationTimeUtc > f.LastWriteTimeUtc ? f.CreationTimeUtc : f.LastWriteTimeUtc).Max() : DateTime.MinValue; + + if (!Directory.Exists(location)) + { + return DateTime.MinValue; + } + + var files = FileSystem.GetFiles(location).ToList(); + + if (files.Count == 0) + { + return DateTime.MinValue; + } + + return files.Select(f => f.CreationTimeUtc > f.LastWriteTimeUtc ? f.CreationTimeUtc : f.LastWriteTimeUtc).Max(); } /// <summary> diff --git a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs index 6be0881b4..b5c6df7ec 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteEpisodeProvider.cs @@ -263,21 +263,21 @@ namespace MediaBrowser.Controller.Providers.TV var actors = doc.SafeGetString("//GuestStars"); if (actors != null) { - episode.AddPeople(actors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = "Actor", Name = str })); + episode.AddPeople(actors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = PersonType.GuestStar, Name = str })); } var directors = doc.SafeGetString("//Director"); if (directors != null) { - episode.AddPeople(directors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = "Director", Name = str })); + episode.AddPeople(directors.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = PersonType.Director, Name = str })); } var writers = doc.SafeGetString("//Writer"); if (writers != null) { - episode.AddPeople(writers.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = "Writer", Name = str })); + episode.AddPeople(writers.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(str => new PersonInfo { Type = PersonType.Writer, Name = str })); } if (ConfigurationManager.Configuration.SaveLocalMeta) diff --git a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs index f4e6d7893..89cb89289 100644 --- a/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs +++ b/MediaBrowser.Controller/Providers/TV/RemoteSeriesProvider.cs @@ -322,7 +322,7 @@ namespace MediaBrowser.Controller.Providers.TV personNode.AppendChild(doc.ImportNode(subNode, true)); //need to add the type var typeNode = doc.CreateNode(XmlNodeType.Element, "Type", null); - typeNode.InnerText = "Actor"; + typeNode.InnerText = PersonType.Actor; personNode.AppendChild(typeNode); actorsNode.AppendChild(personNode); } diff --git a/MediaBrowser.Model/Entities/MBRegistrationRecord.cs b/MediaBrowser.Model/Entities/MBRegistrationRecord.cs index 1349da4d3..5eeb07a66 100644 --- a/MediaBrowser.Model/Entities/MBRegistrationRecord.cs +++ b/MediaBrowser.Model/Entities/MBRegistrationRecord.cs @@ -4,10 +4,10 @@ namespace Mediabrowser.Model.Entities { public class MBRegistrationRecord { - public DateTime ExpirationDate = DateTime.MinValue; - public bool IsRegistered = false; - public bool RegChecked = false; - public bool RegError = false; + public DateTime ExpirationDate { get; set; } + public bool IsRegistered { get; set;} + public bool RegChecked { get; set; } + public bool RegError { get; set; } private bool? _isInTrial; public bool TrialVersion { diff --git a/MediaBrowser.Model/Entities/PersonType.cs b/MediaBrowser.Model/Entities/PersonType.cs index fca1fbf20..e8c46e29a 100644 --- a/MediaBrowser.Model/Entities/PersonType.cs +++ b/MediaBrowser.Model/Entities/PersonType.cs @@ -26,5 +26,9 @@ namespace MediaBrowser.Model.Entities /// The music artist /// </summary> public const string MusicArtist = "MusicArtist"; + /// <summary> + /// The guest star + /// </summary> + public const string GuestStar = "GuestStar"; } } diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index 86886d751..59a5e938d 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -120,7 +120,7 @@ namespace MediaBrowser.Model.Querying /// If the Person filter is used, this can also be used to restrict to a specific person type /// </summary> /// <value>The type of the person.</value> - public string PersonType { get; set; } + public string[] PersonTypes { get; set; } /// <summary> /// Search characters used to find items diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs index b1402eec7..4c7dd1da6 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs @@ -105,6 +105,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer DefaultRedirectPath = defaultRedirectpath; _logger = logger; + ServiceStack.Logging.LogManager.LogFactory = new NLogFactory(); + EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; @@ -136,58 +138,56 @@ namespace MediaBrowser.Server.Implementations.HttpServer Plugins.Add(new SwaggerFeature()); Plugins.Add(new CorsFeature()); - ServiceStack.Logging.LogManager.LogFactory = new NLogFactory(); - ResponseFilters.Add((req, res, dto) => + { + var exception = dto as Exception; + + if (exception != null) { - var exception = dto as Exception; + _logger.ErrorException("Error processing request for {0}", exception, req.RawUrl); - if (exception != null) + if (!string.IsNullOrEmpty(exception.Message)) { - _logger.ErrorException("Error processing request for {0}", exception, req.RawUrl); - - if (!string.IsNullOrEmpty(exception.Message)) - { - var error = exception.Message.Replace(Environment.NewLine, " "); - error = RemoveControlCharacters(error); + var error = exception.Message.Replace(Environment.NewLine, " "); + error = RemoveControlCharacters(error); - res.AddHeader("X-Application-Error-Code", error); - } + res.AddHeader("X-Application-Error-Code", error); } + } - if (dto is CompressedResult) - { - // Per Google PageSpeed - // This instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed. - // The correct version of the resource is delivered based on the client request header. - // This is a good choice for applications that are singly homed and depend on public proxies for user locality. - res.AddHeader("Vary", "Accept-Encoding"); - } + if (dto is CompressedResult) + { + // Per Google PageSpeed + // This instructs the proxies to cache two versions of the resource: one compressed, and one uncompressed. + // The correct version of the resource is delivered based on the client request header. + // This is a good choice for applications that are singly homed and depend on public proxies for user locality. + res.AddHeader("Vary", "Accept-Encoding"); + } - var hasOptions = dto as IHasOptions; + var hasOptions = dto as IHasOptions; - if (hasOptions != null) + if (hasOptions != null) + { + // Content length has to be explicitly set on on HttpListenerResponse or it won't be happy + string contentLength; + + if (hasOptions.Options.TryGetValue("Content-Length", out contentLength) && !string.IsNullOrEmpty(contentLength)) { - // Content length has to be explicitly set on on HttpListenerResponse or it won't be happy - string contentLength; + var length = long.Parse(contentLength, UsCulture); - if (hasOptions.Options.TryGetValue("Content-Length", out contentLength) && !string.IsNullOrEmpty(contentLength)) + if (length > 0) { - var length = long.Parse(contentLength, UsCulture); - - if (length > 0) - { - var response = (HttpListenerResponse) res.OriginalResponse; + var response = (HttpListenerResponse)res.OriginalResponse; - response.ContentLength64 = length; + response.ContentLength64 = length; - // Disable chunked encoding. Technically this is only needed when using Content-Range, but - // anytime we know the content length there's no need for it - response.SendChunked = false; - } + // Disable chunked encoding. Technically this is only needed when using Content-Range, but + // anytime we know the content length there's no need for it + response.SendChunked = false; } } - }); + } + }); } /// <summary> diff --git a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs index c33975a64..684b72cc9 100644 --- a/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs +++ b/MediaBrowser.Server.Implementations/IO/DirectoryWatchers.cs @@ -39,6 +39,11 @@ namespace MediaBrowser.Server.Implementations.IO private readonly ConcurrentDictionary<string,string> _tempIgnoredPaths = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase); /// <summary> + /// Any file name ending in any of these will be ignored by the watchers + /// </summary> + private readonly List<string> _alwaysIgnoreFiles = new List<string> {"thumbs.db","small.jpg","albumart.jpg"}; + + /// <summary> /// The timer lock /// </summary> private readonly object _timerLock = new object(); @@ -313,10 +318,18 @@ namespace MediaBrowser.Server.Implementations.IO /// <param name="e">The <see cref="FileSystemEventArgs" /> instance containing the event data.</param> void watcher_Changed(object sender, FileSystemEventArgs e) { + // Ignore when someone manually creates a new folder if (e.ChangeType == WatcherChangeTypes.Created && e.Name == "New folder") { return; } + + // Ignore certain files + if (_alwaysIgnoreFiles.Any(f => e.Name.EndsWith(f, StringComparison.OrdinalIgnoreCase))) + { + return; + } + if (_tempIgnoredPaths.ContainsKey(e.FullPath)) { Logger.Info("Watcher requested to ignore change to " + e.FullPath); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 3bb5472df..ca261a393 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -696,7 +696,7 @@ namespace MediaBrowser.Server.Implementations.Library var tasks = new List<Task>(); - var includedPersonTypes = new[] { PersonType.Actor, PersonType.Director }; + var includedPersonTypes = new[] { PersonType.Actor, PersonType.Director, PersonType.GuestStar }; var people = RootFolder.RecursiveChildren .Where(c => c.People != null) diff --git a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs index 69383f7ed..5cba80850 100644 --- a/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs +++ b/MediaBrowser.WebDashboard/Api/ConfigurationPageInfo.cs @@ -21,13 +21,13 @@ namespace MediaBrowser.WebDashboard.Api /// Gets or sets the plugin id. /// </summary> /// <value>The plugin id.</value> - public Guid PluginId { get; set; } + public string PluginId { get; set; } public ConfigurationPageInfo(IPluginConfigurationPage page) { Name = page.Name; ConfigurationPageType = page.ConfigurationPageType; - PluginId = page.Plugin.Id; + PluginId = page.Plugin.Id.ToString(); } } } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index e7216efb9..861112b50 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <metadata> <id>MediaBrowser.Common.Internal</id> - <version>3.0.72</version> + <version>3.0.75</version> <title>MediaBrowser.Common.Internal</title> <authors>Luke</authors> <owners>ebr,Luke,scottisafool</owners> @@ -12,7 +12,7 @@ <description>Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption.</description> <copyright>Copyright © Media Browser 2013</copyright> <dependencies> - <dependency id="MediaBrowser.Common" version="3.0.72" /> + <dependency id="MediaBrowser.Common" version="3.0.74" /> <dependency id="NLog" version="2.0.0.2000" /> <dependency id="ServiceStack.Text" version="3.9.38" /> <dependency id="protobuf-net" version="2.0.0.621" /> diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index f63072a93..f034329f9 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>MediaBrowser.Common</id> - <version>3.0.72</version> + <version>3.0.75</version> <title>MediaBrowser.Common</title> <authors>Media Browser Team</authors> <owners>ebr,Luke,scottisafool</owners> diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 25a82b71c..1797f275c 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata> <id>MediaBrowser.Server.Core</id> - <version>3.0.72</version> + <version>3.0.75</version> <title>Media Browser.Server.Core</title> <authors>Media Browser Team</authors> <owners>ebr,Luke,scottisafool</owners> @@ -12,7 +12,7 @@ <description>Contains core components required to build plugins for Media Browser Server.</description> <copyright>Copyright © Media Browser 2013</copyright> <dependencies> - <dependency id="MediaBrowser.Common" version="3.0.72" /> + <dependency id="MediaBrowser.Common" version="3.0.75" /> </dependencies> </metadata> <files> |
