public static bool GetCurrentMediaItem(out MediaItem currentMediaItem, out bool isDetailsView)
        {
            ///
            /// Netflix currently uses MovingPictures skin properties, this may change in future.
            ///

            FileLog.Info("Getting selected movie information from Netflix.");

            isDetailsView = true;
            currentMediaItem = new MediaItem();

            // check if we're in details view or main list
            var facade = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow).GetControl(50);
            if (facade != null && facade.IsVisible) isDetailsView = false;

            // get all movie properties
            currentMediaItem.Title = GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.title").Trim();
            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.summary").Trim();
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#MovingPictures.Coverart").Trim();

            int iYear;
            if (int.TryParse(GUIPropertyManager.GetProperty("#MovingPictures.SelectedMovie.year").Trim(), out iYear))
            {
                currentMediaItem.Year = iYear;
            }

            return true;
        }
示例#2
0
        internal static void Play(string url, MediaItem mediaItem)
        {
            if (string.IsNullOrEmpty(url)) return;

            if (!Utility.IsPluginAvailable("OnlineVideos"))
            {
                GUIUtils.ShowNotifyDialog(Localisation.Translation.Trailers, Localisation.Translation.OnlineVideosNotInstalled);
                return;
            }
            else if (Utility.FileVersion(Utility.OnlineVideosPlugin) < new Version(2, 0, 0, 0))
            {
                GUIUtils.ShowNotifyDialog(Localisation.Translation.Trailers, Localisation.Translation.OnlineVideosMinVersionNotInstalled);
                return;
            }

            CurrentMedia = mediaItem;

            if (url.ToLowerInvariant().Contains("youtube.com"))
            {
                // use onlinevideo youtube siteutils to get
                // playback urls from youtube url
                GetTrailerUrl(url);
            }
            else
            {
                BufferTrailer(url);
            }
        }
        public static bool GetCurrentMediaItem(out MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected movie information from My Films.");

            currentMediaItem = new MediaItem();
            selectedMovie = MyFilmsDetail.GetCurrentMovie();

            currentMediaItem.Title = selectedMovie.Title;
            currentMediaItem.Year = selectedMovie.Year;
            currentMediaItem.Poster = selectedMovie.Picture;
            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#myfilms.db.description.value").Trim();

            // Get local file information
            currentMediaItem.FullPath = selectedMovie.File;

            // Check if TMDb ID is available
            int tmdbid = 0;
            if (int.TryParse(selectedMovie.TMDBNumber, out tmdbid))
            {
                if (tmdbid > 0) currentMediaItem.TMDb = tmdbid.ToString();
            }

            // Next best ID to use
            string imdbid = selectedMovie.IMDBNumber;
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9) currentMediaItem.IMDb = imdbid;

            return true;
        }
        public static bool GetCurrentMediaItem(out MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected movie information from MyVideos");

            currentMediaItem = new MediaItem();
            currentMediaItem.Title = GUIPropertyManager.GetProperty("#title").Trim();

            int year;
            var strYear = GUIPropertyManager.GetProperty("#year").Trim();
            if (int.TryParse(strYear, out year))
                currentMediaItem.Year = year;

            // Get IMDb ID
            string imdbid = GUIPropertyManager.GetProperty("#imdbnumber").Trim();
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9)
                currentMediaItem.IMDb = imdbid;

            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#plot").Trim();
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#thumb").Trim();

            // Get Local File Info
            currentMediaItem.FullPath = GUIPropertyManager.GetProperty("#file").Trim();

            // At the very least we should have a file
            if (string.IsNullOrEmpty(currentMediaItem.FullPath))
            {
                // try get the selected item on the facade
                if (SelectedItem != null && !SelectedItem.IsFolder)
                {
                    currentMediaItem.FullPath = SelectedItem.Path;
                }
            }

            return true;
        }
示例#5
0
        public static bool GetCurrentMediaItem(out MediaItem currentMediaItem, WindowType windowType)
        {
            currentMediaItem = new MediaItem();

            switch (windowType)
            {
                case WindowType.Movie:
                    return GetMovieMediaItem(ref currentMediaItem);

                case WindowType.Show:
                    return GetShowMediaItem(ref currentMediaItem);

                case WindowType.Season:
                    return GetSeasonMediaItem(ref currentMediaItem);

                case WindowType.Episode:
                    return GetEpisodeMediaItem(ref currentMediaItem);

                case WindowType.List:
                    return GetListMediaItem(ref currentMediaItem);

            }

            return false;
        }
        public static bool GetCurrentMediaItem(out MediaItem currentMediaItem, out bool isDetailsView)
        {
            FileLog.Info("Getting selected movie information from MovingPictures.");

            currentMediaItem = new MediaItem();
            browser = MovingPicturesCore.Browser;
            isDetailsView = browser.CurrentView.ToString().Equals("DETAILS");

            selectedMovie = browser.SelectedMovie;

            currentMediaItem.Title = selectedMovie.Title;
            currentMediaItem.Year = selectedMovie.Year;
            currentMediaItem.Plot = selectedMovie.Summary;
            currentMediaItem.Poster = selectedMovie.CoverFullPath;

            // Get local file information
            currentMediaItem.FullPath = selectedMovie.LocalMedia.First().FullPath;

            // Check if TMDb ID is available
            string tmdbid = GetTmdbID(selectedMovie);
            if (!string.IsNullOrEmpty(tmdbid)) currentMediaItem.TMDb = tmdbid;

            // Next best ID to use
            string imdbid = selectedMovie.ImdbID;
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9) currentMediaItem.IMDb = imdbid;

            return true;
        }
        public static bool GetCurrentMediaItem(out MediaItem currentMediaItem, out bool isDetailsView)
        {
            FileLog.Info("Getting selected movie information from ShowTimes.");

            // check if we're in details view
            isDetailsView = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow).GetControl(24).IsVisible;

            // get title
            currentMediaItem = new MediaItem();

            if (isDetailsView)
                currentMediaItem.Title = GUIPropertyManager.GetProperty("#st_title").Trim();
            else
                currentMediaItem.Title = GUIPropertyManager.GetProperty("#selecteditem").Trim();

            // clean the title
            currentMediaItem.Title = currentMediaItem.Title.Replace("3D", string.Empty).Trim();

            // get year
            DateTime releaseDate;
            var strReleaseDate = GUIPropertyManager.GetProperty("#st_releasedate").Trim();
            if (DateTime.TryParse(strReleaseDate, out releaseDate))
            {
                // get the year component
                currentMediaItem.Year = releaseDate.Year;
            }

            // get IMDb ID
            string imdbid = GUIPropertyManager.GetProperty("#st_imdb").Trim();
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9)
                currentMediaItem.IMDb = imdbid;

            // get TMDb ID
            int iTMDbID;
            if (int.TryParse(GUIPropertyManager.GetProperty("#st_tmdb").Trim(), out iTMDbID))
                currentMediaItem.TMDb = iTMDbID.ToString();

            // get poster
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#st_poster").Trim();

            // get overview
            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#st_plot").Trim();

            return true;
        }
