Ejemplo n.º 1
0
 public static DBSeason getCorrespondingSeason(int seriesID, int seasonIndex)
 {
     try
     {
         DBSeason cached = cache.getSeason(seriesID, seasonIndex);
         if (cached != null)
         {
             return(cached);
         }
         List <DBSeason> tmpSeasons = DBSeason.Get(seriesID);
         foreach (DBSeason season in tmpSeasons)
         {
             cache.addChangeSeason(season);
             if (season[DBSeason.cIndex] == seasonIndex)
             {
                 return(season);
             }
         }
         return(null);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public void HideSeries(bool hide)
        {
            MPTVSeriesLog.Write(string.Format("{0} series {1} from view", (hide ? "Hiding" : "UnHiding"), Helper.getCorrespondingSeries(this[DBSeries.cID])));

            // respect 'Show Local Files Only' setting
            List <DBSeason> seasons = DBSeason.Get(this[DBSeries.cID]);

            if (seasons != null)
            {
                foreach (DBSeason season in seasons)
                {
                    // Hide Seasons
                    season.HideSeason(hide);
                }
            }

            // Hide Series
            this[DBSeries.cHidden] = hide;
            // Set Scan Ignore
            if (DBOption.GetOptions(DBOption.cSetHiddenSeriesAsScanIgnore))
            {
                this[cScanIgnore] = hide;
            }
            this.Commit();
        }
Ejemplo n.º 3
0
        public List <string> deleteSeries(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 DBSeason(), DBSeason.cSeriesID, this[DBSeries.cID], SQLConditionType.Equal);

            /* TODO dunno if to include or exclude hidden items.
             * if they 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 DBSeason(), DBSeason.cHidden, 0, SQLConditionType.Equal);
             * }
             */

            List <DBSeason> seasons = DBSeason.Get(condition, false);

            if (seasons != null)
            {
                foreach (DBSeason season in seasons)
                {
                    resultMsg.AddRange(season.deleteSeason(type));
                }
            }

            #region Facade Remote Color
            // if we were successful at deleting all episodes of series 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[DBOnlineSeries.cHasLocalFiles] = false;
                this.Commit();
            }
            #endregion

            #region Cleanup
            // if there are no error messages and if we need to delete from db
            // Delete from online tables and season/series tables
            IsSeriesRemoved = false;
            if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk)
            {
                condition = new SQLCondition();
                condition.Add(new DBSeries(), DBSeries.cID, this[DBSeries.cID], SQLConditionType.Equal);
                DBSeries.Clear(condition);

                condition = new SQLCondition();
                condition.Add(new DBOnlineSeries(), DBOnlineSeries.cID, this[DBSeries.cID], SQLConditionType.Equal);
                DBOnlineSeries.Clear(condition);

                IsSeriesRemoved = true;
            }
            #endregion

            return(resultMsg);
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
        public List <DBSeason> getSeasonItems(int stepIndex, string[] currentStepSelection)
        {
            MPTVSeriesLog.Write("View: Get Seasons", MPTVSeriesLog.LogLevel.Debug);
            SQLCondition conditions = null;

            if (stepIndex >= m_steps.Count)
            {
                return(null);                            // wrong index specified!!
            }
            addHierarchyConditions(ref stepIndex, ref currentStepSelection, ref conditions);
            MPTVSeriesLog.Write("View: Get Seasons: Executing SQL", MPTVSeriesLog.LogLevel.Debug);
            return(DBSeason.Get(conditions));
        }
