From 049ef9b4ecd2c884e0ddb062b606770ef7f2dfa9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 16 Nov 2014 17:46:01 -0500 Subject: update naming methods --- MediaBrowser.Controller/Entities/AdultVideo.cs | 24 +------------ MediaBrowser.Controller/Entities/Movies/Movie.cs | 5 ++- MediaBrowser.Controller/Entities/TV/Series.cs | 5 ++- .../Entities/UserViewBuilder.cs | 20 +++++------ MediaBrowser.Controller/Library/ILibraryManager.cs | 12 +++++++ .../MediaBrowser.Controller.csproj | 1 - MediaBrowser.Controller/Providers/NameParser.cs | 39 ---------------------- 7 files changed, 27 insertions(+), 79 deletions(-) delete mode 100644 MediaBrowser.Controller/Providers/NameParser.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/AdultVideo.cs b/MediaBrowser.Controller/Entities/AdultVideo.cs index ec2913ab4..6c3f7851e 100644 --- a/MediaBrowser.Controller/Entities/AdultVideo.cs +++ b/MediaBrowser.Controller/Entities/AdultVideo.cs @@ -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(); ProductionLocations = new List(); } - - 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; - } } } diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index c0afe3df9..686abdaf5 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -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) { diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index 7f6591287..3d1051b18 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -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) { diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 71e26b23c..aff4af468 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -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) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 68b99e472..615ddd90f 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -361,6 +361,11 @@ namespace MediaBrowser.Controller.Library /// true if [is video file] [the specified path]; otherwise, false. bool IsVideoFile(string path); + /// + /// Determines whether [is audio file] [the specified path]. + /// + /// The path. + /// true if [is audio file] [the specified path]; otherwise, false. bool IsAudioFile(string path); /// @@ -405,5 +410,12 @@ namespace MediaBrowser.Controller.Library /// if set to true [consider seasonless]. /// System.Nullable<System.Int32>. int? GetEpisodeNumberFromFile(string path, bool considerSeasonless); + + /// + /// Parses the name. + /// + /// The name. + /// ItemInfo. + ItemLookupInfo ParseName(string name); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 0457ea72e..420da131e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -266,7 +266,6 @@ - diff --git a/MediaBrowser.Controller/Providers/NameParser.cs b/MediaBrowser.Controller/Providers/NameParser.cs deleted file mode 100644 index cdd0974ea..000000000 --- a/MediaBrowser.Controller/Providers/NameParser.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Text.RegularExpressions; - -namespace MediaBrowser.Controller.Providers -{ - public static class NameParser - { - static readonly Regex[] NameMatches = - { - new Regex(@"(?.*)\((?\d{4})\)"), // matches "My Movie (2001)" and gives us the name and the year - new Regex(@"(?.*)(\.(?\d{4})(\.|$)).*$"), - new Regex(@"(?.*)") // last resort matches the whole string as the name - }; - - /// - /// Parses the name. - /// - /// The name. - /// Name of the just. - /// The year. - 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; - } - } - } - } -} -- cgit v1.2.3