示例#8
0
        internal static void Play(string filename, MediaItem mediaItem)
        {
            FileLog.Info("Starting playback of local file: {0}", filename);

            GUIGraphicsContext.IsFullScreenVideo = true;
            GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO);

            try
            {
                CurrentFileName = filename;
                g_Player.Play(filename, g_Player.MediaType.Video);
                GUIUtils.SetPlayProperties(mediaItem);
            }
            catch (Exception e)
            {
                FileLog.Info("Failed to play local file with error: {0}", e.Message);
            }
        }
示例#9
0
        private static bool GetEpisodeMediaItem(ref MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected episode information from Trakt.");

            // first get show info
            GetShowMediaItem(ref currentMediaItem);

            currentMediaItem.MediaType = MediaItemType.Episode;

            // get season
            currentMediaItem.Season = int.Parse(GUIPropertyManager.GetProperty("#Trakt.Episode.Season"));

            // get episode
            currentMediaItem.Episode = int.Parse(GUIPropertyManager.GetProperty("#Trakt.Episode.Number"));

            // get episode name
            currentMediaItem.EpisodeName = GUIPropertyManager.GetProperty("#Trakt.Episode.Title");

            // get thumb
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#Trakt.Episode.EpisodeImageFilename");

            return true;
        }
        public List<GUITrailerListItem> Search(MediaItem searchItem)
        {
            var listItems = new List<GUITrailerListItem>();

            // Clear trailer file list, we may be 'aggressive' with our search
            // so this can avoid duplicates in a crude way
            TrailerFiles.Clear();

            // Check local auto-download directory first
            if (AutoDownloadEnabled())
            {
                listItems.AddRange(GetTrailersFromAutoDownloadDirectory(searchItem));
            }

            // Search for Trailer(s) in Sub-Folder of current media
            if (!string.IsNullOrEmpty(searchItem.Directory))
            {
                if (listItems.Count == 0 || PluginSettings.SearchLocalAggressiveSearch)
                {
                    listItems.AddRange(GetTrailersFromCurrentMediaSubFolder(searchItem));
                }

                // Search for Trailer(s) in the current media directory
                if (listItems.Count == 0 || PluginSettings.SearchLocalAggressiveSearch)
                {
                    listItems.AddRange(GetTrailersFromLocalMediaFolder(searchItem));
                }
            }

            // Search for Trailer(s) in dedicated directories
            if (listItems.Count == 0 || PluginSettings.SearchLocalAggressiveSearch)
            {
                listItems.AddRange(GetTrailersFromDedicatedFolder(searchItem));
            }

            return listItems;
        }
示例#11
0
        private static bool GetListMediaItem(ref MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected list item information from Trakt.");

            string listType = GUIPropertyManager.GetProperty("#Trakt.List.ItemType").ToLowerInvariant();

            // check if we're in a list which supports movies, shows, seasons and episodes
            switch (listType)
            {
                case "movie":
                    return GetMovieMediaItem(ref currentMediaItem);

                case "show":
                    return GetShowMediaItem(ref currentMediaItem);

                case "season":
                    return GetSeasonMediaItem(ref currentMediaItem);

                case "episode":
                    return GetEpisodeMediaItem(ref currentMediaItem);
            }

            return true;
        }
        private List<GUITrailerListItem> GetTrailersFromDedicatedFolder(MediaItem searchItem)
        {
            var listItems = new List<GUITrailerListItem>();

            if (!PluginSettings.SearchLocalInDedicatedDirectory) return listItems;

            FileLog.Debug("Searching for trailers from dedicated trailer directory...");

            foreach (var directory in PluginSettings.SearchLocalDedicatedDirectories.Split('|').ToList())
            {
                FileLog.Debug("Searching for local trailers in directory: '{0}'", directory);

                // if we have found trailers we don't need to continue looking
                if (!Directory.Exists(directory) || (listItems.Count > 0 && !PluginSettings.SearchLocalAggressiveSearch)) continue;

                // first check the base directory, this case is for when
                // all movie trailers are together i.e. filenames will be unique
                foreach (var pattern in PluginSettings.SearchLocalDedicatedDirectorySearchPatterns.Split('|').ToList())
                {
                    if (listItems.Count > 0 && !PluginSettings.SearchLocalAggressiveSearch) continue;
                    listItems.AddRange(SearchForLocalTrailers(searchItem, directory, ReplaceVars(searchItem, pattern)));
                }

                // if we have not found any trailers by now, check sub-directories
                // since the sub-directories are unique we can search all files '*'.
                foreach (var subDirectory in PluginSettings.SearchLocalDedicatedSubDirectories.Split('|').ToList())
                {
                    if (listItems.Count > 0 && !PluginSettings.SearchLocalAggressiveSearch) continue;

                    string subdir = string.Format(@"{0}\{1}", directory, ReplaceVars(searchItem, subDirectory));
                    FileLog.Debug("Searching for local trailers in sub-directory: '{0}'", subdir);

                    if (!Directory.Exists(subdir)) continue;
                    listItems.AddRange(SearchForLocalTrailers(searchItem, subdir, "*"));
                }
            }

            FileLog.Info("Found {0} trailer(s) from dedicated trailer directories.", listItems.Count.ToString());

            return listItems;
        }
        private List<GUITrailerListItem> GetTrailersFromCurrentMediaSubFolder(MediaItem searchItem)
        {
            var listItems = new List<GUITrailerListItem>();

            if (!PluginSettings.SearchLocalInSubFolder) return listItems;

            FileLog.Debug("Searching for trailers from local media sub-folder(s)...");

            if (string.IsNullOrEmpty(searchItem.Directory))
            {
                FileLog.Info("No associated directory for search item, cancelling search from current media sub-folder");
                return listItems;
            }

            // Get list of sub-folder names to search in from the base path of the media's filename
            // First get list of common names from the Trailer and Trailers translation string
            var subFolders = new HashSet<string>{ Translation.Trailers, Translation.Trailer, "Trailers", "Trailer" };

            // Add any additional folder names defined by the user, multiple names seperated by pipe char: '|'
            foreach (var folder in PluginSettings.SearchLocalAdditionalSubFolders.Split('|').ToList())
            {
                // ignore invalid folder names
                if (!string.IsNullOrEmpty(folder) && folder.IndexOfAny(Path.GetInvalidPathChars()) == -1)
                {
                    subFolders.Add(folder);
                }
            }

            FileLog.Debug("Searching in the following sub-folders: {0}", string.Join(", ", subFolders.Select(a => a.ToString()).ToArray()));

            // Search for any files with-in defined sub-folders
            foreach (var subfolder in subFolders)
            {
                string directory = Path.Combine(searchItem.Directory, subfolder);
                FileLog.Debug("Searching for local trailers in directory: '{0}'", directory);

                if (!Directory.Exists(directory)) continue;

                listItems.AddRange(SearchForLocalTrailers(searchItem, directory, "*"));
            }

            FileLog.Info("Found {0} trailer(s) from local media sub-folders.", listItems.Count.ToString());

            return listItems;
        }
