Beispiel #1
0
        public static void UpdateEpisodeCounts(DBSeries series, DBSeason season)
        {
            if (series == null || season == null)
            {
                return;
            }

            int epsTotal     = 0;
            int epsUnWatched = 0;

            // Updated Season count
            DBEpisode.GetSeasonEpisodeCounts(series, season, out epsTotal, out epsUnWatched);

            season[DBSeason.cEpisodeCount]      = epsTotal;
            season[DBSeason.cEpisodesUnWatched] = epsUnWatched;
            season[DBSeason.cUnwatchedItems]    = epsUnWatched > 0;
            season.Commit();

            // Now Update the series count
            epsTotal     = 0;
            epsUnWatched = 0;

            DBEpisode.GetSeriesEpisodeCounts(series[DBSeries.cID], out epsTotal, out epsUnWatched);

            series[DBOnlineSeries.cEpisodeCount]      = epsTotal;
            series[DBOnlineSeries.cEpisodesUnWatched] = epsUnWatched;
            series[DBOnlineSeries.cUnwatchedItems]    = epsUnWatched > 0;
            series.Commit();
        }
Beispiel #2
0
        public static void UpdateEpisodeCounts(DBSeries series, Dictionary <string, List <EpisodeCounter> > episodes)
        {
            if (series == null)
            {
                return;
            }

            string seriesId           = series[DBSeries.cID];
            int    seriesEpsTotal     = 0;
            int    seriesEpsUnWatched = 0;
            bool   airedOrder         = series.IsAiredOrder;

            // dont worry about filtering season list, we already have a filtered episode list
            // query without std conditions for faster response.
            var conditions = new SQLCondition(new DBSeason(), DBSeason.cSeriesID, seriesId, SQLConditionType.Equal);
            var seasons    = DBSeason.Get(conditions, false);

            // update season counts
            List <EpisodeCounter> eps = new List <EpisodeCounter>();

            if (episodes.TryGetValue(seriesId, out eps))
            {
                foreach (var season in seasons)
                {
                    var seasonEps = eps.Where(e => airedOrder ? e.SeasonAirIdx == season[DBSeason.cIndex] : e.SeasonDvdIdx == season[DBSeason.cIndex]).ToList();

                    // dont commit seasons if are not viewing them
                    // episodes for count is already filtered so can return 0 results
                    if (seasonEps.Count == 0)
                    {
                        continue;
                    }

                    int count          = seasonEps.Count();
                    int unWatchedCount = seasonEps.Where(e => e.EpisodeWatched != "1").Count();

                    season[DBSeason.cEpisodeCount]      = count;
                    season[DBSeason.cEpisodesUnWatched] = unWatchedCount;
                    season[DBSeason.cUnwatchedItems]    = unWatchedCount > 0;
                    season.Commit();

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

                // update series counts
                series[DBOnlineSeries.cEpisodeCount]      = seriesEpsTotal;
                series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched;
                series[DBOnlineSeries.cUnwatchedItems]    = seriesEpsUnWatched > 0;
                series.Commit();
            }
        }
Beispiel #3
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();
        }
Beispiel #4
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);
        }
Beispiel #5
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();
            }
        }