Ejemplo n.º 6
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.º 7
0
        public void DownloadBanners(string onlineLanguage)
        {
            int maxConsecutiveDownloadErrors;
            var consecutiveDownloadErrors = 0;

            if (!int.TryParse(DBOption.GetOptions(DBOption.cMaxConsecutiveDownloadErrors).ToString(), out maxConsecutiveDownloadErrors))
            {
                maxConsecutiveDownloadErrors = 3;
            }

            // now that we have all the paths, download all the files
            foreach (SeriesBannersMap map in SeriesBannersMap)
            {
                #region Series Wide Banners

                var seriesWideBanners       = new List <WideBannerSeries>(map.SeriesWideBanners);
                var seriesWideBannersToKeep = new List <WideBannerSeries>();

                // if localized and english banners exist then only get them
                // if none exist, then get what's left over
                if (seriesWideBanners.Exists(b => b.Language == onlineLanguage || b.Language == "en" || b.Language == string.Empty))
                {
                    seriesWideBanners.RemoveAll(b => b.Language != onlineLanguage && b.Language != "en" && b.Language != string.Empty);
                }

                foreach (var seriesWideBanner in seriesWideBanners)
                {
                    if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors)
                    {
                        MPTVSeriesLog.Write("Too many consecutive download errors. Aborting.");
                        return;
                    }

                    // mark the filename with the language
                    seriesWideBanner.FileName = Helper.cleanLocalPath(seriesWideBanner.SeriesName) + @"\-lang" + seriesWideBanner.Language + "-" + seriesWideBanner.OnlinePath;

                    string file = OnlineAPI.DownloadBanner(seriesWideBanner.OnlinePath, Settings.Path.banners, seriesWideBanner.FileName);
                    if (BannerDownloadDone != null)
                    {
                        BannerDownloadDone(file);
                        seriesWideBannersToKeep.Add(seriesWideBanner);
                        consecutiveDownloadErrors = 0;
                    }
                    else
                    {
                        consecutiveDownloadErrors++;
                    }
                }

                map.SeriesWideBanners = seriesWideBannersToKeep;

                #endregion

                #region Series Posters

                var seriesPosters       = new List <PosterSeries>(map.SeriesPosters);
                var seriesPostersToKeep = new List <PosterSeries>();

                // if localized and english banners exist then only get them
                // if none exist, then get what's left over
                if (seriesPosters.Exists(p => p.Language == onlineLanguage || p.Language == "en" || p.Language == string.Empty))
                {
                    seriesPosters.RemoveAll(p => p.Language != onlineLanguage && p.Language != "en" && p.Language != string.Empty);
                }

                foreach (var seriesPoster in seriesPosters)
                {
                    if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors)
                    {
                        MPTVSeriesLog.Write("Too many consecutive download errors. Aborting.");
                        return;
                    }

                    // mark the filename with the language
                    seriesPoster.FileName = Helper.cleanLocalPath(seriesPoster.SeriesName) + @"\-lang" + seriesPoster.Language + "-" + seriesPoster.OnlinePath;
                    string file = OnlineAPI.DownloadBanner(seriesPoster.OnlinePath, Settings.Path.banners, seriesPoster.FileName);
                    if (BannerDownloadDone != null)
                    {
                        BannerDownloadDone(file);
                        seriesPostersToKeep.Add(seriesPoster);
                        consecutiveDownloadErrors = 0;
                    }
                    else
                    {
                        consecutiveDownloadErrors++;
                    }
                }

                map.SeriesPosters = seriesPostersToKeep;

                #endregion

                #region Season Posters

                List <DBSeason> localSeasons = DBSeason.Get(new SQLCondition(new DBSeason(), DBSeason.cSeriesID, map.SeriesID, SQLConditionType.Equal), false);

                var seasonPosters       = new List <PosterSeason>(map.SeasonPosters);
                var seasonPostersToKeep = new List <PosterSeason>();

                // if localized and english banners exist then only get them
                // if none exist, then get what's left over
                if (seasonPosters.Exists(p => p.Language == onlineLanguage || p.Language == "en" || p.Language == string.Empty))
                {
                    seasonPosters.RemoveAll(p => p.Language != onlineLanguage && p.Language != "en" && p.Language != string.Empty);
                }

                foreach (var seasonPoster in seasonPosters)
                {
                    if (consecutiveDownloadErrors >= maxConsecutiveDownloadErrors)
                    {
                        MPTVSeriesLog.Write("Too many consecutive download errors. Aborting.");
                        return;
                    }

                    // only download season banners if we have online season in database
                    if (!localSeasons.Any(s => s[DBSeason.cIndex] == seasonPoster.SeasonIndex))
                    {
                        continue;
                    }

                    seasonPoster.FileName = Helper.cleanLocalPath(seasonPoster.SeriesName) + @"\-lang" + seasonPoster.Language + "-" + seasonPoster.OnlinePath;

                    string file = OnlineAPI.DownloadBanner(seasonPoster.OnlinePath, Settings.Path.banners, seasonPoster.FileName);
                    if (BannerDownloadDone != null)
                    {
                        BannerDownloadDone(file);
                        seasonPostersToKeep.Add(seasonPoster);
                        consecutiveDownloadErrors = 0;
                    }
                    else
                    {
                        consecutiveDownloadErrors++;
                    }
                }

                map.SeasonPosters = seasonPostersToKeep;

                #endregion
            }
        }