Ejemplo n.º 1
0
        private TraktRateSeries CreateSeriesRateData(DBSeries series)
        {
            if (series == null || series[DBOnlineSeries.cTraktIgnore]) return null;

            string rating = series[DBOnlineSeries.cMyRating];

            TraktRateSeries seriesData = new TraktRateSeries()
            {
                Rating = rating,
                SeriesID = series[DBOnlineSeries.cID],
                Year = series.Year,
                Title = series[DBOnlineSeries.cOriginalName],
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password,
            };

            TraktLogger.Info("Rating '{0}' as '{1}/10'", series.ToString(), rating.ToString());
            return seriesData;
        }
Ejemplo n.º 2
0
        public static void UpdateEpisodeCounts(DBSeries series)
        {
            if (series == null)
            {
                return;
            }

            int seriesEpsTotal     = 0;
            int seriesEpsUnWatched = 0;
            int epsTotal           = 0;
            int epsUnWatched       = 0;

            // Update for each season in series and add each to total series count
            SQLCondition condition = new SQLCondition();

            if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
            {
                //don't include hidden seasons unless the ShowHiddenItems option is set
                condition.Add(new DBSeason(), DBSeason.cHidden, 0, SQLConditionType.Equal);
            }

            List <DBSeason> Seasons = DBSeason.Get(series[DBSeries.cID], condition);

            foreach (DBSeason season in Seasons)
            {
                epsTotal     = 0;
                epsUnWatched = 0;

                DBEpisode.GetSeasonEpisodeCounts(series, season, out epsTotal, out epsUnWatched);
                season[DBSeason.cEpisodeCount]      = epsTotal;
                season[DBSeason.cEpisodesUnWatched] = epsUnWatched;
                season[DBSeason.cUnwatchedItems]    = epsUnWatched > 0;
                season.Commit();

                seriesEpsTotal += epsTotal;
                // Count the Special (Season 0 (zero)) episodes as watched!
                if ((season[DBSeason.cIndex] != 0) || (season[DBSeason.cIndex] == 0 && !DBOption.GetOptions(DBOption.cCountSpecialEpisodesAsWatched)))
                {
                    seriesEpsUnWatched += epsUnWatched;
                }

                MPTVSeriesLog.Write(string.Format("Series \"{0} Season {1}\" has {2}/{3} unwatched episodes", series.ToString(), season[DBSeason.cIndex], epsUnWatched, epsTotal), MPTVSeriesLog.LogLevel.Debug);
            }

            MPTVSeriesLog.Write(string.Format("Series \"{0}\" has {1}/{2} unwatched episodes", series.ToString(), seriesEpsUnWatched, seriesEpsTotal), MPTVSeriesLog.LogLevel.Debug);

            series[DBOnlineSeries.cEpisodeCount]      = seriesEpsTotal;
            series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched;
            series[DBOnlineSeries.cUnwatchedItems]    = seriesEpsUnWatched > 0;
            series.Commit();
        }
