public static bool canSearchMediaDetailWithType(BasicMediaDetail basicMediaDetail, SubtitlesSearchType subtitlesSearchType)
        {
            bool useImdbMovieQuery = !(string.IsNullOrEmpty((basicMediaDetail.ImdbID)));
            bool useTitle = !(string.IsNullOrEmpty((basicMediaDetail.Title)));
            bool useMovieQuery = useTitle && !(string.IsNullOrEmpty((basicMediaDetail.YearStr)));
            bool useEpisodeQuery = useTitle &&
                                   (
                                     (basicMediaDetail.AbsoluteNumbering && string.IsNullOrEmpty(basicMediaDetail.SeasonStr) && !string.IsNullOrEmpty(basicMediaDetail.EpisodeStr)) ||
                                     (!basicMediaDetail.AbsoluteNumbering && !string.IsNullOrEmpty(basicMediaDetail.SeasonStr) && !string.IsNullOrEmpty(basicMediaDetail.EpisodeStr))
                                   );

            switch (subtitlesSearchType) {
                case SubtitlesSearchType.IMDb:
                    return useImdbMovieQuery;
                case SubtitlesSearchType.TVSHOW:
                    return useEpisodeQuery;
                case SubtitlesSearchType.MOVIE:
                    return useMovieQuery;
                default:
                    return false;
            }
        }
        public static SettingsGroup getDefaultGroupForSearchType(SubtitlesSearchType searchType)
        {
            SettingsGroup result = null;

            List<SettingsGroup> allProviderGroups = getAllProviderGroups();

            if (allProviderGroups == null || allProviderGroups.Count == 0) return result;

            foreach (SettingsGroup settingsGroup in allProviderGroups) {
                switch (searchType) {
                    case SubtitlesSearchType.IMDb:
                    case SubtitlesSearchType.MOVIE:
                        if (settingsGroup.Enabled && settingsGroup.DefaultForMovies && groupHasEnabledProviders(settingsGroup))
                            return settingsGroup;
                        break;
                    case SubtitlesSearchType.TVSHOW:
                        if (settingsGroup.Enabled && settingsGroup.DefaultForTVShows && groupHasEnabledProviders(settingsGroup))
                            return settingsGroup;
                        break;
                }
            }
            return result;
        }
Exemple #3
0
        public void DownloadSubtitle(SubtitleItem subtitleItem, BasicMediaDetail mediaDetail, FolderSelectionItem folderSelectionItem, SubtitlesSearchType searchType, bool skipDefaults)
        {
            if (IsCanceled())
                Kill();
            if (_subtitlesDownloaderThread != null && _subtitlesDownloaderThread.IsAlive)
                return;

            _isCanceled = false;
            _status = ThreadStatus.StatusEnded;

            DownloadData downloadData = new DownloadData {
                SubtitleItem = subtitleItem,
                MediaDetail = mediaDetail,
                FolderSelectionItem = folderSelectionItem,
                SearchType = searchType,
                SkipDefaults = skipDefaults,
                StatusList = new List<SubtitleDownloadStatus>()
            };

            _subtitlesDownloaderThread = new Thread(DownloadSubtitleAsync);
            _subtitlesDownloaderThread.IsBackground = true;
            _subtitlesDownloaderThread.Name = "Subtitles Downloader Thread";
            _subtitlesDownloaderThread.Start(downloadData);
        }
