fixes #640 - Add management filters

pull/702/head
Luke Pulverenti 11 years ago
parent 42a2522637
commit ad52d8b5d9

@ -1,4 +1,5 @@
using System.Globalization; using System.Globalization;
using System.IO;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -6,6 +7,7 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying; using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost; 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")] [ApiMember(Name = "MaxPremiereDate", Description = "Optional. The maximum premiere date. Format = yyyyMMddHHmmss", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string MaxPremiereDate { get; set; } 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> /// <summary>
@ -1029,9 +1046,92 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => i.PremiereDate.HasValue && i.PremiereDate.Value <= date); 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; 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> /// <summary>
/// Determines whether the specified item has image. /// Determines whether the specified item has image.
/// </summary> /// </summary>

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

@ -262,7 +262,10 @@ namespace MediaBrowser.Controller.Entities
{ {
if (!IsInMixedFolder) 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(); return base.GetDeletePaths();

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

@ -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;
}
}
}
}
}

@ -1,10 +1,14 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" /> <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> <Files>
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="259" Column="4" /> <File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="58" Column="12" /> <File FileName="MediaBrowser.Server.Mono\IO\FileSystemFactory.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\IO\FileSystemFactory.cs" Line="22" 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> </Files>
<Pads> <Pads>
<Pad Id="ProjectPad"> <Pad Id="ProjectPad">
@ -16,10 +20,13 @@
<Node name="References" expanded="True" /> <Node name="References" expanded="True" />
<Node name="Web" expanded="True" /> <Node name="Web" expanded="True" />
</Node> </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="MediaBrowser.Server.Mono" expanded="True">
<Node name="IO" expanded="True" /> <Node name="References" expanded="True" />
<Node name="Program.cs" selected="True" />
</Node> </Node>
</State> </State>
</Pad> </Pad>

@ -15,7 +15,6 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -190,12 +189,6 @@ namespace MediaBrowser.Providers.Movies
internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669"; internal static string ApiKey = "f6bd687ffa63cd282b6ff2c6877f2669";
internal static string AcceptHeader = "application/json,image/*"; 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) protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
{ {
if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb))) if (string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)))
@ -309,30 +302,6 @@ namespace MediaBrowser.Providers.Movies
return false; 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> /// <summary>
/// Finds the id. /// Finds the id.
/// </summary> /// </summary>
@ -343,7 +312,7 @@ namespace MediaBrowser.Providers.Movies
{ {
int? yearInName; int? yearInName;
string name = item.Name; string name = item.Name;
ParseName(name, out name, out yearInName); NameParser.ParseName(name, out name, out yearInName);
var year = item.ProductionYear ?? yearInName; var year = item.ProductionYear ?? yearInName;

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

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

@ -9,6 +9,7 @@
<package id="ServiceStack" version="3.9.70" targetFramework="net45" /> <package id="ServiceStack" version="3.9.70" targetFramework="net45" />
<package id="ServiceStack.Api.Swagger" 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.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.OrmLite.SqlServer" version="3.9.43" targetFramework="net45" />
<package id="ServiceStack.Redis" 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" /> <package id="ServiceStack.Text" version="3.9.70" targetFramework="net45" />

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

@ -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)
};
}
}
}

@ -1,4 +1,5 @@
using MediaBrowser.Providers.Movies; using MediaBrowser.Controller.Providers;
using MediaBrowser.Providers.Movies;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MediaBrowser.Tests.Providers { namespace MediaBrowser.Tests.Providers {
@ -8,27 +9,27 @@ namespace MediaBrowser.Tests.Providers {
public void TestNameMatches() { public void TestNameMatches() {
var name = string.Empty; var name = string.Empty;
int? year = null; 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("My Movie", name);
Assert.AreEqual(2013, year); Assert.AreEqual(2013, year);
name = string.Empty; name = string.Empty;
year = null; 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("My Movie 2", name);
Assert.AreEqual(2013, year); Assert.AreEqual(2013, year);
name = string.Empty; name = string.Empty;
year = null; 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("My Movie 2001", name);
Assert.AreEqual(2013, year); Assert.AreEqual(2013, year);
name = string.Empty; name = string.Empty;
year = null; 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("My Movie - 2", name);
Assert.AreEqual(2013, year); Assert.AreEqual(2013, year);
name = string.Empty; name = string.Empty;
year = null; 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("curse.of.chucky", name);
Assert.AreEqual(2013, year); Assert.AreEqual(2013, year);
} }

Loading…
Cancel
Save