fixes #640 - Add management filters

This commit is contained in:
Luke Pulverenti 2013-12-01 21:24:14 -05:00
parent 42a2522637
commit ad52d8b5d9
13 changed files with 183 additions and 85 deletions

View File

@ -1,4 +1,5 @@
using System.Globalization;
using System.IO;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
@ -6,6 +7,7 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
@ -212,6 +214,21 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "MaxPremiereDate", Description = "Optional. The maximum premiere date. Format = yyyyMMddHHmmss", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MaxPremiereDate { get; set; }
[ApiMember(Name = "HasOverview", Description = "Optional filter by items that have an overview or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasOverview { get; set; }
[ApiMember(Name = "HasImdbId", Description = "Optional filter by items that have an imdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasImdbId { get; set; }
[ApiMember(Name = "HasTmdbId", Description = "Optional filter by items that have a tmdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasTmdbId { get; set; }
[ApiMember(Name = "HasTvdbId", Description = "Optional filter by items that have a tvdb id or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasTvdbId { get; set; }
[ApiMember(Name = "IsYearMismatched", Description = "Optional filter by items that are potentially misidentified.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsYearMismatched { get; set; }
}
/// <summary>
@ -1029,9 +1046,92 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => i.PremiereDate.HasValue && i.PremiereDate.Value <= date);
}
if (request.HasOverview.HasValue)
{
var filterValue = request.HasOverview.Value;
items = items.Where(i =>
{
var hasValue = !string.IsNullOrEmpty(i.Overview);
return hasValue == filterValue;
});
}
if (request.HasImdbId.HasValue)
{
var filterValue = request.HasImdbId.Value;
items = items.Where(i =>
{
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Imdb));
return hasValue == filterValue;
});
}
if (request.HasTmdbId.HasValue)
{
var filterValue = request.HasTmdbId.Value;
items = items.Where(i =>
{
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tmdb));
return hasValue == filterValue;
});
}
if (request.HasTvdbId.HasValue)
{
var filterValue = request.HasTvdbId.Value;
items = items.Where(i =>
{
var hasValue = !string.IsNullOrEmpty(i.GetProviderId(MetadataProviders.Tvdb));
return hasValue == filterValue;
});
}
if (request.IsYearMismatched.HasValue)
{
var filterValue = request.IsYearMismatched.Value;
items = items.Where(i => IsYearMismatched(i) == filterValue);
}
return items;
}
private bool IsYearMismatched(BaseItem item)
{
if (item.ProductionYear.HasValue)
{
var path = item.Path;
if (!string.IsNullOrEmpty(path))
{
int? yearInName;
string name;
NameParser.ParseName(Path.GetFileName(path), out name, out yearInName);
// Go up a level if we didn't get a year
if (!yearInName.HasValue)
{
NameParser.ParseName(Path.GetFileName(Path.GetDirectoryName(path)), out name, out yearInName);
}
if (yearInName.HasValue)
{
return yearInName.Value != item.ProductionYear.Value;
}
}
}
return false;
}
/// <summary>
/// Determines whether the specified item has image.
/// </summary>

View File

@ -138,6 +138,7 @@ namespace MediaBrowser.Controller.Entities
/// Gets or sets the type of the location.
/// </summary>
/// <value>The type of the location.</value>
[IgnoreDataMember]
public virtual LocationType LocationType
{
get

View File

@ -262,7 +262,10 @@ namespace MediaBrowser.Controller.Entities
{
if (!IsInMixedFolder)
{
return new[] { System.IO.Path.GetDirectoryName(Path) };
if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
{
return new[] { System.IO.Path.GetDirectoryName(Path) };
}
}
return base.GetDeletePaths();

View File

@ -117,6 +117,7 @@
<Compile Include="Notifications\NotificationUpdateEventArgs.cs" />
<Compile Include="Providers\IDynamicInfoProvider.cs" />
<Compile Include="Providers\IImageProvider.cs" />
<Compile Include="Providers\NameParser.cs" />
<Compile Include="Session\ISessionManager.cs" />
<Compile Include="Drawing\ImageExtensions.cs" />
<Compile Include="Entities\AggregateFolder.cs" />

View File

@ -0,0 +1,39 @@
using System;
using System.Text.RegularExpressions;
namespace MediaBrowser.Controller.Providers
{
public static class NameParser
{
static readonly Regex[] NameMatches = new[] {
new Regex(@"(?<name>.*)\((?<year>\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year
new Regex(@"(?<name>.*)(\.(?<year>\d{4})(\.|$)).*$"),
new Regex(@"(?<name>.*)") // last resort matches the whole string as the name
};
/// <summary>
/// Parses the name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="justName">Name of the just.</param>
/// <param name="year">The year.</param>
public static void ParseName(string name, out string justName, out int? year)
{
justName = null;
year = null;
foreach (var re in NameMatches)
{
Match m = re.Match(name);
if (m.Success)
{
justName = m.Groups["name"].Value.Trim();
string y = m.Groups["year"] != null ? m.Groups["year"].Value : null;
int temp;
year = Int32.TryParse(y, out temp) ? temp : (int?)null;
break;
}
}
}
}
}

View File

@ -1,10 +1,14 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Program.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Implementations\Persistence\SqliteExtensions.cs">
<Files>
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="259" Column="4" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="58" Column="12" />
<File FileName="MediaBrowser.Server.Mono\IO\FileSystemFactory.cs" Line="22" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\IO\FileSystemFactory.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Implementations\Persistence\SqliteExtensions.cs" Line="2" Column="14" />
<File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\Assemblies.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="1" Column="1" />
</Files>
<Pads>
<Pad Id="ProjectPad">
@ -16,10 +20,13 @@
<Node name="References" expanded="True" />
<Node name="Web" expanded="True" />
</Node>
<Node name="MediaBrowser.Server.Implementations" expanded="True" />
<Node name="MediaBrowser.Server.Implementations" expanded="True">
<Node name="Persistence" expanded="True">
<Node name="SqliteExtensions.cs" selected="True" />
</Node>
</Node>
<Node name="MediaBrowser.Server.Mono" expanded="True">
<Node name="IO" expanded="True" />
<Node name="Program.cs" selected="True" />
<Node name="References" expanded="True" />
</Node>
</State>
</Pad>

View File

@ -15,7 +15,6 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
@ -190,12 +189,6 @@ namespace MediaBrowser.Providers.Movies
internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669";
internal static string AcceptHeader = "application/json,image/*";
static readonly Regex[] NameMatches = new[] {
new Regex(@"(?<name>.*)\((?<year>\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year
new Regex(@"(?<name>.*)(\.(?<year>\d{4})(\.|$)).*$"),
new Regex(@"(?<name>.*)") // last resort matches the whole string as the name
};
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
@ -309,30 +302,6 @@ namespace MediaBrowser.Providers.Movies
return false;
}
/// <summary>
/// Parses the name.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="justName">Name of the just.</param>
/// <param name="year">The year.</param>
public static void ParseName(string name, out string justName, out int? year)
{
justName = null;
year = null;
foreach (var re in NameMatches)
{
Match m = re.Match(name);
if (m.Success)
{
justName = m.Groups["name"].Value.Trim();
string y = m.Groups["year"] != null ? m.Groups["year"].Value : null;
int temp;
year = Int32.TryParse(y, out temp) ? temp : (int?)null;
break;
}
}
}
/// <summary>
/// Finds the id.
/// </summary>
@ -343,7 +312,7 @@ namespace MediaBrowser.Providers.Movies
{
int? yearInName;
string name = item.Name;
ParseName(name, out name, out yearInName);
NameParser.ParseName(name, out name, out yearInName);
var year = item.ProductionYear ?? yearInName;

View File

@ -109,19 +109,11 @@ namespace MediaBrowser.Providers.Movies
public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
{
BaseProviderInfo data;
if (!item.ProviderData.TryGetValue(Id, out data))
{
data = new BaseProviderInfo();
item.ProviderData[Id] = data;
}
var imdbId = item.GetProviderId(MetadataProviders.Imdb);
if (string.IsNullOrEmpty(imdbId))
{
data.LastRefreshStatus = ProviderRefreshStatus.Success;
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}
@ -182,9 +174,7 @@ namespace MediaBrowser.Providers.Movies
ParseAdditionalMetadata(item, result);
}
data.LastRefreshStatus = ProviderRefreshStatus.Success;
SetLastRefreshed(item, DateTime.UtcNow);
return true;
}

View File

@ -41,6 +41,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MediaBrowser.BdInfo.1.0.0.5\lib\net20\BDInfo.dll</HintPath>
</Reference>
<Reference Include="Mono.Data.Sqlite">
<HintPath>..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.70\lib\net35\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="ServiceStack, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.3.9.70\lib\net35\ServiceStack.dll</HintPath>
@ -57,6 +60,13 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.Common.3.9.70\lib\net35\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.OrmLite, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.70\lib\net35\ServiceStack.OrmLite.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.OrmLite.Sqlite">
<HintPath>..\packages\ServiceStack.OrmLite.Sqlite.Mono.3.9.70\lib\net35\ServiceStack.OrmLite.Sqlite.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.ServiceInterface, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\ServiceStack.3.9.70\lib\net35\ServiceStack.ServiceInterface.dll</HintPath>
@ -262,6 +272,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="sqlite3.dll" />
<Content Include="swagger-ui\css\hightlight.default.css">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -9,6 +9,7 @@
<package id="ServiceStack" version="3.9.70" targetFramework="net45" />
<package id="ServiceStack.Api.Swagger" version="3.9.70" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.70" targetFramework="net45" />
<package id="ServiceStack.OrmLite.Sqlite.Mono" version="3.9.70" targetFramework="net45" />
<package id="ServiceStack.OrmLite.SqlServer" version="3.9.43" targetFramework="net45" />
<package id="ServiceStack.Redis" version="3.9.43" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.70" targetFramework="net45" />

View File

@ -44,13 +44,13 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Data" />
<Reference Include="Mono.Posix" />
<Reference Include="ServiceStack.Common">
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Common.dll</HintPath>
<HintPath>..\packages\ServiceStack.Common.3.9.70\lib\net35\ServiceStack.Common.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Interfaces">
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Interfaces.dll</HintPath>
<HintPath>..\packages\ServiceStack.Common.3.9.70\lib\net35\ServiceStack.Interfaces.dll</HintPath>
</Reference>
<Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
@ -82,7 +82,6 @@
</Compile>
<Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\NativeApp.cs" />
<Compile Include="Native\HttpClientFactory.cs" />
<Compile Include="Networking\NetworkManager.cs" />
<Compile Include="..\MediaBrowser.ServerApplication\FFMpeg\FFMpegDownloader.cs">
<Link>FFMpeg\FFMpegDownloader.cs</Link>

View File

@ -1,24 +0,0 @@
using System;
using System.Net.Http;
namespace MediaBrowser.ServerApplication.Native
{
/// <summary>
/// Class HttpClientFactory
/// </summary>
public static class HttpClientFactory
{
/// <summary>
/// Gets the HTTP client.
/// </summary>
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
/// <returns>HttpClient.</returns>
public static HttpClient GetHttpClient(bool enableHttpCompression)
{
return new HttpClient()
{
Timeout = TimeSpan.FromSeconds(20)
};
}
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Providers.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Providers.Movies;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MediaBrowser.Tests.Providers {
@ -8,27 +9,27 @@ namespace MediaBrowser.Tests.Providers {
public void TestNameMatches() {
var name = string.Empty;
int? year = null;
MovieDbProvider.ParseName("My Movie (2013)", out name, out year);
NameParser.ParseName("My Movie (2013)", out name, out year);
Assert.AreEqual("My Movie", name);
Assert.AreEqual(2013, year);
name = string.Empty;
year = null;
MovieDbProvider.ParseName("My Movie 2 (2013)", out name, out year);
NameParser.ParseName("My Movie 2 (2013)", out name, out year);
Assert.AreEqual("My Movie 2", name);
Assert.AreEqual(2013, year);
name = string.Empty;
year = null;
MovieDbProvider.ParseName("My Movie 2001 (2013)", out name, out year);
NameParser.ParseName("My Movie 2001 (2013)", out name, out year);
Assert.AreEqual("My Movie 2001", name);
Assert.AreEqual(2013, year);
name = string.Empty;
year = null;
MovieDbProvider.ParseName("My Movie - 2 (2013)", out name, out year);
NameParser.ParseName("My Movie - 2 (2013)", out name, out year);
Assert.AreEqual("My Movie - 2", name);
Assert.AreEqual(2013, year);
name = string.Empty;
year = null;
MovieDbProvider.ParseName("curse.of.chucky.2013.stv.unrated.multi.1080p.bluray.x264-rough", out name, out year);
NameParser.ParseName("curse.of.chucky.2013.stv.unrated.multi.1080p.bluray.x264-rough", out name, out year);
Assert.AreEqual("curse.of.chucky", name);
Assert.AreEqual(2013, year);
}