示例#14
0
        public static void ShowMovieTrailersPluginMenu(TraktMovieSummary movie)
        {
            var images = TmdbCache.GetMovieImages(movie.Ids.Tmdb, true);

            var trailerItem = new MediaItem
            {
                IMDb = movie.Ids.Imdb.ToNullIfEmpty(),
                TMDb = movie.Ids.Tmdb.ToString(),
                Plot = movie.Overview,
                Poster = TmdbCache.GetMoviePosterFilename(images),
                Title = movie.Title,
                Year = movie.Year.GetValueOrDefault(0)
            };
            Trailers.Trailers.SearchForTrailers(trailerItem);
        }
示例#15
0
 public static void ShowTVShowTrailersPluginMenu(TraktShowSummary show)
 {
     var showImages = TmdbCache.GetShowImages(show.Ids.Tmdb, true);
     var trailerItem = new MediaItem
     {
         MediaType = MediaItemType.Show,
         IMDb = show.Ids.Imdb.ToNullIfEmpty(),
         TVDb = show.Ids.Tvdb.ToString(),
         TVRage = show.Ids.TvRage.ToString(),
         TMDb = show.Ids.Tmdb.ToString(),
         Plot = show.Overview,
         Poster = TmdbCache.GetShowPosterFilename(showImages),
         Title = show.Title,
         Year = show.Year.GetValueOrDefault(0),
         AirDate = show.FirstAired.FromISO8601().ToString("yyyy-MM-dd")
     };
     Trailers.Trailers.SearchForTrailers(trailerItem);
 }
示例#16
0
        public static void ShowTVSeasonTrailersPluginMenu(TraktShowSummary show, int season)
        {
            CurrentMediaType = MediaType.Show;
            CurrentShow = show;

            // check for parental controls
            if (PromptForPinCode)
            {
                if (!GUIUtils.ShowPinCodeDialog(TraktSettings.ParentalControlsPinCode))
                {
                    TraktLogger.Warning("Parental controls pin code has not successfully been entered. Window ID = {0}", GUIWindowManager.ActiveWindow);
                    return;
                }
            }

            var showImages = TmdbCache.GetShowImages(show.Ids.Tmdb, true);
            var trailerItem = new MediaItem
            {
                MediaType = MediaItemType.Season,
                IMDb = show.Ids.Imdb.ToNullIfEmpty(),
                TMDb = show.Ids.Tmdb.ToString(),
                TVDb = show.Ids.Tvdb.ToString(),
                TVRage = show.Ids.TvRage.ToString(),
                Plot = show.Overview,
                Poster = TmdbCache.GetShowPosterFilename(showImages),
                Title = show.Title,
                Year = show.Year.GetValueOrDefault(0),
                AirDate = show.FirstAired.FromISO8601().ToString("yyyy-MM-dd"),
                Season = season
            };
            Trailers.Trailers.SearchForTrailers(trailerItem);
        }
示例#17
0
        public static void SearchForTrailers(MediaItem searchItem)
        {
            ReShowTrailerMenu = false;

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                var menuItems = new List<GUITrailerListItem>();

                // add enabled local sources
                foreach (var trailerProvider in TrailerProviders.Where(t => t.IsLocal && t.Enabled))
                {
                    menuItems.AddRange(trailerProvider.Search(searchItem));
                }

                // add enabled online sources
                if (menuItems.Count == 0 || !PluginSettings.SkipOnlineProvidersIfLocalFound)
                {
                    foreach (var trailerProvider in TrailerProviders.Where(t => !t.IsLocal && t.Enabled))
                    {
                        menuItems.AddRange(trailerProvider.Search(searchItem));
                    }
                }

                return menuItems;
            },
            delegate(bool success, object result)
            {
                if (success)
                {
                    FileLog.Debug("Showing Trailer Menu for selection.");
                    var menuItems = result as List<GUITrailerListItem>;
                    if (menuItems.Count > 0)
                    {
                        #region Auto-Play
                        // only one local trailer
                        if (PluginSettings.AutoPlayOnSingleLocalOrOnlineTrailer && menuItems.Where(t => !t.IsOnlineItem && !t.IsSearchItem).Count() == 1)
                        {
                            var localTrailer = menuItems.Find(t => !t.IsOnlineItem);
                            LocalPlayer.Play(localTrailer.URL, localTrailer.CurrentMedia);
                            return;
                        }
                        // only one online trailer
                        else if (PluginSettings.AutoPlayOnSingleLocalOrOnlineTrailer && menuItems.Where(t => t.IsOnlineItem && !t.IsSearchItem).Count() == 1)
                        {
                            var onlineTrailer = menuItems.Find(t => t.IsOnlineItem && !t.IsSearchItem);
                            OnlinePlayer.Play(onlineTrailer.URL, onlineTrailer.CurrentMedia);
                            return;
                        }
                        // only one of anything - doesn't matter if AutoPlay is enabled just do it.
                        else if (menuItems.Count == 1)
                        {
                            FileLog.Info("Only a single result to show, skipping GUI menu selection dialog.");

                            if (menuItems.First().IsSearchItem)
                            {
                                FileLog.Info("Performing online lookup for trailer: {0}", menuItems.First().URL);
                                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.OnlineVideos, menuItems.First().URL);
                            }
                            else if (menuItems.First().IsOnlineItem)
                            {
                                FileLog.Info("Performing online lookup for trailer: {0}", menuItems.First().URL);
                                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.OnlineVideos, menuItems.First().URL);
                            }
                            else
                            {
                                LocalPlayer.Play(menuItems.First().URL, menuItems.First().CurrentMedia);
                            }
                            return;
                        }
                        #endregion

                        #region Show Menu
                        int selectedItem = GUIUtils.ShowMenuDialog(menuItems.First().CurrentMedia.ToString(), menuItems);
                        if (selectedItem >= 0)
                        {
                            // re-show menu after playback is enabled and there is more than one local/online trailer to select.
                            ReShowTrailerMenu = PluginSettings.ReShowMenuAfterTrailerPlay && (menuItems.Count(t => !t.IsSearchItem) > 1);
                            CurrentMediaItem = menuItems[selectedItem].CurrentMedia;

                            // Search or Play?
                            if (menuItems[selectedItem].IsSearchItem)
                            {
                                FileLog.Info("Performing online lookup for trailer: {0}", menuItems[selectedItem].URL);
                                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.OnlineVideos, menuItems[selectedItem].URL);
                            }
                            else if (menuItems[selectedItem].IsOnlineItem)
                            {
                                // play the selected trailer
                                OnlinePlayer.Play(menuItems[selectedItem].URL, menuItems[selectedItem].CurrentMedia);
                            }
                            else
                            {
                                // play local media
                                LocalPlayer.Play(menuItems[selectedItem].URL, menuItems[selectedItem].CurrentMedia);
                            }
                        }
                        else
                        {
                            FileLog.Debug("No Trailer selected for playback or search.");
                        }
                        #endregion
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Trailers, Translation.NoTrailersFound);
                    }
                }
            }, Translation.GettingTrailers, true);
        }