Ejemplo n.º 3
0
        public List <string> deleteSeason(TVSeriesPlugin.DeleteMenuItems type)
        {
            List <string> resultMsg = new List <string>();

            // Always delete from Local episode table if deleting from disk or database
            SQLCondition condition = new SQLCondition();

            condition.Add(new DBEpisode(), DBEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
            condition.Add(new DBEpisode(), DBEpisode.cSeasonIndex, this[DBSeason.cIndex], SQLConditionType.Equal);

            /* TODO will include hidden episodes as hidden attribute is only in onlineepisodes. maybe we should include it in localepisodes also..
             * if hidden episodes are excluded then the if (resultMsg.Count is wrong and should do another select to get proper count
             * if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
             * {
             *  //don't include hidden seasons unless the ShowHiddenItems option is set
             *  condition.Add(new DBEpisode(), idden, 0, SQLConditionType.Equal);
             * }
             */

            List <DBEpisode> episodes = DBEpisode.Get(condition, false);

            if (episodes != null)
            {
                bool hasLocalEpisodesToDelete = episodes.Exists(e => !string.IsNullOrEmpty(e[DBEpisode.cFilename]));
                hasLocalEpisodesToDelete &= (type == TVSeriesPlugin.DeleteMenuItems.disk || type == TVSeriesPlugin.DeleteMenuItems.diskdatabase);

                DBSeries series     = Helper.getCorrespondingSeries(this[DBSeason.cSeriesID]);
                string   seriesName = series == null ? this[DBSeason.cSeriesID].ToString() : series.ToString();

                // show progress dialog as this can be a long process esp for network drives
                // will show new progress for each season if deleting from the series level
                GUIDialogProgress progressDialog = null;
                if (!Settings.isConfig)
                {
                    progressDialog = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
                    progressDialog.Reset();
                    progressDialog.DisplayProgressBar = true;
                    progressDialog.ShowWaitCursor     = false;
                    progressDialog.DisableCancel(true);
                    progressDialog.SetHeading(Translation.Delete);
                    progressDialog.Percentage = 0;
                    progressDialog.SetLine(1, string.Format("{0} {1} {2}", seriesName, Translation.Season, this[DBSeason.cIndex]));
                    progressDialog.SetLine(2, string.Empty);

                    // only show progress dialog if we have local files in season
                    if (hasLocalEpisodesToDelete)
                    {
                        progressDialog.StartModal(GUIWindowManager.ActiveWindow);
                    }
                }

                int counter = 0;

                foreach (DBEpisode episode in episodes)
                {
                    string episodeName = string.Format("{0}x{1} - {2}", episode[DBOnlineEpisode.cSeasonIndex], episode[DBOnlineEpisode.cEpisodeIndex], episode[DBOnlineEpisode.cEpisodeName]);
                    if (!Settings.isConfig)
                    {
                        progressDialog.SetLine(2, episodeName);
                    }
                    if (!Settings.isConfig)
                    {
                        GUIWindowManager.Process();
                    }

                    resultMsg.AddRange(episode.deleteEpisode(type, true));

                    if (!Settings.isConfig)
                    {
                        progressDialog.Percentage = Convert.ToInt32(((double)++counter / (double)episodes.Count) * 100.0);
                    }
                    if (!Settings.isConfig)
                    {
                        GUIWindowManager.Process();
                    }
                }

                // close progress dialog
                if (!Settings.isConfig)
                {
                    progressDialog.Close();
                }

                // if we have removed all episodes in season without error, cleanup the online table
                if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk)
                {
                    condition = new SQLCondition();
                    condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeasonIndex, this[DBSeason.cIndex], SQLConditionType.Equal);
                    DBOnlineEpisode.Clear(condition);
                }
            }

            #region Facade Remote Color
            // if we were successful at deleting all episodes of season from disk, set HasLocalFiles to false
            // note: we only do this if the database entries still exist
            if (resultMsg.Count == 0 && type == TVSeriesPlugin.DeleteMenuItems.disk)
            {
                this[cHasLocalFiles] = false;
                this.Commit();
            }

            // if we were successful at deleting all episodes of season from disk,
            // also check if any local episodes exist on disk for series and set HasLocalFiles to false
            if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.database)
            {
                // Check Series for Local Files
                SQLCondition episodeConditions = new SQLCondition();
                episodeConditions.Add(new DBEpisode(), DBEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                List <DBEpisode> localEpisodes = DBEpisode.Get(episodeConditions);
                if (localEpisodes.Count == 0 && !DBSeries.IsSeriesRemoved)
                {
                    DBSeries series = DBSeries.Get(this[DBSeason.cSeriesID]);
                    if (series != null)
                    {
                        series[DBOnlineSeries.cHasLocalFiles] = false;
                        series.Commit();
                    }
                }
            }
            #endregion

            #region Cleanup

            // if there are no error messages and if we need to delete from db
            if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk)
            {
                condition = new SQLCondition();
                condition.Add(new DBSeason(), DBSeason.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                condition.Add(new DBSeason(), DBSeason.cIndex, this[DBSeason.cIndex], SQLConditionType.Equal);
                DBSeason.Clear(condition);
            }

            DBSeries.IsSeriesRemoved = false;
            if (type != TVSeriesPlugin.DeleteMenuItems.disk)
            {
                // If local/online episode count is zero then delete the series and all seasons
                condition = new SQLCondition();
                condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                episodes = DBEpisode.Get(condition, false);
                if (episodes.Count == 0)
                {
                    // Delete Seasons
                    condition = new SQLCondition();
                    condition.Add(new DBSeason(), DBSeason.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBSeason.Clear(condition);

                    // Delete Local Series
                    condition = new SQLCondition();
                    condition.Add(new DBSeries(), DBSeries.cID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBSeries.Clear(condition);

                    // Delete Online Series
                    condition = new SQLCondition();
                    condition.Add(new DBOnlineSeries(), DBOnlineSeries.cID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBOnlineSeries.Clear(condition);

                    DBSeries.IsSeriesRemoved = true;
                }
            }
            #endregion

            return(resultMsg);
        }
Ejemplo n.º 4
0
        private void ShowViewTagsMenu(bool add, DBSeries series)
        {
            IDialogbox dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return;

            dlg.Reset();
            string sDialogHeading = (add ? Translation.AddViewTag : Translation.RemoveViewTag);
            dlg.SetHeading(sDialogHeading);

            GUIListItem pItem = null;
            DBView[] views = DBView.getTaggedViews();

            string currTags = series[DBOnlineSeries.cViewTags];
            String[] splitTags = currTags.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            // Add Menu items
            if (add)
            {
                // List available tag views
                foreach (DBView view in views)
                {
                    string viewname = view[DBView.cTransToken];
                    // We dont want to add it to the list if its already a member
                    if (!currTags.Contains("|" + viewname + "|"))
                    {
                        pItem = new GUIListItem(viewname);
                        dlg.Add(pItem);
                        pItem.ItemId = view[DBView.cIndex];
                    }
                }

                pItem = new GUIListItem(Translation.NewViewTag + " ...");
                dlg.Add(pItem);
                pItem.ItemId = (int)eContextItems.viewAddToNewView;
            }
            else
            {
                // we list all the tags that current series is a member of
                int iItemIdx = 1000;
                foreach (String tag in splitTags)
                {
                    pItem = new GUIListItem(tag);
                    dlg.Add(pItem);
                    pItem.ItemId = iItemIdx++;
                }
            }

            // Show Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0 || dlg.SelectedId == (int)DeleteMenuItems.cancel)
                return;

            #region Add a New Tagged View
            string selectedItem = string.Empty;
            if (dlg.SelectedId == (int)eContextItems.viewAddToNewView)
            {
                GetStringFromUserDescriptor Keyboard = new GetStringFromUserDescriptor();
                Keyboard.Text = string.Empty;
                Keyboard.ShiftEnabled = true;
                bool viewExists = true;

                while (viewExists)
                {
                    if (this.GetStringFromUser(Keyboard, out selectedItem) == ReturnCode.OK)
                    {
                        // Create View if it doesnt exist
                        viewExists = false;
                        foreach (DBView view in views)
                        {
                            if (selectedItem.Equals(view[DBView.cTransToken], StringComparison.CurrentCultureIgnoreCase))
                            {
                                ShowViewExistsMessage(selectedItem);
                                viewExists = true;
                                break;
                            }
                        }
                    }
                    else
                        return;
                }
                if (selectedItem.Length == 0)
                    return;

                // Add New View to database
                // Ensure index is unique...assumes index is updated when deleting views
                int index = logicalView.getAll(true).Count;
                string config = DBView.GetTaggedViewConfigString(selectedItem);

                MPTVSeriesLog.Write(string.Format("Creating New Tagged View: {0}", selectedItem));
                DBView.AddView(index, selectedItem, selectedItem, config, true);
            }
            #endregion

            string newTags = string.Empty;

            // Get Selected Item if not a new Tag
            if (dlg.SelectedId != (int)eContextItems.viewAddToNewView)
                selectedItem = dlg.SelectedLabelText;

            // Add / Remove Tag from series
            if (add)
            {
                MPTVSeriesLog.Write(string.Format("Adding new Tag \"{0}\" to series: {1}", selectedItem, series.ToString()));
                newTags = Helper.GetSeriesViewTags(series, true, selectedItem);
            }
            else
            {
                MPTVSeriesLog.Write(string.Format("Removing Tag \"{0}\" from series: {1}", selectedItem, series.ToString()));
                newTags = Helper.GetSeriesViewTags(series, false, selectedItem);
            }

            // Update Main View List
            m_allViews = logicalView.getAll(false);

            // Commit changes to database
            series[DBOnlineSeries.cViewTags] = newTags;
            series.Commit();

            // Special case to handle online favourites
            // We need to add/remove from online database
            if (selectedItem == DBView.cTranslateTokenOnlineFavourite)
            {
                string account = DBOption.GetOptions(DBOption.cOnlineUserID);
                if (String.IsNullOrEmpty(account))
                {
                    GUIDialogOK dlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                    dlgOK.SetHeading(Translation.OnlineFavourites);
                    dlgOK.SetLine(1, Translation.TVDB_INFO_ACCOUNTID_1);
                    dlgOK.SetLine(2, Translation.TVDB_INFO_ACCOUNTID_2);
                    dlgOK.DoModal(GUIWindowManager.ActiveWindow);
                    MPTVSeriesLog.Write("Cannot submit online favourite, make sure you have your Account identifier set!");
                }
                else
                {
                    Online_Parsing_Classes.OnlineAPI.ConfigureFavourites(add, account, series[DBOnlineSeries.cID]);
                }
            }

            // Load Facade to reflect changes
            // We only need to reload when removing from a View that is active
            if (!add)
            {
                if (m_CurrLView.Name.Equals(selectedItem, StringComparison.CurrentCultureIgnoreCase) ||
                    m_CurrLView.gettypeOfStep(0) == logicalViewStep.type.group)
                    LoadFacade();
            }
        }
Ejemplo n.º 5
0
        private void UpdateEpisodes(DBSeries series, DBSeason season, DBEpisode episode)
        {
            List<DBValue> epIDsUpdates = new List<DBValue>();
            List<DBValue> seriesIDsUpdates = new List<DBValue>();

            SQLCondition conditions = null;
            string searchPattern = string.Empty;

            // Get selected Series and/or list of Episode(s) to update
            switch (this.listLevel)
            {
                case Listlevel.Series:
                    seriesIDsUpdates.Add(series[DBSeries.cID]);
                    conditions = new SQLCondition(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, series[DBSeries.cID], SQLConditionType.Equal);
                    epIDsUpdates.AddRange(DBEpisode.GetSingleField(DBOnlineEpisode.cID, conditions, new DBOnlineEpisode()));
                    searchPattern = "*.jpg";
                    break;

                case Listlevel.Season:
                    conditions = new SQLCondition(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, season[DBSeason.cSeriesID], SQLConditionType.Equal);
                    conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeasonIndex, season[DBSeason.cIndex], SQLConditionType.Equal);
                    epIDsUpdates.AddRange(DBEpisode.GetSingleField(DBOnlineEpisode.cID, conditions, new DBOnlineEpisode()));
                    searchPattern = season[DBSeason.cIndex] + "x*.jpg";
                    break;

                case Listlevel.Episode:
                    epIDsUpdates.Add(episode[DBOnlineEpisode.cID]);
                    conditions = new SQLCondition(new DBOnlineEpisode(), DBOnlineEpisode.cID, episode[DBOnlineEpisode.cID], SQLConditionType.Equal);
                    searchPattern = episode[DBOnlineEpisode.cSeasonIndex] + "x" + episode[DBOnlineEpisode.cEpisodeIndex] + ".jpg";
                    break;
            }

            // Delete Physical Thumbnails
            // Dont prompt if just doing a single episode update
            bool deleteThumbs = true;
            if (this.listLevel != Listlevel.Episode)
            {
                GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                if (dlgYesNo != null)
                {
                    dlgYesNo.Reset();
                    dlgYesNo.SetHeading(Translation.DeleteThumbnailsHeading);
                    dlgYesNo.SetLine(1, Translation.DeleteThumbnailsLine1);
                    dlgYesNo.SetLine(2, Translation.DeleteThumbnailsLine2);
                    dlgYesNo.SetDefaultToYes(false);
                    dlgYesNo.DoModal(GUIWindowManager.ActiveWindow);
                    if (!dlgYesNo.IsConfirmed) deleteThumbs = false;
                }
            }

            if (deleteThumbs)
            {
                string thumbnailPath = Helper.PathCombine(Settings.GetPath(Settings.Path.banners), Helper.cleanLocalPath(series.ToString()) + @"\Episodes");

                // Search and delete matching files that actually exist
                string[] fileList = Directory.GetFiles(thumbnailPath, searchPattern);

                foreach (string file in fileList)
                {
                    MPTVSeriesLog.Write("Deleting Episode Thumbnail: " + file);
                    FileInfo fileInfo = new FileInfo(file);
                    try
                    {
                        fileInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        MPTVSeriesLog.Write("Failed to Delete Episode Thumbnail: " + file + ": " + ex.Message);
                    }
                }

                // Remove local thumbnail reference from db so that it thumbnails will be downloaded
                DBEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cEpisodeThumbnailFilename, (DBValue)"", conditions);
            }

            // Execute Online Parsing Actions
            if (epIDsUpdates.Count > 0)
            {

                lock (m_parserUpdaterQueue)
                {
                    List<ParsingAction> parsingActions = new List<ParsingAction>();
                    // Conditional parsing actions
                    if (this.listLevel == Listlevel.Series) parsingActions.Add(ParsingAction.UpdateSeries);
                    parsingActions.Add(ParsingAction.UpdateEpisodes);
                    if (deleteThumbs) parsingActions.Add(ParsingAction.UpdateEpisodeThumbNails);
                    parsingActions.Add(ParsingAction.UpdateEpisodeCounts);

                    m_parserUpdaterQueue.Add(new CParsingParameters(parsingActions, seriesIDsUpdates, epIDsUpdates));
                }

            }
        }
Ejemplo n.º 6
0
        protected override void OnPageLoad()
        {
            MPTVSeriesLog.Write("OnPageLoad() started.", MPTVSeriesLog.LogLevel.Debug);
            if (m_Facade == null)
            {
                // Most likely the skin does not exist
                GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                dlg.Reset();
                dlg.SetHeading(Translation.wrongSkin);
                dlg.DoModal(GetID);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            GUIPropertyManager.SetProperty("#currentmodule", pluginName);

            ImageAllocator.SetFontName(m_Facade.AlbumListLayout == null ? m_Facade.ListLayout.FontName : m_Facade.AlbumListLayout.FontName);

            #region Clear GUI Properties
            // Clear GUI Properties when first entering the plugin
            // This will avoid ugly property names being seen before
            // its corresponding value is assigned
            if (!m_bPluginLoaded)
            {
                clearGUIProperty(guiProperty.Subtitle);
                clearGUIProperty(guiProperty.Title);
                clearGUIProperty(guiProperty.Description);

                clearGUIProperty(guiProperty.CurrentView);
                clearGUIProperty(guiProperty.SimpleCurrentView);
                clearGUIProperty(guiProperty.NextView);
                clearGUIProperty(guiProperty.LastView);
                clearGUIProperty(guiProperty.SeriesCount);
                clearGUIProperty(guiProperty.GroupCount);
                clearGUIProperty(guiProperty.FilteredEpisodeCount);
                clearGUIProperty(guiProperty.WatchedCount);
                clearGUIProperty(guiProperty.UnWatchedCount);

                clearFieldsForskin("Series");
                clearFieldsForskin("Season");
                clearFieldsForskin("Episode");
            }
            #endregion

            localLogos.appendEpImage = m_Episode_Image == null ? true : false;

            #region View Setup and Loading Parameters
            bool viewSwitched = false;
            m_LoadingParameter = GetLoadingParameter();

            if (m_LoadingParameter.Type != LoadingParameterType.None && m_LoadingParameter.Type != LoadingParameterType.View)
            {
                m_JumpToViewLevel = true;

                if (m_allViews == null || m_allViews.Count == 0) m_allViews = logicalView.getAll(false);
                if (m_CurrLView == null) switchView((string)DBOption.GetOptions("lastView"));

                int viewLevels = m_CurrLView.m_steps.Count;

                m_SelectedSeries = Helper.getCorrespondingSeries(Convert.ToInt32(m_LoadingParameter.SeriesId));
                if (m_SelectedSeries == null)
                {
                    MPTVSeriesLog.Write("Failed to get series object from loading parameter!", MPTVSeriesLog.LogLevel.Debug);
                    m_LoadingParameter.Type = LoadingParameterType.None;
                }
                else
                {
                    MPTVSeriesLog.Write(string.Format("Loading into series: {0}", m_SelectedSeries.ToString(), MPTVSeriesLog.LogLevel.Debug));
                    m_stepSelection = new string[] { m_LoadingParameter.SeriesId };
                    m_stepSelections.Add(m_stepSelection);
                    pushFieldsToSkin(m_SelectedSeries, "Series");
                }

                switch (m_LoadingParameter.Type)
                {
                    #region Series
                    case LoadingParameterType.Series:
                        // load into Season view if multiple seasons exists
                        // will auto drill down to current available season if only one exists
                        if (viewLevels > 1) m_CurrViewStep = viewLevels - 2;
                        else m_CurrViewStep = 0;
                        this.listLevel = Listlevel.Season;
                        break;
                    #endregion

                    #region Season
                    case LoadingParameterType.Season:
                        m_SelectedSeason = Helper.getCorrespondingSeason(Convert.ToInt32(m_LoadingParameter.SeriesId), Convert.ToInt32(m_LoadingParameter.SeasonIdx));
                        if (m_SelectedSeason == null)
                        {
                            m_LoadingParameter.Type = LoadingParameterType.None;
                            break;
                        }
                        // load into episode view for series/season
                        if (viewLevels > 1) m_CurrViewStep = viewLevels - 1;
                        else m_CurrViewStep = 0;
                        this.listLevel = Listlevel.Episode;
                        m_stepSelection = new string[] { m_LoadingParameter.SeriesId, m_LoadingParameter.SeasonIdx };
                        m_stepSelections.Add(m_stepSelection);
                        break;
                    #endregion

                    #region Episode
                    case LoadingParameterType.Episode:
                        m_SelectedEpisode = DBEpisode.Get(Convert.ToInt32(m_LoadingParameter.SeriesId), Convert.ToInt32(m_LoadingParameter.SeasonIdx), Convert.ToInt32(m_LoadingParameter.EpisodeIdx));
                        if (m_SelectedEpisode == null)
                        {
                            m_LoadingParameter.Type = LoadingParameterType.None;
                            break;
                        }
                        // load into episode view for series/season
                        if (viewLevels > 1) m_CurrViewStep = viewLevels - 1;
                        else m_CurrViewStep = 0;
                        this.listLevel = Listlevel.Episode;
                        m_stepSelection = new string[] { m_LoadingParameter.SeriesId, m_LoadingParameter.SeasonIdx };
                        m_stepSelections.Add(m_stepSelection);
                        break;
                    #endregion
                }

                setViewLabels();
            }

            // Initialize View, also check if current view is locked after exiting and re-entering plugin
            if (m_LoadingParameter.Type == LoadingParameterType.None || m_LoadingParameter.Type == LoadingParameterType.View)
            {
                m_JumpToViewLevel = false;

                if (m_CurrLView == null || (m_CurrLView.ParentalControl && logicalView.IsLocked) || !string.IsNullOrEmpty(m_LoadingParameter.ViewName))
                {
                    // Get available Views
                    m_allViews = logicalView.getAll(false);
                    if (m_allViews.Count > 0)
                    {
                        try
                        {
                            if (m_LoadingParameter.Type == LoadingParameterType.View)
                            {
                                viewSwitched = switchView(m_LoadingParameter.ViewName);
                            }
                            else
                            {
                                viewSwitched = switchView((string)DBOption.GetOptions("lastView"));
                            }
                        }
                        catch
                        {
                            viewSwitched = false;
                            MPTVSeriesLog.Write("Error when switching view");
                        }
                    }
                    else
                    {
                        viewSwitched = false;
                        MPTVSeriesLog.Write("Error, cannot display items because no Views have been found!");
                    }
                }
                else
                {
                    viewSwitched = true;
                    setViewLabels();
                }

                // If unable to load view, exit
                if (!viewSwitched)
                {
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }
            }
            #endregion

            backdrop.GUIImageOne = FanartBackground;
            backdrop.GUIImageTwo = FanartBackground2;
            backdrop.LoadingImage = loadingImage;

            DBEpisode previouslySelectedEpisode = m_SelectedEpisode;

            LoadFacade();
            m_Facade.Focus = true;

            // Update Button Labels with translations
            if (viewMenuButton != null)
                viewMenuButton.Label = Translation.ButtonSwitchView;

            if (filterButton != null)
                filterButton.Label = Translation.Filters;

            if (ImportButton != null)
                ImportButton.Label = Translation.ButtonRunImport;

            if (LayoutMenuButton != null)
                LayoutMenuButton.Label = Translation.ButtonChangeLayout;

            if (OptionsMenuButton != null)
                OptionsMenuButton.Label = Translation.ButtonOptions;

            setProcessAnimationStatus(m_parserUpdaterWorking);

            if (m_Logos_Image != null)
            {
                logosHeight = m_Logos_Image.Height;
                logosWidth = m_Logos_Image.Width;
            }

            m_bPluginLoaded = true;

            Helper.disableNativeAutoplay();

            // Ask to Rate Episode, onPageLoad is triggered after returning from player
            if (ask2Rate != null)
            {
                showRatingsDialog(ask2Rate, true);
                ask2Rate = null;
                // Refresh the facade if we want to see the submitted rating
                if (this.listLevel == Listlevel.Episode)
                {
                    LoadFacade();
                }
            }

            // Play after subtitle download
            if (m_PlaySelectedEpisodeAfterSubtitles && previouslySelectedEpisode != null && previouslySelectedEpisode == m_SelectedEpisode)
            {
                CommonPlayEpisodeAction();
                m_PlaySelectedEpisodeAfterSubtitles = false;
            }

            // Push last update time to skin
            setGUIProperty(guiProperty.LastOnlineUpdate, DBOption.GetOptions(DBOption.cImport_OnlineUpdateScanLastTime));

            MPTVSeriesLog.Write("OnPageLoad() completed.", MPTVSeriesLog.LogLevel.Debug);
        }
Ejemplo n.º 7
0
        private void ChangeEpisodeMatchingOrder(DBSeries series, string order)
        {
            MPTVSeriesLog.Write("Changing Episode Match Order for {0}, to {1}", series.ToString(), order);

            // get list of local episodes to re-match
            SQLCondition conditions = new SQLCondition();
            conditions.Add(new DBEpisode(), DBEpisode.cSeriesID, series[DBSeries.cID], SQLConditionType.Equal);
            List<DBEpisode> localEpisodes = DBEpisode.Get(conditions);
            OnlineParsing.matchOnlineToLocalEpisodes(series, localEpisodes, new GetEpisodes(series[DBSeries.cID]), order);
            return;
        }
Ejemplo n.º 8
0
        public static void UpdateEpisodeCounts(DBSeries series)
        {
            if (series == null) return;

            int seriesEpsTotal = 0;
            int seriesEpsUnWatched = 0;
            int epsTotal = 0;
            int epsUnWatched = 0;

            // Update for each season in series and add each to total series count
            SQLCondition condition = new SQLCondition();
            if (!DBOption.GetOptions(DBOption.cShowHiddenItems)) {
                //don't include hidden seasons unless the ShowHiddenItems option is set
                condition.Add(new DBSeason(), DBSeason.cHidden, 0, SQLConditionType.Equal);
            }
            
            List<DBSeason> Seasons = DBSeason.Get(series[DBSeries.cID], condition);         
            foreach (DBSeason season in Seasons)
            {
                epsTotal = 0;
                epsUnWatched = 0;
             
                DBEpisode.GetSeasonEpisodeCounts(series, season, out epsTotal, out epsUnWatched);
                season[DBSeason.cEpisodeCount] = epsTotal;
                season[DBSeason.cEpisodesUnWatched] = epsUnWatched;
                season[DBSeason.cUnwatchedItems] = epsUnWatched > 0;
                season.Commit();

                seriesEpsTotal += epsTotal;
                // Count the Special (Season 0 (zero)) episodes as watched!
                if ((season[DBSeason.cIndex] != 0) || (season[DBSeason.cIndex] == 0 && !DBOption.GetOptions(DBOption.cCountSpecialEpisodesAsWatched)))
                {
                    seriesEpsUnWatched += epsUnWatched;
                }

                MPTVSeriesLog.Write(string.Format("Series \"{0} Season {1}\" has {2}/{3} unwatched episodes", series.ToString(), season[DBSeason.cIndex], epsUnWatched, epsTotal), MPTVSeriesLog.LogLevel.Debug);
            }

            MPTVSeriesLog.Write(string.Format("Series \"{0}\" has {1}/{2} unwatched episodes", series.ToString(), seriesEpsUnWatched, seriesEpsTotal), MPTVSeriesLog.LogLevel.Debug);
         
            series[DBOnlineSeries.cEpisodeCount] = seriesEpsTotal;
            series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched;
            series[DBOnlineSeries.cUnwatchedItems] = seriesEpsUnWatched > 0;
            series.Commit();
        }
Ejemplo n.º 9
0
        protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (control == null) return; // may enter tvs from another window via click

            if (control == this.viewMenuButton)
            {
                showViewSwitchDialog();                
                GUIControl.UnfocusControl(GetID, viewMenuButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
                return;
            }

            if (control == this.filterButton)
            {
                ShowFiltersMenu();
                GUIControl.UnfocusControl(GetID, filterButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
            }

            if (control == this.LayoutMenuButton)
            {
                ShowLayoutMenu();
                GUIControl.UnfocusControl(GetID, LayoutMenuButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
                return;
            }

            if (control == this.OptionsMenuButton)
            {
                ShowOptionsMenu();
                GUIControl.UnfocusControl(GetID, OptionsMenuButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
                return;
            }

            if (control == this.ImportButton)
            {
                lock (m_parserUpdaterQueue)
                {
                    m_parserUpdaterQueue.Add(new CParsingParameters(true, true));
                }
                
                // Start Import if delayed
                ChangeImportTimer(1000, 1000);

                GUIControl.UnfocusControl(GetID, ImportButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
                return;
            }

            if (control == this.LoadPlaylistButton)
            {
                OnShowSavedPlaylists(DBOption.GetOptions(DBOption.cPlaylistPath));
                GUIControl.UnfocusControl(GetID, LoadPlaylistButton.GetID);
                GUIControl.FocusControl(GetID, m_Facade.GetID);
                return;
            }

            if (actionType != Action.ActionType.ACTION_SELECT_ITEM) return; // some other events raised onClicked too for some reason?
            if (control == this.m_Facade)
            {
                if (this.m_Facade.SelectedListItem == null || this.m_Facade.SelectedListItem.TVTag == null)
                    return;
                
                #region Parental Control Check for Tagged Views
                if (CurrentViewLevel == Listlevel.Group && logicalView.IsLocked)
                {
                    string viewName = this.m_Facade.SelectedListItem.Label;
                    DBView[] views = DBView.getTaggedViews();
                    foreach (DBView view in views)
                    {
                        if (view[DBView.cTransToken] == viewName || view[DBView.cPrettyName] == viewName)
                        {
                            // check if we are entering a protected view
                            if (view[DBView.cParentalControl])
                            {
                                GUIPinCode pinCodeDlg = (GUIPinCode)GUIWindowManager.GetWindow(GUIPinCode.ID);
                                pinCodeDlg.Reset();

                                pinCodeDlg.MasterCode = DBOption.GetOptions(DBOption.cParentalControlPinCode);
                                pinCodeDlg.EnteredPinCode = string.Empty;
                                pinCodeDlg.SetHeading(Translation.PinCode);
                                pinCodeDlg.SetLine(1, string.Format(Translation.PinCodeDlgLabel1, viewName));
                                pinCodeDlg.SetLine(2, Translation.PinCodeDlgLabel2);
                                pinCodeDlg.Message = Translation.PinCodeMessageIncorrect;
                                pinCodeDlg.DoModal(GUIWindowManager.ActiveWindow);
                                if (!pinCodeDlg.IsCorrect)
                                {
                                    MPTVSeriesLog.Write("PinCode entered was incorrect, showing Views Menu");
                                    return;
                                }
                                else
                                    logicalView.IsLocked = false;
                            }
                        }
                    }
                }
                #endregion

                m_back_up_select_this = null;
                switch (CurrentViewLevel)
                {
                    case Listlevel.Group:
                        this.m_CurrViewStep++;
                        setNewListLevelOfCurrView(m_CurrViewStep);
                        m_stepSelection = new string[] { this.m_Facade.SelectedListItem.Label };
                        m_stepSelections.Add(m_stepSelection);
                        m_stepSelectionPretty.Add(this.m_Facade.SelectedListItem.Label);
                        MPTVSeriesLog.Write("Group Clicked: ", this.m_Facade.SelectedListItem.Label, MPTVSeriesLog.LogLevel.Debug);
                        LoadFacade();
                        this.m_Facade.Focus = true;
                        break;

                    case Listlevel.Series:
                        m_SelectedSeries = this.m_Facade.SelectedListItem.TVTag as DBSeries;
                        if (m_SelectedSeries == null) return;

                        this.m_CurrViewStep++;
                        setNewListLevelOfCurrView(m_CurrViewStep);
                        m_stepSelection = new string[] { m_SelectedSeries[DBSeries.cID].ToString() };
                        m_stepSelections.Add(m_stepSelection);
                        m_stepSelectionPretty.Add(m_SelectedSeries.ToString());
                        MPTVSeriesLog.Write("Series Clicked: ", m_stepSelection[0], MPTVSeriesLog.LogLevel.Debug);
                        this.LoadFacade();
                        this.m_Facade.Focus = true;
                        break;

                    case Listlevel.Season:
                        m_SelectedSeason = this.m_Facade.SelectedListItem.TVTag as DBSeason;
                        if (m_SelectedSeason == null) return;

                        this.m_CurrViewStep++;
                        setNewListLevelOfCurrView(m_CurrViewStep);
                        m_stepSelection = new string[] { m_SelectedSeason[DBSeason.cSeriesID].ToString(), m_SelectedSeason[DBSeason.cIndex].ToString() };
                        m_stepSelections.Add(m_stepSelection);
                        m_stepSelectionPretty.Add(m_SelectedSeason[DBSeason.cIndex] == 0 ? Translation.specials : Translation.Season + " " + m_SelectedSeason[DBSeason.cIndex]);
                        MPTVSeriesLog.Write("Season Clicked: ", m_stepSelection[0] + " - " + m_stepSelection[1], MPTVSeriesLog.LogLevel.Debug);
                        this.LoadFacade();
                        this.m_Facade.Focus = true;
                        break;

                    case Listlevel.Episode:
                        m_SelectedEpisode = this.m_Facade.SelectedListItem.TVTag as DBEpisode;
                        if (m_SelectedEpisode == null) return;
                        MPTVSeriesLog.Write("Episode Clicked: ", m_SelectedEpisode[DBEpisode.cCompositeID].ToString(), MPTVSeriesLog.LogLevel.Debug);

                        CommonPlayEpisodeAction();
                        break;
                }
            }
            base.OnClicked(controlId, control, actionType);
        }
Ejemplo n.º 10
0
        private void doWork(string aSeriesID)
        {
            XmlNode lEnglishBanners = null;
            XmlNode lBanners        = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID));

            if (lBanners == null)
            {
                return;
            }

            DBSeries lSeries = Helper.getCorrespondingSeries(Int32.Parse(aSeriesID));

            if (lSeries == null)
            {
                return;
            }

            string lSeriesName = lSeries.ToString();
            List <WideBannerSeries> lWidebannerSeriesList = new List <WideBannerSeries>();
            List <PosterSeries>     lPosterSeriesList     = new List <PosterSeries>();
            List <PosterSeason>     lPosterSeasonList     = new List <PosterSeason>();
            SeriesBannersMap        lMap = new SeriesBannersMap();

            lMap.SeriesID = aSeriesID;

            #region Series WideBanners
            lWidebannerSeriesList = GetWideSeriesBanners(lBanners, aSeriesID, lSeriesName);

            // if the banner count is zero, try to get from english language
            if (lWidebannerSeriesList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en")
            {
                lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en");
                if (lEnglishBanners == null)
                {
                    return;
                }

                lWidebannerSeriesList = GetWideSeriesBanners(lEnglishBanners, aSeriesID, lSeriesName);
            }

            // sort by highest rated
            lWidebannerSeriesList.Sort();

            // remove banners of no interest
            if (!DBOption.GetOptions(DBOption.cGetTextBanners))
            {
                lWidebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.text);
            }
            if (!DBOption.GetOptions(DBOption.cGetBlankBanners))
            {
                lWidebannerSeriesList.RemoveAll(b => b.Style == ArtworkStyles.blank);
            }

            // Respect User Limits, exception: if higher rated image or localised image is uploaded online
            int limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesWideBanners);
            if (limit < lWidebannerSeriesList.Count)
            {
                lWidebannerSeriesList.RemoveRange(limit, lWidebannerSeriesList.Count - limit);
            }

            lMap.SeriesWideBanners = lWidebannerSeriesList;
            #endregion

            #region Series Posters
            lPosterSeriesList = GetPosterSeries(lBanners, aSeriesID, lSeriesName);

            // if the poster count is zero, try to get from english language
            if (lPosterSeriesList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en")
            {
                if (lEnglishBanners == null)
                {
                    lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en");
                    if (lEnglishBanners == null)
                    {
                        return;
                    }
                }

                lPosterSeriesList = GetPosterSeries(lEnglishBanners, aSeriesID, lSeriesName);
            }

            lPosterSeriesList.Sort();

            limit = DBOption.GetOptions(DBOption.cArtworkLimitSeriesPosters);
            if (limit < lPosterSeriesList.Count)
            {
                lPosterSeriesList.RemoveRange(limit, lPosterSeriesList.Count - limit);
            }

            lMap.SeriesPosters = lPosterSeriesList;
            #endregion

            #region Season Posters
            List <string> lSeasons = new List <string>();
            lPosterSeasonList = GetPosterSeason(lBanners, aSeriesID, lSeriesName, ref lSeasons);

            // if the poster count is zero try to get from english language
            if (lPosterSeasonList.Count == 0 && OnlineAPI.GetSeriesLanguage(int.Parse(aSeriesID)) != "en")
            {
                if (lEnglishBanners == null)
                {
                    lEnglishBanners = OnlineAPI.GetBannerList(Int32.Parse(aSeriesID), "en");
                    if (lEnglishBanners == null)
                    {
                        return;
                    }
                }

                lPosterSeasonList = GetPosterSeason(lEnglishBanners, aSeriesID, lSeriesName, ref lSeasons);
            }

            lPosterSeasonList.Sort();

            // we dont support season widebanners
            lPosterSeasonList.RemoveAll(p => p.Style == ArtworkStyles.seasonwide);

            limit = DBOption.GetOptions(DBOption.cArtworkLimitSeasonPosters);
            List <PosterSeason> posterSeasonListTemp = new List <PosterSeason>(lPosterSeasonList);

            foreach (string season in lSeasons)
            {
                int count = 0;
                foreach (PosterSeason pSeason in posterSeasonListTemp)
                {
                    if (season == pSeason.SeasonIndex)
                    {
                        count++;
                        if (limit < count)
                        {
                            lPosterSeasonList.Remove(pSeason);
                        }
                    }
                }
            }

            lMap.SeasonPosters = lPosterSeasonList;
            #endregion

            // series already in?
            if (SeriesBannersMap.Contains(lMap))
            {
                SeriesBannersMap seriesMap = SeriesBannersMap[SeriesBannersMap.IndexOf(lMap)];
                seriesMap.SeasonPosters.AddRange(lMap.SeasonPosters);
                seriesMap.SeriesWideBanners.AddRange(lMap.SeriesWideBanners);
                seriesMap.SeriesPosters.AddRange(lMap.SeriesPosters);
            }
            else
            {
                SeriesBannersMap.Add(lMap);
            }
        }
Ejemplo n.º 11
0
        private TraktRateSeries CreateSeriesRateData(DBSeries series)
        {
            if (series == null || series[DBOnlineSeries.cTraktIgnore]) return null;

            TraktRateValue loveorhate = series[DBOnlineSeries.cMyRating] >= 7.0 ? TraktRateValue.love : TraktRateValue.hate;

            TraktRateSeries seriesData = new TraktRateSeries()
            {
                Rating = loveorhate.ToString(),
                SeriesID = series[DBOnlineSeries.cID],
                Year = series.Year,
                Title = series[DBOnlineSeries.cOriginalName],
                UserName = TraktSettings.Username,
                Password = TraktSettings.Password,
            };

            TraktLogger.Info("Rating '{0}' as '{1}'", series.ToString(), loveorhate.ToString());
            return seriesData;
        }
Ejemplo n.º 12
0
        public static void SynchronizeLibrary(List <DBEpisode> episodes, TraktSyncModes mode)
        {
            if (episodes.Count == 0)
            {
                return;
            }

            // get unique series ids
            var uniqueSeriesIDs = (from seriesIDs in episodes
                                   select seriesIDs[DBEpisode.cSeriesID].ToString()).Distinct().ToList();

            // go over each series, can only send one series at a time
            foreach (string seriesID in uniqueSeriesIDs)
            {
                DBSeries series = Helper.getCorrespondingSeries(int.Parse(seriesID));
                if (series == null || series[DBOnlineSeries.cTraktIgnore])
                {
                    continue;
                }

                MPTVSeriesLog.Write("Trakt: Synchronizing '{0}' episodes for series '{1}'.", mode.ToString(), series.ToString());

                TraktSync traktSync = GetTraktSyncObject(series, episodes);

                // upload to trakt
                TraktResponse response = TraktAPI.SyncEpisodeLibrary(traktSync, mode);
                if (response == null)
                {
                    MPTVSeriesLog.Write("Trakt Error: Response from server was unexpected.");
                    continue;
                }

                // check for any error and log result
                CheckTraktErrorAndNotify(response, false);

                if (response.Status == "success")
                {
                    SQLCondition conditions = new SQLCondition();

                    // flag episodes and commit to database
                    switch (mode)
                    {
                    case TraktSyncModes.seen:
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, seriesID, SQLConditionType.Equal);
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cWatched, 1, SQLConditionType.Equal);
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cHidden, 0, SQLConditionType.Equal);
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 0, SQLConditionType.Equal);

                        // we always flag traktLibrary field as the 'traktSeen' field counts as part of library
                        DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktLibrary, 1, conditions);
                        DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 1, conditions);
                        break;

                    case TraktSyncModes.library:
                        // we can't do a global set as our conditions are from two different tables
                        // where filename is not empty and traktLibrary = 0
                        foreach (DBEpisode ep in episodes.Where(e => e[DBEpisode.cSeriesID] == seriesID))
                        {
                            ep[DBOnlineEpisode.cTraktLibrary] = 1;
                            ep.Commit();
                        }
                        break;

                    case TraktSyncModes.unseen:
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, seriesID, SQLConditionType.Equal);
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cHidden, 0, SQLConditionType.Equal);
                        conditions.Add(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 2, SQLConditionType.Equal);
                        DBOnlineEpisode.GlobalSet(new DBOnlineEpisode(), DBOnlineEpisode.cTraktSeen, 0, conditions);
                        break;

                    case TraktSyncModes.unlibrary:
                        break;
                    }
                }

                // wait a short period before uploading another series
                Thread.Sleep(2000);
            }
        }