public static DBSeries getCorrespondingSeries(int id) { try { DBSeries cached = cache.getSeries(id); if (cached != null) { return(cached); } SQLCondition cond = new SQLCondition(); cond.Add(new DBSeries(), DBSeries.cID, id, SQLConditionType.Equal); List <DBSeries> tmpSeries = DBSeries.Get(cond); foreach (DBSeries series in tmpSeries) // should only be one! { if (series[DBSeries.cID] == id) { cache.addChangeSeries(series); return(series); } } return(null); } catch (Exception) { return(null); } }
public List <DBSeries> getSeriesItems(int stepIndex, string[] currentStepSelection) { MPTVSeriesLog.Write("View: Get Series Items", 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 Series Items: Executing SQL", MPTVSeriesLog.LogLevel.Debug); return(DBSeries.Get(conditions)); }
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); }
static DBSeries() { // make sure the table is created on first run (and columns are added before we call SET) DBSeries dummy = new DBSeries(); s_nLastLocalID = DBOption.GetOptions(DBOption.cDBSeriesLastLocalID); s_FieldToDisplayNameMap.Add(cParsedName, "Parsed Name"); int nCurrentDBVersion = cDBVersion; int nUpgradeDBVersion = DBOption.GetOptions(DBOption.cDBSeriesVersion); while (nUpgradeDBVersion != nCurrentDBVersion) { SQLCondition condEmpty = new SQLCondition(); List <DBSeries> AllSeries = Get(condEmpty); // take care of the upgrade in the table switch (nUpgradeDBVersion) { case 1: case 2: // upgrade to version 3; clear the series table (we use 2 other tables now) try { String sqlQuery = "DROP TABLE series"; DBTVSeries.Execute(sqlQuery); nUpgradeDBVersion++; } catch { } break; case 3: // set all new perseries timestamps to 0 DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cGetEpisodesTimeStamp, 0, new SQLCondition()); DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cUpdateBannersTimeStamp, 0, new SQLCondition()); nUpgradeDBVersion++; break; case 4: DBSeries.GlobalSet(new DBSeries(), DBSeries.cHidden, 0, new SQLCondition()); nUpgradeDBVersion++; break; case 5: // copy all local parsed name into the online series if seriesID = 0 SQLCondition conditions = new SQLCondition(); conditions.Add(new DBOnlineSeries(), DBOnlineSeries.cID, 0, SQLConditionType.LessThan); // just getting the series should be enough List <DBSeries> seriesList = DBSeries.Get(conditions); nUpgradeDBVersion++; break; case 6: // set all watched flag timestamp to 0 (will be created) DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cWatchedFileTimeStamp, 0, new SQLCondition()); nUpgradeDBVersion++; break; case 7: // all series no tagged for auto download at first DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cTaggedToDownload, 0, new SQLCondition()); nUpgradeDBVersion++; break; case 8: // create the unwatcheditem value by parsin the episodes foreach (DBSeries series in AllSeries) { DBEpisode episode = DBEpisode.GetFirstUnwatched(series[DBSeries.cID]); if (episode != null) { series[DBOnlineSeries.cUnwatchedItems] = true; } else { series[DBOnlineSeries.cUnwatchedItems] = false; } series.Commit(); } nUpgradeDBVersion++; break; case 9: // Set number of watched/unwatched episodes foreach (DBSeries series in AllSeries) { int epsTotal = 0; int epsUnWatched = 0; DBEpisode.GetSeriesEpisodeCounts(series[DBSeries.cID], out epsTotal, out epsUnWatched); series[DBOnlineSeries.cEpisodeCount] = epsTotal; series[DBOnlineSeries.cEpisodesUnWatched] = epsUnWatched; series.Commit(); } nUpgradeDBVersion++; break; case 10: // Update Sort Name Column foreach (DBSeries series in AllSeries) { series[DBOnlineSeries.cSortName] = Helper.GetSortByName(series[DBOnlineSeries.cPrettyName]); series.Commit(); } nUpgradeDBVersion++; break; case 11: // Migrate isFavourite to new Tagged View conditions = new SQLCondition(); conditions.Add(new DBOnlineSeries(), DBOnlineSeries.cIsFavourite, "1", SQLConditionType.Equal); seriesList = DBSeries.Get(conditions); MPTVSeriesLog.Write("Migrating Favourite Series"); foreach (DBSeries series in seriesList) { // Tagged view are seperated with the pipe "|" character string tagName = "|" + DBView.cTranslateTokenFavourite + "|"; series[DBOnlineSeries.cViewTags] = Helper.GetSeriesViewTags(series, true, tagName); series.Commit(); } // Migrate isOnlineFavourite to new TaggedView conditions = new SQLCondition(); conditions.Add(new DBOnlineSeries(), DBOnlineSeries.cIsOnlineFavourite, "1", SQLConditionType.Equal); seriesList = DBSeries.Get(conditions); MPTVSeriesLog.Write("Migrating Online Favourite Series"); foreach (DBSeries series in seriesList) { // Tagged view are seperated with the pipe "|" character string tagName = "|" + DBView.cTranslateTokenOnlineFavourite + "|"; series[DBOnlineSeries.cViewTags] = Helper.GetSeriesViewTags(series, true, tagName); series.Commit(); } nUpgradeDBVersion++; break; case 12: // we now have parsed_series names as titlecased // to avoid users having to re-identify series for new episodes, and to avoid duplicate entries, we upgrade existing series names foreach (var series in AllSeries) { string oldName = series[DBSeries.cParsedName]; string newName = oldName.ToTitleCase(); MPTVSeriesLog.Write(string.Format("Upgrading Parsed Series Name: {0} to {1}", oldName, newName)); series[DBSeries.cParsedName] = newName; series.Commit(); } nUpgradeDBVersion++; break; case 13: // original name not working in previous release DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cOriginalName, (DBValue)string.Empty, new SQLCondition()); nUpgradeDBVersion++; break; case 14: // original name not working in previous release DBOnlineSeries.GlobalSet(new DBOnlineSeries(), DBOnlineSeries.cTraktIgnore, 0, new SQLCondition()); nUpgradeDBVersion++; break; default: // new DB, nothing special to do nUpgradeDBVersion = nCurrentDBVersion; break; } } DBOption.SetOptions(DBOption.cDBSeriesVersion, nCurrentDBVersion); }