示例#18
0
        private static bool GetShowMediaItem(ref MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected show information from Trakt.");

            currentMediaItem.MediaType = MediaItemType.Show;

            // get title
            currentMediaItem.Title = GUIPropertyManager.GetProperty("#Trakt.Show.Title");

            // get year
            int year;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Show.Year"), out year))
                currentMediaItem.Year = year;

            // get air date
            currentMediaItem.AirDate = GUIPropertyManager.GetProperty("#Trakt.Show.FirstAired");

            // get IMDb ID
            string imdbid = GUIPropertyManager.GetProperty("#Trakt.Show.Imdb");
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9)
                currentMediaItem.IMDb = imdbid;

            // get TMDb ID
            int iTMDbId;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Show.TmdbId"), out iTMDbId))
                currentMediaItem.TMDb = iTMDbId.ToString();

            // get TVDb ID
            int iTVDbID;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Show.TvdbId"), out iTVDbID))
                currentMediaItem.TVDb = iTVDbID.ToString();

            // get TVRage ID
            int iTVRageID;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Show.TvRageId"), out iTVRageID))
                currentMediaItem.TVRage = iTVRageID.ToString();

            // get poster
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#Trakt.Show.PosterImageFilename");

            // get overview
            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#Trakt.Show.Overview");

            return true;
        }
        private List<GUITrailerListItem> SearchForLocalTrailers(MediaItem searchItem, string directory, string searchPattern)
        {
            var listItems = new List<GUITrailerListItem>();

            FileLog.Debug("Searching for local trailers in directory: '{0}', with search pattern: '{1}'", directory, searchPattern);

            // check if string replacements produced a bad search pattern
            if (searchPattern.Contains("**") || searchPattern.Contains("null"))
                return listItems;

            try
            {
                foreach (var file in Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly))
                {
                    // check it's a video file as defined by MediaPortal and User in MP Configuration
                    if (!MediaPortal.Util.Utils.IsVideo(file)) continue;

                    // check it's not a sample
                    if (Path.GetFileName(file).ToLowerInvariant().StartsWith("sample")) continue;

                    // check it's not the same file as the source
                    if (file.Equals(searchItem.FullPath, StringComparison.InvariantCultureIgnoreCase)) continue;

                    // check we have not already got this trailer matched
                    if (TrailerFiles.Contains(file)) continue;

                    FileLog.Debug("Found local trailer that matched search criteria: '{0}'", file);

                    var listItem = new GUITrailerListItem();

                    listItem.Label = Path.GetFileNameWithoutExtension(file);
                    listItem.Label2 = Translation.Local;
                    listItem.URL = file;
                    listItem.CurrentMedia = searchItem;

                    listItems.Add(listItem);

                    // store trailer file in case we are in 'aggressive' mode
                    TrailerFiles.Add(file);
                }
            }
            catch (Exception e)
            {
                FileLog.Error("Failed to get files from '{0}' with error: {1}", directory, e.Message);
            }

            return listItems;
        }
示例#20
0
        internal static void ShowTrailerMenu()
        {
            var mediaItem = new MediaItem
            {
                MediaType = MediaItemType.Show,
                AirDate = m_SelectedSeries[DBOnlineSeries.cFirstAired],
                IMDb = m_SelectedSeries[DBOnlineSeries.cIMDBID],
                Poster = m_SelectedSeries.Poster,
                Plot = m_SelectedSeries[DBOnlineSeries.cSummary],
                Title = m_SelectedSeries[DBOnlineSeries.cOriginalName],
                TVDb = m_SelectedSeries[DBOnlineSeries.cID]                
            };

            int year = 0;
            if (int.TryParse(m_SelectedSeries.Year, out year))
            {
                mediaItem.Year = year;
            }

            if (CurrentViewLevel == Listlevel.Season)
            {
                mediaItem.MediaType = MediaItemType.Season;
                mediaItem.Season = m_SelectedSeason[DBSeason.cIndex];
                mediaItem.Poster = m_SelectedSeason.Banner;
            }
            else if (CurrentViewLevel == Listlevel.Episode)
            {
                mediaItem.MediaType = MediaItemType.Episode;
                mediaItem.Season = m_SelectedEpisode[DBOnlineEpisode.cSeasonIndex];
                mediaItem.Episode = m_SelectedEpisode[DBOnlineEpisode.cEpisodeIndex];
                mediaItem.EpisodeName = m_SelectedEpisode[DBOnlineEpisode.cEpisodeName];
                mediaItem.Plot = m_SelectedEpisode[DBOnlineEpisode.cEpisodeSummary];
                mediaItem.Poster = m_SelectedEpisode[DBOnlineEpisode.cEpisodeThumbnailFilename];

                if (!string.IsNullOrEmpty(m_SelectedEpisode[DBEpisode.cFilename]))
                {
                    mediaItem.FullPath = m_SelectedEpisode[DBEpisode.cFilename];
                }
            }

            Trailers.Trailers.SearchForTrailers(mediaItem);
        }
        public List<GUITrailerListItem> Search(MediaItem searchItem)
        {
            List<GUITrailerListItem> listItems = new List<GUITrailerListItem>();

            switch (searchItem.MediaType)
            {
                case MediaItemType.Movie:
                    listItems = SearchMovieTrailers(searchItem);
                    break;

                case MediaItemType.Show:
                case MediaItemType.Season:
                case MediaItemType.Episode:
                    listItems = SearchShowTrailers(searchItem);
                    break;
            }

            return listItems;
        }