Beispiel #6
0
        private void ShowEpisodeSortByMenu(DBSeries series, bool ChangeMatchingOrder)
        {
            IDialogbox dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
                return;

            dlg.Reset();
            if (ChangeMatchingOrder)
                dlg.SetHeading(Translation.ChangeOnlineMatchOrder);
            else
                dlg.SetHeading(Translation.SortBy);

            #region Add Menu items
            GUIListItem pItem = null;

            string currMatchOrder = series[DBOnlineSeries.cChosenEpisodeOrder].ToString();
            if (string.IsNullOrEmpty(currMatchOrder)) currMatchOrder = EpisodeSortByMenuItems.Aired.ToString();

            string currSortOrder = series[DBOnlineSeries.cEpisodeSortOrder].ToString();
            if (string.IsNullOrEmpty(currSortOrder)) currSortOrder = EpisodeSortByMenuItems.Aired.ToString();

            string selection = ChangeMatchingOrder ? currMatchOrder : currSortOrder;

            // For now we will just add sort options for the Aired and DVD Order
            pItem = new GUIListItem(Translation.AiredOrder);
            dlg.Add(pItem);
            pItem.ItemId = (int)EpisodeSortByMenuItems.Aired;
            if (selection == EpisodeSortByMenuItems.Aired.ToString()) pItem.Selected = true;

            if (series[DBOnlineSeries.cEpisodeOrders].ToString().Contains(EpisodeSortByMenuItems.DVD.ToString()))
            {
                pItem = new GUIListItem(Translation.DVDOrder);
                dlg.Add(pItem);
                pItem.ItemId = (int)EpisodeSortByMenuItems.DVD;
                if (selection == EpisodeSortByMenuItems.DVD.ToString()) pItem.Selected = true;
            }

            // TODO: sort by absolute order and just show a single season in GUI...later
            if (series[DBOnlineSeries.cEpisodeOrders].ToString().Contains(EpisodeSortByMenuItems.Absolute.ToString()) && ChangeMatchingOrder)
            {
                pItem = new GUIListItem(Translation.AbsoluteOrder);
                dlg.Add(pItem);
                pItem.ItemId = (int)EpisodeSortByMenuItems.Absolute;
                if (selection == EpisodeSortByMenuItems.Absolute.ToString()) pItem.Selected = true;
            }

            if (ChangeMatchingOrder)
            {
                pItem = new GUIListItem(Translation.Title);
                dlg.Add(pItem);
                pItem.ItemId = (int)EpisodeSortByMenuItems.Title;
                if (selection == EpisodeSortByMenuItems.Title.ToString()) pItem.Selected = true;
            }
            #endregion

            #region Show Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0)
                return;

            // if we change matching order then we should also change
            // corresponding sort order
            switch (dlg.SelectedId)
            {
                case (int)EpisodeSortByMenuItems.Aired:
                    if (ChangeMatchingOrder)
                    {
                        series[DBOnlineSeries.cChosenEpisodeOrder] = EpisodeSortByMenuItems.Aired.ToString();
                        ChangeEpisodeMatchingOrder(series, EpisodeSortByMenuItems.Aired.ToString());
                    }
                    series[DBOnlineSeries.cEpisodeSortOrder] = EpisodeSortByMenuItems.Aired.ToString();
                    break;
                case (int)EpisodeSortByMenuItems.DVD:
                    if (ChangeMatchingOrder)
                    {
                        series[DBOnlineSeries.cChosenEpisodeOrder] = EpisodeSortByMenuItems.DVD.ToString();
                        ChangeEpisodeMatchingOrder(series, EpisodeSortByMenuItems.DVD.ToString());
                    }
                    series[DBOnlineSeries.cEpisodeSortOrder] = EpisodeSortByMenuItems.DVD.ToString();
                    break;
                case (int)EpisodeSortByMenuItems.Absolute:
                    if (ChangeMatchingOrder)
                    {
                        series[DBOnlineSeries.cChosenEpisodeOrder] = EpisodeSortByMenuItems.Absolute.ToString();
                        ChangeEpisodeMatchingOrder(series, EpisodeSortByMenuItems.Absolute.ToString());
                    }
                    break;
                case (int)EpisodeSortByMenuItems.Title:
                    series[DBOnlineSeries.cChosenEpisodeOrder] = EpisodeSortByMenuItems.Title.ToString();
                    ChangeEpisodeMatchingOrder(series, EpisodeSortByMenuItems.Title.ToString());
                    break;
            }
            #endregion

            // commit selection
            series.Commit();

            // re-calculate episode counts for each season as they can differ
            // with different sort orders
            if (!ChangeMatchingOrder)
            {
                DBSeries.UpdateEpisodeCounts(series);
            }

            // Re-load the facade to re-sort episodes
            LoadFacade();
        }
