예제 #1
0
        public static bool DownloadSeriesDetails(VideoTags videoTags, bool prioritizeMatchDate, bool dontOverwriteTitle, Log jobLog)
        {
            XPathDocument     Xp;
            XPathNavigator    Nav;
            XPathExpression   Exp;
            XPathNodeIterator Itr;

            // There are no TheTVDB mirrors, so skip that step

            // ******************
            // Get the series ID
            // ******************
            try
            {
                if (!String.IsNullOrWhiteSpace(videoTags.imdbId)) // If we have a specific IMDB movieId specified, look up the movie details on TVDB
                {
                    Xp = new XPathDocument("http://www.thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=" + videoTags.imdbId);
                }
                else if (!String.IsNullOrWhiteSpace(videoTags.tvdbId)) // If we have a specific TVDB seriesId specified, look up the series details
                {
                    // First match by Episode name and then by Original broadcast date (by default prioritize match date is false)
                    if (!MatchSeriesInformation(videoTags, videoTags.tvdbId, prioritizeMatchDate, dontOverwriteTitle, jobLog))
                    {
                        return(MatchSeriesInformation(videoTags, videoTags.tvdbId, !prioritizeMatchDate, dontOverwriteTitle, jobLog));
                    }
                    else
                    {
                        return(true);
                    }
                }
                else // Generic search by name
                {
                    Xp = new XPathDocument("http://www.thetvdb.com/api/GetSeries.php?seriesname=" + videoTags.Title);
                }

                Nav = Xp.CreateNavigator();
                Exp = Nav.Compile("//Data/Series");
                Itr = Nav.Select(Exp);
            }
            catch (Exception e)
            {
                jobLog.WriteEntry("Unable to connect to TVDB\r\nError -> " + e.ToString(), Log.LogEntryType.Warning);
                return(false);
            }

            while (Itr.MoveNext()) // loop through all series returned trying to find a match
            {
                string   seriesID    = XML.GetXMLTagValue("seriesid", Itr.Current.OuterXml);
                string   seriesTitle = XML.GetXMLTagValue("SeriesName", Itr.Current.OuterXml);
                string[] aliasNames  = XML.GetXMLTagValue("AliasNames", Itr.Current.OuterXml).Split('|'); // sometimes the alias matches

                // Compare the series title with the title of the recording
                if ((String.Compare(seriesTitle.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) &&
                    (!aliasNames.Any(s => (String.Compare(s.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) == 0))))
                {
                    continue; // Name mismatch
                }
                if (String.IsNullOrWhiteSpace(seriesID))
                {
                    continue; // can't do anything without seriesID
                }
                // First match by Episode name and then by Original broadcast date (by default prioritize match date is false)
                if (!MatchSeriesInformation(videoTags, seriesID, prioritizeMatchDate, dontOverwriteTitle, jobLog))
                {
                    if (MatchSeriesInformation(videoTags, seriesID, !prioritizeMatchDate, dontOverwriteTitle, jobLog))
                    {
                        return(true);
                    }

                    // Else we continue looping through the returned series looking for a match if nothing matches
                }
                else
                {
                    return(true);
                }
            }

            jobLog.WriteEntry("No match found on TVDB", Log.LogEntryType.Debug);

            return(false); // no match found
        }