示例#22
0
        public static void SetPlayProperties(MediaItem item, bool onlinevideoplayer = false)
        {
            var playThread = new Thread((obj) =>
            {
                Thread.Sleep(2000);

                var playItem = obj as MediaItem;
                if (playItem == null) return;

                SetProperty("#Play.Current.Title", playItem.Title);
                SetProperty("#Play.Current.Plot", playItem.Plot);
                SetProperty("#Play.Current.Thumb", playItem.Poster);
                SetProperty("#Play.Current.Year", playItem.Year.ToString());
                SetProperty("#Play.Current.IMDBNumber", playItem.IMDb);
                SetProperty("#Play.Current.TMDBNumber", playItem.TMDb);

                // check if we should set any online video specific properties
                if (onlinevideoplayer)
                {
                    SetProperty("#Play.Current.OnlineVideos.SiteName", "YouTube Trailers");
                    SetProperty("#Play.Current.OnlineVideos.SiteIcon", TrailersLogo);
                }
            })
            {
                IsBackground = true,
                Name = "TrailerPlay"
            };

            playThread.Start(item);
        }
        private List<GUITrailerListItem> SearchMovieTrailers(MediaItem searchItem)
        {
            string searchTerm = string.Empty;
            var listItems = new List<GUITrailerListItem>();

            if (!string.IsNullOrEmpty(searchItem.TMDb))
            {
                searchTerm = searchItem.TMDb;
            }
            else if (!string.IsNullOrEmpty((searchItem.IMDb ?? string.Empty).Trim()))
            {
                var externalId = PluginSettings.IMDbIds.FirstOrDefault(t => t.ExternalId == searchItem.IMDb);
                if (externalId == null)
                {
                    // use the find method to lookup by external source id
                    FileLog.Debug("Searching themoviedb.org for all objects with IMDb ID '{0}'", searchItem.IMDb);

                    var findResults = TMDbAPI.TMDbFind(searchItem.IMDb, TMDbAPI.ExternalSource.imdb_id);
                    if (findResults == null || findResults.Movies == null || findResults.Movies.Count == 0)
                    {
                        FileLog.Warning("Not enough information to search for trailers from themoviedb.org, no matches found using IMDb ID");
                        return listItems;
                    }

                    // there should only be one
                    searchTerm = findResults.Movies.First().Id.ToString();

                    // cache id so we can use it again
                    PluginSettings.IMDbIds.Add(new PluginSettings.ExternalID { ExternalId = searchItem.IMDb, TmdbId = findResults.Movies.First().Id });
                }
                else
                {
                    FileLog.Debug("Found cached TMDb ID '{0}' for IMDb External ID: '{1}'", externalId.TmdbId.ToString(), searchItem.IMDb);
                    searchTerm = externalId.TmdbId.ToString();
                }
            }
            else if (!string.IsNullOrEmpty(searchItem.Title))
            {
                // we do the best we can with out any proper movie id's
                FileLog.Debug("Searching themoviedb.org for movie: Title: '{0}', Year: '{1}'", searchItem.Title, searchItem.Year);

                var searchResults = TMDbAPI.SearchMovies(searchItem.Title, language: "en", year: searchItem.Year <= 1900 ? null : searchItem.Year.ToString());
                if (searchResults == null || searchResults.TotalResults == 0)
                {
                    FileLog.Warning("No movies found, skipping search from the themoviedb.org.");
                    return listItems;
                }
                else
                {
                    foreach (var movie in searchResults.Results)
                    {
                        FileLog.Debug("Found movie: Title: '{0}', Original Title: '{1}', Release Date: '{2}', TMDb: '{3}', Popularity: '{4}'", movie.Title, movie.OriginalTitle, movie.ReleaseDate, movie.Id, movie.Popularity);
                    }
                }

                // get the movie id of the first result, this would be the most likely match (based on popularity)
                // we can think about providing a menu of choices as well based on demand
                searchTerm = searchResults.Results.First().Id.ToString();
                searchItem.TMDb = searchTerm;
            }
            else
            {
                FileLog.Warning("Not enough information to search for trailers from themoviedb.org, require IMDb ID, TMDb ID or Title+Year.");
                return listItems;
            }

            FileLog.Debug("Searching for movie trailers using search term '{0}' from themoviedb.org...", searchTerm);
            var trailers = GetMovieTrailersFromCache(searchTerm);
            if (trailers == null || trailers.Results == null)
            {
                FileLog.Error("Error getting movie trailers from themoviedb.org.");
                return listItems;
            }

            foreach (var trailer in trailers.Results)
            {
                var listItem = new GUITrailerListItem();

                string itemName = string.IsNullOrEmpty(trailer.Type) || trailer.Name.ToLowerInvariant().Contains(trailer.Type.ToLowerInvariant()) ? trailer.Name : string.Format("{0} - {1}", trailer.Name, trailer.Type);
                itemName = string.IsNullOrEmpty(trailer.Size) || itemName.ToLowerInvariant().Contains(trailer.Size.ToLowerInvariant()) ? itemName : string.Format("{0} ({1})", itemName, trailer.Size);
                if (PluginSettings.PreferredLanguage != "en")
                {
                    itemName = string.Format("{0} [{1}]", itemName, trailer.LanguageCode);
                }

                listItem.Label = itemName;
                listItem.Label2 = Localisation.Translation.Online;
                listItem.URL = WebUtils.GetYouTubeURL(trailer.Key);
                listItem.TVTag = trailer;
                listItem.IsOnlineItem = true;
                listItem.CurrentMedia = searchItem;

                listItems.Add(listItem);
            }

            FileLog.Info("Found {0} movie trailer(s) from themoviedb.org", trailers.Results.Count.ToString());

            return listItems;
        }
        private List<GUITrailerListItem> GetTrailersFromLocalMediaFolder(MediaItem searchItem)
        {
            var listItems = new List<GUITrailerListItem>();

            if (!PluginSettings.SearchLocalInCurrentMediaFolder) return listItems;
            FileLog.Debug("Searching for trailers from local media folder...");

            if (string.IsNullOrEmpty(searchItem.Directory))
            {
                FileLog.Info("No associated directory for search item, cancelling search from current media folder");
                return listItems;
            }

            foreach (var pattern in PluginSettings.SearchLocalCurrentMediaFolderSearchPatterns.Split('|').ToList())
            {
                if (listItems.Count > 0 && !PluginSettings.SearchLocalAggressiveSearch) continue;
                listItems.AddRange(SearchForLocalTrailers(searchItem, searchItem.Directory, ReplaceVars(searchItem, pattern)));
            }

            FileLog.Info("Found {0} trailer(s) from local media folder.", listItems.Count.ToString());

            return listItems;
        }
        private List<GUITrailerListItem> GetTrailersFromAutoDownloadDirectory(MediaItem searchItem)
        {
            var listItems = new List<GUITrailerListItem>();

            FileLog.Debug("Searching for trailers from local auto-download directory...");

            // trailers in auto-download directory are grouped by movie folder in the form 'title% (%year%) [%imdbid%]'
            // first check with imdbid
            string folder = string.Format("{0} ({1}) [{2}]", searchItem.Title, searchItem.Year, searchItem.IMDb);
            string directory = Path.Combine(PluginSettings.AutoDownloadDirectory, folder.ToCleanFileName());
            if (Directory.Exists(directory))
            {
                FileLog.Debug("Searching for local trailers in directory: '{0}'", directory);
                listItems.AddRange(SearchForLocalTrailers(searchItem, directory, "*"));
            }
            else
            {
                // check with empty imdb id.
                folder = string.Format("{0} ({1}) []", searchItem.Title, searchItem.Year);
                directory = Path.Combine(PluginSettings.AutoDownloadDirectory, folder.ToCleanFileName());

                if (Directory.Exists(directory))
                {
                    FileLog.Debug("Searching for local trailers in directory: '{0}'", directory);
                    listItems.AddRange(SearchForLocalTrailers(searchItem, directory, "*"));
                }
            }

            FileLog.Info("Found {0} trailer(s) from local auto-download directory.", listItems.Count.ToString());

            return listItems;
        }
        private string ReplaceVars(MediaItem searchItem, string searchPattern)
        {
            searchPattern = searchPattern.Replace("%title%", searchItem.Title.ToCleanFileName());
            searchPattern = searchPattern.Replace("%year%", searchItem.Year.ToString());
            searchPattern = searchPattern.Replace("%imdb%", searchItem.IMDb ?? string.Empty);
            searchPattern = searchPattern.Replace("%filename%", searchItem.FilenameWOExtension ?? "null");
            searchPattern = searchPattern.Replace("%episode%", searchItem.Episode.HasValue ? searchItem.Episode.ToString() : string.Empty);
            searchPattern = searchPattern.Replace("%season%", searchItem.Season.HasValue ? searchItem.Season.ToString() : string.Empty);
            searchPattern = searchPattern.Replace("%episodename%", searchItem.EpisodeName ?? string.Empty);
            searchPattern = searchPattern.Replace("%airdate%", searchItem.AirDate ?? string.Empty);

            if (string.IsNullOrEmpty(searchPattern))
                searchPattern = "null";

            return searchPattern;
        }