Beispiel #7
0
        private void CycleSeriesPoster(DBSeries series, bool next)
        {
            if (series.PosterList.Count <= 1) return;

            int nCurrent = series.PosterList.IndexOf(series.Poster);

            if (next)
            {
                nCurrent++;
                if (nCurrent >= series.PosterList.Count)
                    nCurrent = 0;
            }
            else
            {
                nCurrent--;
                if (nCurrent < 0)
                    nCurrent = series.PosterList.Count - 1;
            }

            series.Poster = series.PosterList[nCurrent];
            series.Commit();

            // No need to re-load the facade for non-graphical layouts
            if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.List)
                seriesposter.Filename = ImageAllocator.GetSeriesPosterAsFilename(series);
            else
                LoadFacade();
        }
Beispiel #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();
        }
Beispiel #9
0
        public static void UpdateEpisodeCounts(DBSeries series, Dictionary<string, List<EpisodeCounter>> episodes)
        {
            if (series == null) return;

            string seriesId = series[DBSeries.cID];
            int seriesEpsTotal = 0;
            int seriesEpsUnWatched = 0;
            bool airedOrder = series.IsAiredOrder;

            // dont worry about filtering season list, we already have a filtered episode list
            // query without std conditions for faster response.
            var conditions = new SQLCondition(new DBSeason(), DBSeason.cSeriesID, seriesId, SQLConditionType.Equal); 
            var seasons = DBSeason.Get(conditions, false);

            // update season counts
            List<EpisodeCounter> eps = new List<EpisodeCounter>();
            if (episodes.TryGetValue(seriesId, out eps))
            {
                foreach(var season in seasons)
                {
                    var seasonEps = eps.Where(e => airedOrder ? e.SeasonAirIdx == season[DBSeason.cIndex] : e.SeasonDvdIdx == season[DBSeason.cIndex]).ToList();
                    
                    // dont commit seasons if are not viewing them
                    // episodes for count is already filtered so can return 0 results
                    if (seasonEps.Count == 0) continue;

                    int count = seasonEps.Count();
                    int unWatchedCount = seasonEps.Where(e => e.EpisodeWatched != "1").Count();

                    season[DBSeason.cEpisodeCount] = count;
                    season[DBSeason.cEpisodesUnWatched] = unWatchedCount;
                    season[DBSeason.cUnwatchedItems] = unWatchedCount > 0;
                    season.Commit();

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

                // update series counts
                series[DBOnlineSeries.cEpisodeCount] = seriesEpsTotal;
                series[DBOnlineSeries.cEpisodesUnWatched] = seriesEpsUnWatched;
                series[DBOnlineSeries.cUnwatchedItems] = seriesEpsUnWatched > 0;
                series.Commit();
            }
        }
Beispiel #10
0
        protected void ShowChangeSeriesMetaLanguageMenu(DBSeries selectedSeries)
        {
            if (DBOption.GetOptions(DBOption.cOverrideLanguage))
            {
                int iSelected = -1;
                String selectedLang = String.Empty;
                String newLang = String.Empty;
                String selectedLanguage = selectedSeries[DBOnlineSeries.cLanguage];
                List<GUIListItem> items = new List<GUIListItem>();
                
                if (onlineLanguages.Count == 0)
                {
                    onlineLanguages.AddRange(new GetLanguages().languages);
                }

                foreach (Language lang in onlineLanguages)
                {
                    items.Add(new GUIListItem(Helper.UppercaseFirst(lang.language)));
                    if (lang.abbreviation == selectedLanguage)
                    {
                        selectedLang = lang.language;

                        iSelected = items.FindIndex(item => item.Label.Equals(lang.language));
                        items[iSelected].Label = lang.language + " (Selected)";
                    }
                }

                ShowMenuDialog(Translation.ChangeSeriesLanguage, items, iSelected, out newLang);

                if (!newLang.Equals(selectedLang))
                {
                    Language newSelectedLanguage = onlineLanguages.Find(lang => lang.language.Equals(newLang));
                    if (newSelectedLanguage != null)
                    {
                        selectedSeries[DBOnlineSeries.cLanguage] = newSelectedLanguage.abbreviation;
                        selectedSeries.Commit();
                    }
                }
            }
        }