From 3ef0ddcd120124e896f69e15bf238140f6e03344 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 28 Aug 2013 11:56:56 -0400 Subject: [PATCH] improve flexibility of tvdb search. try yearless search if nothing comes back initially --- .../TV/RemoteSeriesProvider.cs | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Providers/TV/RemoteSeriesProvider.cs b/MediaBrowser.Providers/TV/RemoteSeriesProvider.cs index 307094d19..edd60d304 100644 --- a/MediaBrowser.Providers/TV/RemoteSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/RemoteSeriesProvider.cs @@ -194,7 +194,7 @@ namespace MediaBrowser.Providers.TV if (string.IsNullOrEmpty(seriesId)) { - seriesId = await GetSeriesId(series, cancellationToken); + seriesId = await FindSeries(series.Name, cancellationToken).ConfigureAwait(false); } cancellationToken.ThrowIfCancellationRequested(); @@ -446,34 +446,15 @@ namespace MediaBrowser.Providers.TV return item.ResolveArgs.ContainsMetaFileByName(LocalMetaFileName); } - /// - /// Gets the series id. - /// - /// The item. - /// The cancellation token. - /// Task{System.String}. - private async Task GetSeriesId(BaseItem item, CancellationToken cancellationToken) - { - var seriesId = item.GetProviderId(MetadataProviders.Tvdb); - if (string.IsNullOrEmpty(seriesId)) - { - seriesId = await FindSeries(item.Name, cancellationToken).ConfigureAwait(false); - } - return seriesId; - } - - /// /// Finds the series. /// /// The name. /// The cancellation token. /// Task{System.String}. - public async Task FindSeries(string name, CancellationToken cancellationToken) + private async Task FindSeries(string name, CancellationToken cancellationToken) { - - //nope - search for it - string url = string.Format(RootUrl + SeriesQuery, WebUtility.UrlEncode(name)); + var url = string.Format(RootUrl + SeriesQuery, WebUtility.UrlEncode(name)); var doc = new XmlDocument(); using (var results = await HttpClient.Get(new HttpRequestOptions @@ -489,8 +470,8 @@ namespace MediaBrowser.Providers.TV if (doc.HasChildNodes) { - XmlNodeList nodes = doc.SelectNodes("//Series"); - string comparableName = GetComparableName(name); + var nodes = doc.SelectNodes("//Series"); + var comparableName = GetComparableName(name); if (nodes != null) foreach (XmlNode node in nodes) { @@ -509,6 +490,16 @@ namespace MediaBrowser.Providers.TV } } + // Try stripping off the year if it was supplied + var parenthIndex = name.LastIndexOf('('); + + if (parenthIndex != -1) + { + var newName = name.Substring(0, parenthIndex); + + return await FindSeries(newName, cancellationToken); + } + Logger.Info("TVDb Provider - Could not find " + name + ". Check name on Thetvdb.org."); return null; }