示例#27
0
        private static bool GetSeasonMediaItem(ref MediaItem currentMediaItem)
        {
            // first get show info
            GetShowMediaItem(ref currentMediaItem);

            FileLog.Info("Getting selected season information from Trakt.");

            currentMediaItem.MediaType = MediaItemType.Season;

            // get season
            currentMediaItem.Season = int.Parse(GUIPropertyManager.GetProperty("#Trakt.Season.Number"));

            // get poster
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#Trakt.Season.PosterImageFilename");

            return true;
        }
示例#28
0
        private List <GUITrailerListItem> SearchForLocalTrailers(MediaItem searchItem, string directory, string searchPattern)
        {
            var listItems = new List <GUITrailerListItem>();

            FileLog.Debug("Searching for local trailers in directory: '{0}', with search pattern: '{1}'", directory, searchPattern);

            // check if string replacements produced a bad search pattern
            if (searchPattern.Contains("**") || searchPattern.Contains("null"))
            {
                return(listItems);
            }

            try
            {
                foreach (var file in Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly))
                {
                    // check it's a video file as defined by MediaPortal and User in MP Configuration
                    if (!MediaPortal.Util.Utils.IsVideo(file))
                    {
                        continue;
                    }

                    // check it's not a sample
                    if (Path.GetFileName(file).ToLowerInvariant().StartsWith("sample"))
                    {
                        continue;
                    }

                    // check it's not the same file as the source
                    if (file.Equals(searchItem.FullPath, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    // check we have not already got this trailer matched
                    if (TrailerFiles.Contains(file))
                    {
                        continue;
                    }

                    FileLog.Debug("Found local trailer that matched search criteria: '{0}'", file);

                    var listItem = new GUITrailerListItem();

                    listItem.Label        = Path.GetFileNameWithoutExtension(file);
                    listItem.Label2       = Translation.Local;
                    listItem.URL          = file;
                    listItem.CurrentMedia = searchItem;

                    listItems.Add(listItem);

                    // store trailer file in case we are in 'aggressive' mode
                    TrailerFiles.Add(file);
                }
            }
            catch (Exception e)
            {
                FileLog.Error("Failed to get files from '{0}' with error: {1}", directory, e.Message);
            }

            return(listItems);
        }
        internal static bool GetCurrentMediaItem(out MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected item information from MP-TVSeries.");

            currentMediaItem = new MediaItem();

            // get the object (series, season, episode assigned to the TVTag of the selected facade item)
            Object obj = SelectedObject;
            if (obj == null)
            {
                FileLog.Error("Error getting selected item from MP-TVSeries");
                currentMediaItem = null;
                return false;
            }

            // store the selected item into the MediaItem object
            switch (GetViewLevel(obj))
            {
                #region Series
                case ViewLevel.Series:
                    var series = obj as DBSeries;
                    currentMediaItem.MediaType = MediaItemType.Show;
                    currentMediaItem.Title = series[DBOnlineSeries.cOriginalName];
                    currentMediaItem.Plot = series[DBOnlineSeries.cSummary];
                    currentMediaItem.IMDb = series[DBOnlineSeries.cIMDBID];
                    currentMediaItem.TVDb = series[DBOnlineSeries.cID];
                    currentMediaItem.AirDate = series[DBOnlineSeries.cFirstAired];
                    currentMediaItem.Poster = series.Poster;

                    DateTime airDate;
                    if (DateTime.TryParse(series[DBOnlineSeries.cFirstAired], out airDate))
                    {
                        currentMediaItem.Year = airDate.Year;
                    }

                    break;
                #endregion

                #region Season
                case ViewLevel.Season:
                    var season = obj as DBSeason;
                    series = Helper.getCorrespondingSeries(season[DBSeason.cSeriesID]);
                    if (series == null)
                    {
                        FileLog.Error("Error getting current series from season view level in MP-TVSeries.");
                        currentMediaItem = null;
                        return false;
                    }

                    currentMediaItem.MediaType = MediaItemType.Season;
                    currentMediaItem.Season = season[DBSeason.cIndex];
                    currentMediaItem.Title = series[DBOnlineSeries.cOriginalName];
                    currentMediaItem.Plot = series[DBOnlineSeries.cSummary];
                    currentMediaItem.IMDb = series[DBOnlineSeries.cIMDBID];
                    currentMediaItem.TVDb = series[DBOnlineSeries.cID];
                    currentMediaItem.AirDate = series[DBOnlineSeries.cFirstAired];
                    currentMediaItem.Poster = series.Poster;

                    if (DateTime.TryParse(series[DBOnlineSeries.cFirstAired], out airDate))
                    {
                        currentMediaItem.Year = airDate.Year;
                    }

                    if (currentMediaItem.Season == null)
                    {
                        FileLog.Error("Error getting season index from current selected item in MP-TVSeries.");
                        currentMediaItem = null;
                        return false;
                    }
                    break;
                #endregion

                #region Episode
                case ViewLevel.Episode:
                    var episode = obj as DBEpisode;
                    series = Helper.getCorrespondingSeries(episode[DBOnlineEpisode.cSeriesID]);
                    if (series == null)
                    {
                        FileLog.Error("Error getting current series from season view level in MP-TVSeries.");
                        currentMediaItem = null;
                        return false;
                    }

                    currentMediaItem.MediaType = MediaItemType.Episode;
                    currentMediaItem.Season = episode[DBOnlineEpisode.cSeasonIndex];
                    currentMediaItem.Episode = episode[DBOnlineEpisode.cEpisodeIndex];
                    currentMediaItem.EpisodeName = episode[DBOnlineEpisode.cEpisodeName];
                    currentMediaItem.Title = series[DBOnlineSeries.cOriginalName];
                    currentMediaItem.Plot = series[DBOnlineSeries.cSummary];
                    currentMediaItem.IMDb = series[DBOnlineSeries.cIMDBID];
                    currentMediaItem.TVDb = series[DBOnlineSeries.cID];
                    currentMediaItem.AirDate = series[DBOnlineSeries.cFirstAired];
                    currentMediaItem.Poster = series.Poster;

                    if (DateTime.TryParse(series[DBOnlineSeries.cFirstAired], out airDate))
                    {
                        currentMediaItem.Year = airDate.Year;
                    }

                    if (currentMediaItem.Season == null || currentMediaItem.Episode == null)
                    {
                        FileLog.Error("Error getting season/episode index from current selected item in MP-TVSeries.");
                        currentMediaItem = null;
                        return false;
                    }
                    break;
                #endregion

                case ViewLevel.Unknown:
                    FileLog.Error("Error getting current view level from MP-TVSeries.");
                    currentMediaItem = null;
                    return false;
            }

            return true;
        }
示例#30
0
        private static bool GetMovieMediaItem(ref MediaItem currentMediaItem)
        {
            FileLog.Info("Getting selected movie information from Trakt.");

            currentMediaItem.MediaType = MediaItemType.Movie;

            // get title
            currentMediaItem.Title = GUIPropertyManager.GetProperty("#Trakt.Movie.Title");

            // get year
            int year;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Movie.Year"), out year))
                currentMediaItem.Year = year;

            // get IMDb ID
            string imdbid = GUIPropertyManager.GetProperty("#Trakt.Movie.ImdbId");
            if (!string.IsNullOrEmpty(imdbid) && imdbid.Length == 9)
                currentMediaItem.IMDb = imdbid;

            // get TMDb ID
            int iTMDbID;
            if (int.TryParse(GUIPropertyManager.GetProperty("#Trakt.Movie.TmdbId"), out iTMDbID))
                currentMediaItem.TMDb = iTMDbID.ToString();

            // get poster
            currentMediaItem.Poster = GUIPropertyManager.GetProperty("#Trakt.Movie.PosterImageFilename");

            // get overview
            currentMediaItem.Plot = GUIPropertyManager.GetProperty("#Trakt.Movie.Overview");

            return true;
        }
        private List<GUITrailerListItem> SearchShowTrailers(MediaItem searchItem)
        {
            string searchTerm = string.Empty;
            var listItems = new List<GUITrailerListItem>();

            if (!string.IsNullOrEmpty(searchItem.TMDb))
            {
                searchTerm = searchItem.TMDb;
            }
            else if (!string.IsNullOrEmpty(searchItem.TVDb))
            {
                // check if external id is cached
                var externalId = PluginSettings.TVDbIds.FirstOrDefault(t => t.ExternalId == searchItem.TVDb);
                if (externalId == null)
                {

                    // use the find method to lookup by external source id
                    FileLog.Debug("Searching themoviedb.org for all objects with TVDb ID '{0}'", searchItem.TVDb);

                    var findResults = TMDbAPI.TMDbFind(searchItem.TVDb, TMDbAPI.ExternalSource.tvdb_id);
                    if (findResults == null || findResults.Shows == null || findResults.Shows.Count == 0)
                    {
                        FileLog.Warning("Not enough information to search for trailers from themoviedb.org, no matches found using TVDb ID");
                        return listItems;
                    }

                    // there should only be one
                    searchTerm = findResults.Shows.First().Id.ToString();

                    // cache id so we can use it again
                    PluginSettings.TVDbIds.Add(new PluginSettings.ExternalID { ExternalId = searchItem.TVDb, TmdbId = findResults.Shows.First().Id });
                }
                else
                {
                    FileLog.Debug("Found cached TMDb ID '{0}' for TVDb External ID: '{1}'", externalId.TmdbId.ToString(), searchItem.TVDb);
                    searchTerm = externalId.TmdbId.ToString();
                }
            }
            else if (!string.IsNullOrEmpty(searchItem.IMDb))
            {
                // check if external id is cached
                var externalId = PluginSettings.IMDbIds.FirstOrDefault(t => t.ExternalId == searchItem.IMDb);
                if (externalId == null)
                {
                    FileLog.Debug("Searching themoviedb.org for all objects with IMDb ID '{0}'", searchItem.IMDb);

                    var findResults = TMDbAPI.TMDbFind(searchItem.IMDb, TMDbAPI.ExternalSource.imdb_id);
                    if (findResults == null || findResults.Shows == null || findResults.Shows.Count == 0)
                    {
                        FileLog.Warning("Not enough information to search for trailers from themoviedb.org, no matches found using IMDb ID");
                        return listItems;
                    }

                    // there should only be one
                    searchTerm = findResults.Shows.First().Id.ToString();

                    // cache id so we can use it again
                    PluginSettings.IMDbIds.Add(new PluginSettings.ExternalID { ExternalId = searchItem.IMDb, TmdbId = findResults.Shows.First().Id });
                }
                else
                {
                    FileLog.Debug("Found cached TMDb ID '{0}' for IMDb External ID: '{1}'", externalId.TmdbId.ToString(), searchItem.IMDb);
                    searchTerm = externalId.TmdbId.ToString();
                }
            }
            else if (!string.IsNullOrEmpty(searchItem.TVRage))
            {
                // check if external id is cached
                var externalId = PluginSettings.TVRageIds.FirstOrDefault(t => t.ExternalId == searchItem.TVRage);
                if (externalId == null)
                {
                    FileLog.Debug("Searching themoviedb.org for all objects with TVRage ID '{0}'", searchItem.TVRage);

                    var findResults = TMDbAPI.TMDbFind(searchItem.TVRage, TMDbAPI.ExternalSource.tvrage_id);
                    if (findResults == null || findResults.Shows == null || findResults.Shows.Count == 0)
                    {
                        FileLog.Warning("Not enough information to search for trailers from themoviedb.org, no matches found using TVRage ID");
                        return listItems;
                    }

                    // there should only be one
                    searchTerm = findResults.Shows.First().Id.ToString();

                    // cache id so we can use it again
                    PluginSettings.TVRageIds.Add(new PluginSettings.ExternalID { ExternalId = searchItem.TVRage, TmdbId = findResults.Shows.First().Id });
                }
                else
                {
                    FileLog.Debug("Found cached TMDb ID '{0}' for TVRage External ID: '{1}'", externalId.TmdbId.ToString(), searchItem.TVRage);
                    searchTerm = externalId.TmdbId.ToString();
                }
            }
            else if (!string.IsNullOrEmpty(searchItem.Title))
            {
                // we do the best we can with out any proper show id's
                FileLog.Debug("Searching themoviedb.org for show: Title: '{0}', FirstAired: '{1}'", searchItem.Title, searchItem.AirDate ?? "<empty>");

                var searchResults = TMDbAPI.SearchShows(searchItem.Title, language: "en", firstAirDate: string.IsNullOrEmpty(searchItem.AirDate) ? null : searchItem.AirDate);
                if (searchResults == null || searchResults.TotalResults == 0)
                {
                    FileLog.Warning("No shows found, skipping search from the themoviedb.org.");
                    return listItems;
                }
                else
                {
                    foreach (var show in searchResults.Results)
                    {
                        FileLog.Debug("Found show: Name: '{0}', Original Name: '{1}', Air Date: '{2}', TMDb: '{3}', Popularity: '{4}'", show.Name, show.OriginalName, show.FirstAirDate, show.Id, show.Popularity);
                    }
                }

                // get the show id of the first result, this would be the most likely match (based on popularity)
                // we can think about providing a menu of choices as well based on demand
                searchTerm = searchResults.Results.First().Id.ToString();
                searchItem.TMDb = searchTerm;
            }
            else
            {
                FileLog.Warning("Not enough information to search for trailers from themoviedb.org, require IMDb, TVDb, TMDb or TVRage ID or Title+Year.");
                return listItems;
            }

            FileLog.Debug("Searching for tv {0} trailers using search term '{1}' from themoviedb.org...", searchItem.MediaType.ToString().ToLower(), searchTerm );
            TMDb.DataStructures.TMDbTrailers trailers = null;

            // search for correct type
            switch (searchItem.MediaType)
            {
                case MediaItemType.Show:
                    trailers = GetTvShowTrailersFromCache(searchTerm);
                    break;
                case MediaItemType.Season:
                    trailers = GetTvSeasonTrailersFromCache(searchTerm, searchItem.Season);
                    break;
                case MediaItemType.Episode:
                    trailers = GetTvEpisodeTrailersFromCache(searchTerm, searchItem.Season, searchItem.Episode);
                    break;
            }

            if (trailers == null || trailers.Results == null)
            {
                FileLog.Error("Error getting trailers from themoviedb.org.");
                return listItems;
            }

            foreach (var trailer in trailers.Results)
            {
                var listItem = new GUITrailerListItem();

                string itemName = string.IsNullOrEmpty(trailer.Type) || trailer.Name.ToLowerInvariant().Contains(trailer.Type.ToLowerInvariant()) ? trailer.Name : string.Format("{0} - {1}", trailer.Name, trailer.Type);
                itemName = string.IsNullOrEmpty(trailer.Size) || itemName.ToLowerInvariant().Contains(trailer.Size.ToLowerInvariant()) ? itemName : string.Format("{0} ({1})", itemName, trailer.Size);
                if (PluginSettings.PreferredLanguage != "en")
                {
                    itemName = string.Format("{0} [{1}]", itemName, trailer.LanguageCode);
                }

                listItem.Label = itemName;
                listItem.Label2 = Localisation.Translation.Online;
                listItem.URL = WebUtils.GetYouTubeURL(trailer.Key);
                listItem.TVTag = trailer;
                listItem.IsOnlineItem = true;
                listItem.CurrentMedia = searchItem;

                listItems.Add(listItem);
            }

            FileLog.Info("Found {0} tv {1} trailer(s) from themoviedb.org", trailers.Results.Count.ToString(), searchItem.MediaType.ToString().ToLower());

            return listItems;
        }