mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
update naming methods
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
@@ -16,26 +15,5 @@ namespace MediaBrowser.Controller.Entities
|
||||
Taglines = new List<string>();
|
||||
ProductionLocations = new List<string>();
|
||||
}
|
||||
|
||||
public override bool BeforeMetadataRefresh()
|
||||
{
|
||||
var hasChanges = base.BeforeMetadataRefresh();
|
||||
|
||||
if (!ProductionYear.HasValue)
|
||||
{
|
||||
int? yearInName = null;
|
||||
string name;
|
||||
|
||||
NameParser.ParseName(Name, out name, out yearInName);
|
||||
|
||||
if (yearInName.HasValue)
|
||||
{
|
||||
ProductionYear = yearInName;
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanges;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,10 +149,9 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||
|
||||
if (!ProductionYear.HasValue)
|
||||
{
|
||||
int? yearInName = null;
|
||||
string name;
|
||||
var info = LibraryManager.ParseName(Name);
|
||||
|
||||
NameParser.ParseName(Name, out name, out yearInName);
|
||||
var yearInName = info.Year;
|
||||
|
||||
if (yearInName.HasValue)
|
||||
{
|
||||
|
||||
@@ -255,10 +255,9 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||
|
||||
if (!ProductionYear.HasValue)
|
||||
{
|
||||
int? yearInName = null;
|
||||
string name;
|
||||
var info = LibraryManager.ParseName(Name);
|
||||
|
||||
NameParser.ParseName(Name, out name, out yearInName);
|
||||
var yearInName = info.Year;
|
||||
|
||||
if (yearInName.HasValue)
|
||||
{
|
||||
|
||||
@@ -740,7 +740,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
var user = query.User;
|
||||
|
||||
items = items.Where(i => Filter(i, user, query, userDataManager));
|
||||
items = items.Where(i => Filter(i, user, query, userDataManager, libraryManager));
|
||||
|
||||
items = FilterVirtualEpisodes(items,
|
||||
query.IsMissing,
|
||||
@@ -1140,7 +1140,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
};
|
||||
}
|
||||
|
||||
private static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager)
|
||||
private static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager)
|
||||
{
|
||||
if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -1321,7 +1321,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
var filterValue = query.IsYearMismatched.Value;
|
||||
|
||||
if (IsYearMismatched(item) != filterValue)
|
||||
if (IsYearMismatched(item, libraryManager) != filterValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1551,8 +1551,8 @@ namespace MediaBrowser.Controller.Entities
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Apply tag filter
|
||||
var tags = query.Tags;
|
||||
if (tags.Length > 0)
|
||||
@@ -1641,7 +1641,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
return view;
|
||||
}
|
||||
|
||||
public static bool IsYearMismatched(BaseItem item)
|
||||
public static bool IsYearMismatched(BaseItem item, ILibraryManager libraryManager)
|
||||
{
|
||||
if (item.ProductionYear.HasValue)
|
||||
{
|
||||
@@ -1649,14 +1649,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
int? yearInName;
|
||||
string name;
|
||||
NameParser.ParseName(Path.GetFileName(path), out name, out yearInName);
|
||||
var info = libraryManager.ParseName(Path.GetFileName(path));
|
||||
var yearInName = info.Year;
|
||||
|
||||
// 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);
|
||||
info = libraryManager.ParseName(Path.GetFileName(Path.GetDirectoryName(path)));
|
||||
yearInName = info.Year;
|
||||
}
|
||||
|
||||
if (yearInName.HasValue)
|
||||
|
||||
@@ -361,6 +361,11 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <returns><c>true</c> if [is video file] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
bool IsVideoFile(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether [is audio file] [the specified path].
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns><c>true</c> if [is audio file] [the specified path]; otherwise, <c>false</c>.</returns>
|
||||
bool IsAudioFile(string path);
|
||||
|
||||
/// <summary>
|
||||
@@ -405,5 +410,12 @@ namespace MediaBrowser.Controller.Library
|
||||
/// <param name="considerSeasonless">if set to <c>true</c> [consider seasonless].</param>
|
||||
/// <returns>System.Nullable<System.Int32>.</returns>
|
||||
int? GetEpisodeNumberFromFile(string path, bool considerSeasonless);
|
||||
|
||||
/// <summary>
|
||||
/// Parses the name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>ItemInfo.</returns>
|
||||
ItemLookupInfo ParseName(string name);
|
||||
}
|
||||
}
|
||||
@@ -266,7 +266,6 @@
|
||||
<Compile Include="Providers\ItemIdentities.cs" />
|
||||
<Compile Include="Providers\ItemLookupInfo.cs" />
|
||||
<Compile Include="Providers\MetadataRefreshOptions.cs" />
|
||||
<Compile Include="Providers\NameParser.cs" />
|
||||
<Compile Include="Providers\MetadataStatus.cs" />
|
||||
<Compile Include="Providers\ISeriesOrderManager.cs" />
|
||||
<Compile Include="Session\ISessionManager.cs" />
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
public static class NameParser
|
||||
{
|
||||
static readonly Regex[] NameMatches =
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user