Exemple #4
0
 public void FillData(bool progressReportingEnabled, List<string> languageCodes, Dictionary<string, string> providerIDsNames, SubtitlesSearchType searchType)
 {
     _providerIDsAndtitles = providerIDsNames;
     _progressReportingEnabled = progressReportingEnabled;
     _languageCodes = languageCodes;
     _searchType = searchType;
 }
        protected override void OnPageLoad()
        {
            _GUIInitialized = false;
            _currentHandler = null;
            _backupHandler = null;
            _backupHandlerSet = false;
            _shouldDeleteButtonVisible = false;
            _clearedMedia = false;
            _subtitleFilesForCurrentMedia.Clear();
            _subtitlesExistForCurrentMedia = false;
            _mediaAvailable = false;
            _checkMediaForSubtitlesOnOpenDone = false;
            View = ViewMode.NONE;
            ModifySearchSearchType = SubtitlesSearchType.NONE;
            _oldModifySearchSearchType = SubtitlesSearchType.NONE;
            ListControlViewState = ListControlViewState.GROUPSANDPROVIDERS;

            _subtitlesSortMethod = Settings.SettingsManager.Properties.GUISettings.SortMethod;
            _subtitlesSortAsc = Settings.SettingsManager.Properties.GUISettings.SortAscending;

            GUIUtils.SetProperty("#currentmodule", SubCentralUtils.PluginName());

            //if (searchButton == null) {
            if (!CheckAndTranslateSkin()) {
                // if the component didn't load properly we probably have a bad skin file
                GUIUtils.ShowOKDialog(Localization.Error, Localization.CannotLoadSkin);
                GUIWindowManager.ShowPreviousWindow();
                logger.Error("Failed to load all components from skin file. Skin is outdated or invalid.");
                return;
            }
            // test SubtitleDownloader assembly
            if (!core.SubtitleDownloaderInitialized) {
                GUIUtils.ShowOKDialog(Localization.Error, string.Concat(Localization.UnableToLoadSubtitleDownloader, "\n", Localization.SubtitleDownloaderUnavailable));
                GUIWindowManager.ShowPreviousWindow();
                logger.Error("SubtitleDownloader: not available");
                return;
            }

            base.OnPageLoad();
            _GUIInitialized = true;

            GUIControl.DisableControl(GetID, deleteButton.GetID);

            if (sortButton != null)
                sortButton.SortChanged += new SortEventHandler(OnSortChanged);

            // initialize properties
            InitSearchProperties();

            // initialize list control
            _lastSelectedGroupsAndProvidersItemIndex = 0;
            _lastSelectedSubtitlesItemIndex = 1;
            FillProviderGroupsAndProviders(false);

            // get last active module
            int lastActiveWindow = GUIWindowManager.GetPreviousActiveWindow();

            // just entering from the home or basic home or plugins screen, show the main screen
            if (MainWindowIDs.Contains(lastActiveWindow)) {
                logger.Debug("Entered plugin from Home or Basic Home or Plugins screen");
                View = ViewMode.MAIN;
                CurrentHandler = null;
            }

            // entering from a plugin
            else {
                //try to load data from it and if we fail return back to the calling plugin.
                if (!LoadFromPlugin(lastActiveWindow)) {
                    logger.Error("Entered plugin from ID #{0}, but failed to load an appropriate handler.", lastActiveWindow);

                    // show a popup notifying the user
                    if (!GUIUtils.ShowCustomYesNoDialog(Localization.Warning, string.Format(Localization.UnableToImportDataFrom, CurrentHandler == null ? Localization.ExternalPlugin : CurrentHandler.PluginName), Localization.ManualSearch, Localization.Back)) {
                        GUIWindowManager.ShowPreviousWindow();
                        return;
                    }
                    //View = ViewMode.MAIN;
                    OnModifySearch();
                }

                // we loaded details successfully, we are now in file view.
                else {
                    logger.Debug("Entered plugin from {0} ({1})", CurrentHandler.PluginName, CurrentHandler.ID);
                    SubtitlesSearchType searchType = SubCentralUtils.getSubtitlesSearchTypeFromMediaDetail(CurrentHandler.MediaDetail);
                    View = ViewMode.SEARCH;

                    //if (searchType != SubtitlesSearchType.NONE)
                    {
                        EnableDisableProviderGroupsAndProviders(searchType != SubtitlesSearchType.NONE);

                        if (CurrentHandler.MediaDetail.Files != null && CurrentHandler.MediaDetail.Files.Count > 0) {
                          _shouldDeleteButtonVisible = true;
                          GUIControl.EnableControl(GetID, deleteButton.GetID);
                        }

                        if (Settings.SettingsManager.Properties.GUISettings.CheckMediaForSubtitlesOnOpen) {
                            CheckMediaForSubtitlesOnOpen(CurrentHandler);
                        }

                        if (Settings.SettingsManager.Properties.GeneralSettings.PluginLoadWithSearchData == OnPluginLoadWithSearchData.SearchDefaults) {
                            SettingsGroup defaultGroup = SubCentralUtils.getDefaultGroupForSearchType(searchType);
                            if (defaultGroup != null) {
                                _lastSelectedGroupsAndProvidersItemIndex = LocateGroupInListControl(defaultGroup);
                                PerformSearch(defaultGroup);
                            }
                        }
                    }
                }
            }
        }
        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            base.OnClicked(controlId, control, actionType);

            switch (controlId) {
                case (int)GUIControls.SEARCHBUTTON:
                    //PerformSearch();
                    break;

                case (int)GUIControls.CANCELBUTTON:
                    GUIWindowManager.ShowPreviousWindow();
                    break;

                case (int)GUIControls.LANGUAGESBUTTON:
                    OnLanguageSelection();
                    break;

                case (int)GUIControls.MODIFYSEARCHBUTTON:
                    OnModifySearch();
                    break;

                case (int)GUIControls.SORTBUTTON:
                    OnShowDialogSortOptions();
                    break;

                case (int)GUIControls.DELETEBUTTON:
                    OnDeleteSubtitles();
                    break;

                case (int)GUIControls.PROVIDERSLIST:
                    // have to check action type for facade
                    if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_SELECT_ITEM) {
                        OnListSelection();
                    }
                    break;

                case (int)GUIControls.MODIFYSEARCHOKBUTTON:
                    ModifySearchWithUserData();
                    break;

                case (int)GUIControls.MODIFYSEARCHCANCELBUTTON:
                    CancelModifySearch();
                    break;

                case (int)GUIControls.MODIFYSEARCHREVERTBUTTON:
                    RevertModifySearch(true);
                    break;

                case (int)GUIControls.MODIFYSEARCHCLEARFILESBUTTON:
                    ClearFiles();
                    break;

                case (int)GUIControls.MODIFYSEARCHMOVIEBUTTON:
                    if (_oldModifySearchSearchType == SubtitlesSearchType.NONE)
                        _oldModifySearchSearchType = ModifySearchSearchType;
                    ModifySearchSearchType = SubtitlesSearchType.MOVIE;
                    break;

                case (int)GUIControls.MODIFYSEARCHTVSHOWBUTTON:
                    if (_oldModifySearchSearchType == SubtitlesSearchType.NONE)
                        _oldModifySearchSearchType = ModifySearchSearchType;
                    ModifySearchSearchType = SubtitlesSearchType.TVSHOW;
                    break;

                case (int)GUIControls.MODIFYSEARCHIMDBIDBUTTON:
                case (int)GUIControls.MODIFYSEARCHTITLEBUTTON:
                case (int)GUIControls.MODIFYSEARCHYEARBUTTON:
                case (int)GUIControls.MODIFYSEARCHSEASONBUTTON:
                case (int)GUIControls.MODIFYSEARCHEPISODEBUTTON:
                    KeyboardModifySearch(controlId);
                    PublishSearchProperties(true);
                    break;

                case (int)GUIControls.MODIFYSEARCHABSOLUTENUMBERINGBUTTON:
                    ModifyAbsoluteNumbering();
                    break;
            }
        }
        private void RevertModifySearch(bool revertProviderList)
        {
            CurrentHandler.Clear();
            ModifySearchSearchType = SubtitlesSearchType.NONE;
            _oldModifySearchSearchType = SubtitlesSearchType.NONE;
            CurrentHandler = _backupHandler;
            _lastSelectedGroupsAndProvidersItemIndex = 0;
            if (_shouldDeleteButtonVisible)
                GUIControl.EnableControl(GetID, deleteButton.GetID);
            else
                GUIControl.DisableControl(GetID, deleteButton.GetID);

            if (CurrentHandler == null) {
                View = ViewMode.MAIN;
                return;
            }
            //else if (SubCentralUtils.getSubtitlesSearchTypeFromMediaDetail(CurrentHandler.MediaDetail) != SubtitlesSearchType.NONE) {
            if (revertProviderList) {
                if (getRealCurrentSearchSearchType(CurrentHandler.MediaDetail) != SubtitlesSearchType.NONE) {
                    FillProviderGroupsAndProviders(true);
                }
                else {
                    FillProviderGroupsAndProviders(false);
                }
            }
            View = ViewMode.SEARCH;
        }
 void retriever_OnProviderSearchErrorEvent(BasicMediaDetail mediaDetail, SubtitlesSearchType subtitlesSearchType, Exception e)
 {
     retriever.OnProviderSearchErrorEvent -= retriever_OnProviderSearchErrorEvent;
     //HideWaitCursor();
     if (e is NotImplementedException || e is NotSupportedException) {
         switch (subtitlesSearchType) {
             case SubtitlesSearchType.IMDb:
                 GUIUtils.ShowNotifyDialog(Localization.Error, Localization.SiteDoesNotSupportIMDbIDSearch, GUIUtils.NoSubtitlesLogoThumbPath);
                 break;
             case SubtitlesSearchType.MOVIE:
                 GUIUtils.ShowNotifyDialog(Localization.Error, Localization.SiteDoesNotSupportMovieSearch, GUIUtils.NoSubtitlesLogoThumbPath);
                 break;
             case SubtitlesSearchType.TVSHOW:
                 GUIUtils.ShowNotifyDialog(Localization.Error, Localization.SiteDoesNotSupportTVShowSearch, GUIUtils.NoSubtitlesLogoThumbPath);
                 break;
             default:
                 GUIUtils.ShowNotifyDialog(Localization.Error, string.Format(Localization.ErrorWhileRetrievingSubtitlesWithReason, e.Message), GUIUtils.NoSubtitlesLogoThumbPath, 10);
                 //GUIUtils.ShowNotifyDialog(Localization.Error, Localization.ErrorWhileRetrievingSubtitles, GUIUtils.NoSubtitlesLogoThumbPath);
                 break;
         }
     }
     else if (e is System.Net.WebException && ((System.Net.WebException)e).Status == System.Net.WebExceptionStatus.Timeout) {
         GUIUtils.ShowNotifyDialog(Localization.Error, Localization.TimedOutWhileRetrievingSubtitles, GUIUtils.NoSubtitlesLogoThumbPath);
     }
     else {
         GUIUtils.ShowNotifyDialog(Localization.Error, string.Format(Localization.ErrorWhileRetrievingSubtitlesWithReason, e.Message), GUIUtils.NoSubtitlesLogoThumbPath, 10);
         //GUIUtils.ShowNotifyDialog(Localization.Error, Localization.ErrorWhileRetrievingSubtitles, GUIUtils.NoSubtitlesLogoThumbPath);
     }
     _notificationDone = true;
 }
        private void OnModifySearch()
        {
            if (CurrentHandler == null && SubCentralUtils.getEnabledAndValidFoldersForMedia(null, false).Count < 1) {
                GUIUtils.ShowOKDialog(Localization.Warning, Localization.CannotUseManualSearch);
                return;
            }

            ManualSearchHandler manualSearchHandler = core.PluginHandlers[PluginHandlerType.MANUAL] as ManualSearchHandler;

            // copy data from current handler
            if (CurrentHandler != manualSearchHandler && CurrentHandler != null) {
                manualSearchHandler.MediaDetail = CopyMediaDetail(CurrentHandler.MediaDetail);
                manualSearchHandler.Modified = false;
                manualSearchHandler.UpdateTags();
                ModifySearchSearchType = SubCentralUtils.getSubtitlesSearchTypeFromMediaDetail(manualSearchHandler.MediaDetail);
                if (ModifySearchSearchType == SubtitlesSearchType.NONE)
                    ModifySearchSearchType = SubtitlesSearchType.MOVIE;
            }
            else if (CurrentHandler != manualSearchHandler) {
                manualSearchHandler.UpdateTags();
                ModifySearchSearchType = SubtitlesSearchType.MOVIE;
            }

            _oldModifySearchSearchType = ModifySearchSearchType;

            CurrentHandler = manualSearchHandler;

            View = ViewMode.MODIFYSEARCH;
        }