internal static string[] MatchXpathExpressionReturnAllMatches
            (string html, string xPathExpression)
        {


            var doc = new HtmlDocument();

            doc.LoadHtml(html);

            HtmlAgilityPack.HtmlNodeCollection htmlNodesCollection
                = doc.DocumentNode.SelectNodes
                    (xPathExpression);

            var matches = new List<string>();

            foreach (var htmlNode in htmlNodesCollection)
            {
                matches.Add(htmlNode.InnerText);

            }





            return matches.ToArray();

        }
示例#2
0
        static public bool DownloadMovieDetails(VideoTags videoTags)
        {
            // The new v3 database is accessed via the TMDbLib API's
            try
            {
                TMDbClient client = new TMDbClient(MCEBUDDY_TMDB_APIKey);
                List<SearchMovie> movieSearch = new List<SearchMovie>();
                Movie movieMatch = null;

                // TODO: Add support for multiple language searches
                if (String.IsNullOrWhiteSpace(videoTags.imdbId)) // If dont' have a specific movieId specified, look up the movie details
                {
                    if (videoTags.OriginalBroadcastDateTime > GlobalDefs.NO_BROADCAST_TIME) // Release date narrow down
                    {
                        // The information is stored on the server using the network timezone
                        // So we assume that the show being converted was recorded locally and is converted locally so the timezones match
                        DateTime dt = videoTags.OriginalBroadcastDateTime.ToLocalTime();
                        movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, dt.Year).Results;
                    }
                    else // Title Check
                        movieSearch = client.SearchMovie(videoTags.Title.Trim().ToLower(), 0, true, 0).Results;
                }
                else // Specific ID
                {
                    movieMatch = client.GetMovie(videoTags.imdbId); // We have a specific movie to work with
                }

                if (movieMatch == null) // If we haven't forced a movie match
                {
                    foreach (SearchMovie movieResult in movieSearch) // Cycle through all possible combinations
                    {
                        Movie movie = client.GetMovie(movieResult.Id);
                        List<AlternativeTitle> akaValues = null;
                        if (movie.AlternativeTitles != null)
                            akaValues = movie.AlternativeTitles.Titles;
                        bool akaMatch = false;
                        string title = videoTags.Title;
                        if (akaValues != null) // Check if there are any AKA names to match
                            akaMatch = akaValues.Any(s => (String.Compare(s.Title.Trim(), title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) == 0 ? true : false));

                        // Get and match Movie name (check both titles and aka values)
                        if (String.Compare(movie.Title.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters
                            if (String.Compare(movie.OriginalTitle.Trim(), videoTags.Title.Trim(), CultureInfo.InvariantCulture, (CompareOptions.IgnoreSymbols | CompareOptions.IgnoreCase)) != 0) // ignore white space and special characters
                                if (!akaMatch) // check for aka value matches
                                    continue; // No match in name

                        // If we got here, then we found a match
                        movieMatch = movie;
                        break; // We are done here
                    }
                }

                if (movieMatch != null) // We have a match
                {
                    if (!String.IsNullOrWhiteSpace(videoTags.imdbId)) // Match names only if the movie imdb id is not forced, else take what is returned by moviedb
                        videoTags.Title = movieMatch.Title; // Take what is forced for the imdb movie id

                    // Get Movie Id
                    videoTags.tmdbId = movieMatch.Id.ToString();

                    videoTags.IsMovie = true; // this is a movie

                    // Get Overview
                    string overview = movieMatch.Overview;
                    if (!String.IsNullOrWhiteSpace(overview) && String.IsNullOrWhiteSpace(videoTags.Description))
                        videoTags.Description = overview;

                    // Get original release date
                    if (movieMatch.ReleaseDate != null)
                    {
                        DateTime releaseDate = (DateTime)movieMatch.ReleaseDate;
                        if (releaseDate > GlobalDefs.NO_BROADCAST_TIME)
                            if ((videoTags.OriginalBroadcastDateTime <= GlobalDefs.NO_BROADCAST_TIME) || (videoTags.OriginalBroadcastDateTime.Date > releaseDate.Date)) // Sometimes the metadata from the video recordings are incorrect and report the recorded date (which is more recent than the release date) then use MovieDB dates, MovieDB Dates are more reliable than video metadata usually
                                videoTags.OriginalBroadcastDateTime = releaseDate; // MovieDB stores time in network (local) timezone
                    }

                    // Get Genres
                    List<string> genres = new List<string>();
                    foreach (Genre genre in movieMatch.Genres)
                    {
                        genres.Add(genre.Name);
                    }
                    if (genres.Count > 0)
                    {
                        if (videoTags.Genres != null)
                        {
                            if (videoTags.Genres.Length == 0)
                                videoTags.Genres = genres.ToArray();
                        }
                        else
                            videoTags.Genres = genres.ToArray();
                    }

                    // Download the banner file
                    client.GetConfig(); // First we need to get the config
                    VideoMetaData.DownloadBannerFile(videoTags, client.GetImageUrl("original", movieMatch.PosterPath).OriginalString); // Get bannerfile

                    return true; // home free, we're good
                }

                return false;
            }
            catch
            {
                return false;
            }
        }