Exemple #1
0
 public DBSeries(String SeriesName)
     : base(cTableName)
 {
     InitColumns();
     if (!ReadPrimary(SeriesName))
     {
         InitValues();
     }
     if (this[cID] == 0)
     {
         m_onlineSeries = new DBOnlineSeries(s_nLastLocalID);
         s_nLastLocalID--;
         DBOption.SetOptions(DBOption.cDBSeriesLastLocalID, s_nLastLocalID);
         this[cID] = m_onlineSeries[DBOnlineSeries.cID];
         if (String.IsNullOrEmpty(m_onlineSeries[DBOnlineSeries.cPrettyName]))
         {
             m_onlineSeries[DBOnlineSeries.cPrettyName] = this[cParsedName];
             m_onlineSeries[DBOnlineSeries.cSortName]   = this[cParsedName];
             m_onlineSeries.Commit();
         }
     }
     else
     {
         m_onlineSeries = new DBOnlineSeries(this[cID]);
     }
 }
Exemple #2
0
        public GetSeries(String sSeriesName)
        {
            XmlNode node = Online_Parsing_Classes.OnlineAPI.GetSeries(sSeriesName);

            nameToMatch = sSeriesName;
            if (node != null)
            {
                foreach (XmlNode itemNode in node.ChildNodes)
                {
                    DBOnlineSeries series = new DBOnlineSeries();

                    foreach (XmlNode propertyNode in itemNode.ChildNodes)
                    {
                        if (propertyNode.Name == "seriesid") // work around SeriesID inconsistancy
                        {
                            series[DBOnlineSeries.cID] = propertyNode.InnerText;
                        }
                        else if (DBOnlineSeries.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                            series[DBOnlineSeries.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                        else
                        {
                            // we don't know that field, add it to the series table
                            series.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                            series[propertyNode.Name] = propertyNode.InnerText;
                        }
                    }
                    listSeries.Add(series);
                }

                PerfectMatch = RankSearchResults(nameToMatch, listSeries, out listSeries);
            }
        }
Exemple #3
0
        public GetSeries(String sSeriesName)
        {
            XmlNode node = Online_Parsing_Classes.OnlineAPI.GetSeries(sSeriesName);

            nameToMatch = sSeriesName;
            if (node != null)
            {
                foreach (XmlNode itemNode in node.ChildNodes)
                {
                    DBOnlineSeries series = new DBOnlineSeries();

                    foreach (XmlNode propertyNode in itemNode.ChildNodes)
                    {
                        if (propertyNode.Name == "seriesid") // work around SeriesID inconsistancy
                        {
                            series[DBOnlineSeries.cID] = propertyNode.InnerText;
                        }
                        else if (DBOnlineSeries.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                        {
                            series[DBOnlineSeries.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                        }
                        else
                        {
                            // we don't know that field, add it to the series table
                            series.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                            series[propertyNode.Name] = propertyNode.InnerText;
                        }
                    }
                    listSeries.Add(series);
                }

                PerfectMatch = RankSearchResults(nameToMatch, listSeries, out listSeries);
            }
        }
Exemple #4
0
        public static string stdGetSQL(SQLCondition conditions, bool selectFull, bool includeStdCond)
        {
            string field;

            if (selectFull)
            {
                SQLWhat what = new SQLWhat(new DBOnlineSeries());
                what.AddWhat(new DBSeries());
                field = what;
            }
            else
            {
                field = DBOnlineSeries.Q(DBOnlineSeries.cID) + " from " + DBOnlineSeries.cTableName;
            }

            if (includeStdCond)
            {
                conditions.AddCustom(stdConditions.ConditionsSQLString);
            }

            string conds   = conditions;
            string orderBy = string.Empty;

            if (selectFull)
            {
                bool bUseSortName = DBOption.GetOptions(DBOption.cUseSortName);
                orderBy = conditions.customOrderStringIsSet
                      ? conditions.orderString
                      : " order by " + (bUseSortName?"upper(" + DBOnlineSeries.Q(DBOnlineSeries.cSortName) + "),":"") + "upper(" + DBOnlineSeries.Q(DBOnlineSeries.cPrettyName) + ")";
            }
            return("select " + field + " left join " + cTableName + " on " + DBSeries.Q(cID) + "==" + DBOnlineSeries.Q(cID)
                   + conds
                   + orderBy
                   + conditions.limitString);
        }
Exemple #5
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);
        }
Exemple #6
0
 public DBSeries(bool bCreateEmptyOnline)
     : base(cTableName)
 {
     InitColumns();
     InitValues();
     if (bCreateEmptyOnline)
     {
         m_onlineSeries = new DBOnlineSeries();
     }
 }
Exemple #7
0
        static List <string> getDynamicFileName(string dynfilename, Level level)
        {
            int           dnyStart = 0;
            List <string> result   = new List <string>();

            if (!dynfilename.Contains("<"))
            {
                // not dynamic
                result.Add(Helper.getCleanAbsolutePath(dynfilename));
                return(result);
            }
            #pragma warning disable 0642
            else if ((dnyStart = dynfilename.IndexOf("<Episode.")) > -1)
            {
                ;
            }
            else if ((dnyStart = dynfilename.IndexOf("<Series.")) > -1)
            {
                ;
            }
            else if ((dnyStart = dynfilename.IndexOf("<Season.")) > -1)
            {
                ;
            }
            #pragma warning restore 0642
            else
            {
                // no '<' but none of the recognized? that is a wrong entry
                return(result);
            }
            //MPTVSeriesLog.Write("dynamic Filename detected..trying to resolve");
            string fieldToGet = string.Empty;
            string value      = string.Empty;
            fieldToGet = dynfilename.Substring(dnyStart, dynfilename.IndexOf('>', dnyStart) - dnyStart + 1);
            if (getFieldValues(fieldToGet, out value, level))
            {
                // for genres/actors we need to split dynamic filenames again
                string[] vals = DBOnlineSeries.splitField(value);

                for (int i = 0; i < vals.Length; i++)
                {
                    // recursive so we support multiple dyn fields in filename
                    if (vals[i] != fieldToGet)
                    {
                        result.AddRange(getDynamicFileName(dynfilename.Replace(fieldToGet, vals[i].Trim()), level));
                    }
                }
                return(result);
            }
            else
            {
                return(new List <string>(new string[] { string.Empty })); // something went wrong
            }
        }
Exemple #8
0
        public GetSeries(String aSeriesName)
        {
            string lUserLanguage = DBOption.GetOptions(DBOption.cOnlineLanguage);

            if (DBOption.GetOptions(DBOption.cOverrideSearchLanguageToEnglish))
            {
                lUserLanguage = "en";
            }

            // search for series basis the user's language
            XmlNode lNode = Online_Parsing_Classes.OnlineAPI.GetSeries(aSeriesName, lUserLanguage);

            if (lNode == null)
            {
                return;
            }

            // if we have no results from the user's language try English
            if (lNode.ChildNodes.Count == 0 && lUserLanguage != "en")
            {
                lNode = Online_Parsing_Classes.OnlineAPI.GetSeries(aSeriesName, "en");
                if (lNode == null)
                {
                    return;
                }
            }

            foreach (XmlNode itemNode in lNode.ChildNodes)
            {
                var lSeries = new DBOnlineSeries();

                foreach (XmlNode propertyNode in itemNode.ChildNodes)
                {
                    if (propertyNode.Name == "seriesid")   // work around SeriesID inconsistancy
                    {
                        lSeries[DBOnlineSeries.cID] = propertyNode.InnerText;
                    }
                    else if (DBOnlineSeries.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                    {
                        lSeries[DBOnlineSeries.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                    }
                    else
                    {
                        // we don't know that field, add it to the series table
                        lSeries.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                        lSeries[propertyNode.Name] = propertyNode.InnerText;
                    }
                }
                mListSeries.Add(lSeries);
            }

            PerfectMatch = RankSearchResults(aSeriesName, mListSeries, out mListSeries);
        }
Exemple #9
0
        // returns a list of all series with information stored in the database.
        public static List <DBOnlineSeries> getAllSeries()
        {
            List <DBValue>        seriesIDs = DBOnlineSeries.GetSingleField(DBOnlineSeries.cID, new SQLCondition(), new DBOnlineSeries());
            List <DBOnlineSeries> rtn       = new List <DBOnlineSeries>();

            foreach (DBValue currSeriesID in seriesIDs)
            {
                rtn.Add(new DBOnlineSeries(currSeriesID));
            }

            return(rtn);
        }
Exemple #10
0
        public static void UpdateUnWatched(DBEpisode episode)
        {
            DBOnlineSeries series = new DBOnlineSeries(episode[DBEpisode.cSeriesID]);
            DBEpisode      FirstUnwatchedEpisode = DBEpisode.GetFirstUnwatched(series[DBSeries.cID]);

            if (FirstUnwatchedEpisode != null)
            {
                series[DBOnlineSeries.cUnwatchedItems] = true;
            }
            else
            {
                series[DBOnlineSeries.cUnwatchedItems] = false;
            }
            series.Commit();
        }
Exemple #11
0
        public DBSeason(int nSeriesID, int nSeasonIndex)
            : base(cTableName)
        {
            InitColumns();
            String sSeasonID = nSeriesID + "_s" + nSeasonIndex;

            if (!ReadPrimary(sSeasonID))
            {
                InitValues();
                // set the parent series so that banners will be refreshed from scratched
                DBOnlineSeries series = new DBOnlineSeries(nSeriesID);
                series[DBOnlineSeries.cBannersDownloaded] = 0;
                series.Commit();
            }
            this[cSeriesID] = nSeriesID;
            this[cIndex]    = nSeasonIndex;
        }
Exemple #12
0
        public void ChangeSeriesID(int nSeriesID)
        {
            DBOnlineSeries newOnlineSeries = new DBOnlineSeries(nSeriesID);

            if (m_onlineSeries[DBOnlineSeries.cHasLocalFilesTemp])
            {
                newOnlineSeries[DBOnlineSeries.cHasLocalFilesTemp] = 1;
            }
            if (m_onlineSeries[DBOnlineSeries.cHasLocalFiles])
            {
                newOnlineSeries[DBOnlineSeries.cHasLocalFiles] = 1;
            }
            newOnlineSeries[DBOnlineSeries.cEpisodeOrders]      = m_onlineSeries[DBOnlineSeries.cEpisodeOrders];
            newOnlineSeries[DBOnlineSeries.cChosenEpisodeOrder] = m_onlineSeries[DBOnlineSeries.cChosenEpisodeOrder];
            m_onlineSeries = newOnlineSeries;
            this[cID]      = nSeriesID;
        }
Exemple #13
0
        static DBOnlineSeries()
        {
            ///////////////////////////////////////////////////
            #region Pretty Names displayed in Configuration Details Tab
            s_FieldToDisplayNameMap.Add(cID, "Online Series ID");
            s_FieldToDisplayNameMap.Add(cPrettyName, "Title");
            s_FieldToDisplayNameMap.Add(cStatus, "Show Status");
            s_FieldToDisplayNameMap.Add(cGenre, "Genre");
            s_FieldToDisplayNameMap.Add(cSummary, "Show Overview");
            s_FieldToDisplayNameMap.Add(cAirsDay, "Aired Day");
            s_FieldToDisplayNameMap.Add(cAirsTime, "Aired Time");
            s_FieldToDisplayNameMap.Add(cSortName, "Sort By");
            s_FieldToDisplayNameMap.Add(cLanguage, "Language (Override)");
            s_FieldToDisplayNameMap.Add(cIMDBID, "IMDb ID");
            s_FieldToDisplayNameMap.Add(cTraktID, "Trakt ID");
            s_FieldToDisplayNameMap.Add(cEpisodeOrders, "Episode Orders");
            s_FieldToDisplayNameMap.Add(cChosenEpisodeOrder, "Episode Order");
            s_FieldToDisplayNameMap.Add(cContentRating, "Content Rating");
            s_FieldToDisplayNameMap.Add(cMyRating, "My Rating");
            s_FieldToDisplayNameMap.Add(cFirstAired, "First Aired");
            s_FieldToDisplayNameMap.Add(cEpisodeCount, "Episodes");
            s_FieldToDisplayNameMap.Add(cEpisodesUnWatched, "Episodes UnWatched");
            s_FieldToDisplayNameMap.Add(cLastEpisodeAirDate, "Last Aired");
            s_FieldToDisplayNameMap.Add(cLastUpdated, "Last Updated (UTC)");
            s_FieldToDisplayNameMap.Add(cOriginalName, "English Name");
            #endregion
            ///////////////////////////////////////////////////

            //////////////////////////////////////////////////
            #region Local DB field mapping to Online DB
            s_OnlineToFieldMap.Add("id", cID);
            s_OnlineToFieldMap.Add("SeriesName", cPrettyName);
            s_OnlineToFieldMap.Add("Status", cStatus);
            s_OnlineToFieldMap.Add("Genre", cGenre);
            s_OnlineToFieldMap.Add("Overview", cSummary);
            s_OnlineToFieldMap.Add("Airs_DayOfWeek", cAirsDay);
            s_OnlineToFieldMap.Add("Airs_Time", cAirsTime);
            s_OnlineToFieldMap.Add("SortName", cSortName);
            #endregion
            //////////////////////////////////////////////////

            // make sure the table is created on first run
            DBOnlineSeries dummy = new DBOnlineSeries();
        }
Exemple #14
0
        static void getTableFieldname(string what, out DBTable table, out string fieldname)
        {
            string sTable = string.Empty;

            fieldname = string.Empty;
            table     = null;
            what      = what.Replace("<", "").Replace(">", "").Trim();
            sTable    = what.Split('.')[0];
            switch (sTable)
            {
            case "Series":
                if (new DBOnlineSeries().FieldNames.Contains(what.Split('.')[1]))
                {
                    table     = new DBOnlineSeries();
                    fieldname = what.Split('.')[1];
                }
                else
                {
                    table     = new DBSeries();
                    fieldname = what.Split('.')[1];
                }
                break;

            case "Season":
                table     = new DBSeason();
                fieldname = what.Split('.')[1];
                break;

            case "Episode":
                if (new DBOnlineEpisode().FieldNames.Contains(what.Split('.')[1]))
                {
                    table     = new DBOnlineEpisode();
                    fieldname = what.Split('.')[1];
                }
                else
                {
                    table     = new DBEpisode();
                    fieldname = what.Split('.')[1];
                }
                break;
            }
        }
Exemple #15
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);
        }
Exemple #16
0
 public UserInputResultSeriesActionPair(UserInputResults.SeriesAction RequestedAction, DBOnlineSeries series)
 {
     this.RequestedAction = RequestedAction;
     this.ChosenSeries = series;
 }
Exemple #17
0
        public static string resolveDynString(string what, DBTable item, bool splitFields, bool applyUserFormatting)
        {
            // apply userFormatting on the field's itself
            if (applyUserFormatting)
            {
                performUserFormattingReplacement(ref what);
            }

            Level        level      = levelOfItem(item);
            string       value      = what;
            List <Level> whatLevels = getLevel(what);

            _splitFields = splitFields;
            // the item needs to be the type corresponding to the level (we require the item to match the indicated level)
            if (level == Level.Episode) // we can do everything
            {
                if (whatLevels.Contains(Level.Episode))
                {
                    DBOnlineEpisode o = item as DBOnlineEpisode;
                    if (o == null)
                    {
                        value = replaceEpisodeTags(item as DBEpisode, value);
                    }
                    else
                    {
                        value = replaceEpisodeTags(o, value);
                    }
                }
                if (whatLevels.Contains(Level.Season))
                {
                    value = replaceSeasonTags(item[DBEpisode.cSeriesID], item[DBEpisode.cSeasonIndex], value);
                }
                if (whatLevels.Contains(Level.Series))
                {
                    value = replaceSeriesTags(item[DBEpisode.cSeriesID], value);
                }
            }
            else if (level == Level.Season && !whatLevels.Contains(Level.Episode)) // we can do season/series
            {
                if (whatLevels.Contains(Level.Season))
                {
                    value = replaceSeasonTags(item as DBSeason, value);
                }
                if (whatLevels.Contains(Level.Series))
                {
                    value = replaceSeriesTags(item[DBSeason.cSeriesID], value);
                }
            }
            else if (level == Level.Series && !whatLevels.Contains(Level.Episode) && !whatLevels.Contains(Level.Season)) // we can only do series
            {
                DBOnlineSeries o = item as DBOnlineSeries;
                if (o == null)
                {
                    value = replaceSeriesTags(item as DBSeries, value);
                }
                else
                {
                    value = replaceSeriesTags(item[DBSeries.cID], value);
                }
            }
            if (nonFormattingFields.Contains(what))
            {
                return(value);
            }
            value = doFormatting(value, what, item);

            value = MathParser.mathParser.TryParse(value);
            value = MathParser.mathParser.TranslateExpression(value);

            // apply userFormatting on the field's result
            if (applyUserFormatting)
            {
                bool replacementOccured = performUserFormattingReplacement(ref value);
                // because the replacement itself might be dynamic again, we resolve the result again
                if (replacementOccured)
                {
                    value = resolveDynString(value, item, splitFields, applyUserFormatting);
                }
            }
            return(System.Web.HttpUtility.HtmlDecode(value));
        }
Exemple #18
0
        public List <string> getGroupItems(int stepIndex, string[] currentStepSelection) // in nested groups, eg. Networks-Genres-.. we also need selections
        {
            SQLCondition conditions = null;

            MPTVSeriesLog.Write("View: GetGroupItems: Begin", MPTVSeriesLog.LogLevel.Debug);
            if (stepIndex >= m_steps.Count)
            {
                return(null);                            // wrong index specified!!
            }
            addHierarchyConditions(ref stepIndex, ref currentStepSelection, ref conditions);
            logicalViewStep step  = m_steps[stepIndex];
            List <string>   items = new List <string>();

            // to ensure we respect on the fly filter settings
            if (DBOption.GetOptions(DBOption.cOnlyShowLocalFiles) && (typeof(DBOnlineEpisode) != step.groupedBy.table.GetType() && typeof(DBEpisode) != step.groupedBy.table.GetType()))
            {
                // not generic
                SQLCondition fullSubCond = new SQLCondition();
                fullSubCond.AddCustom(DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), DBOnlineSeries.Q(DBOnlineSeries.cID), SQLConditionType.Equal);
                conditions.AddCustom(" exists( " + DBEpisode.stdGetSQL(fullSubCond, false) + " )");
            }
            else if (DBOption.GetOptions(DBOption.cOnlyShowLocalFiles))
            {
                // has to be grouped by something episode
                conditions.Add(new DBEpisode(), DBEpisode.cFilename, "", SQLConditionType.NotEqual);
            }

            string fieldName     = step.groupedBy.rawFieldname;
            string tableName     = step.groupedBy.table.m_tableName;
            string tableField    = step.groupedBy.tableField;
            string userEditField = tableField + DBTable.cUserEditPostFix;
            string sql           = string.Empty;

            // check if the useredit column exists
            if (DBTable.ColumnExists(tableName, fieldName + DBTable.cUserEditPostFix))
            {
                sql = "select distinct(" +
                      "case when (" + userEditField + " is null or " + userEditField + " = " + "'" + "'" + ") " +
                      "then " + tableField + " else " + userEditField + " " +
                      "end) as gnr, " +
                      "count(*) from " + tableName + conditions + " group by gnr" + step.conds.orderString;
            }
            else
            {
                sql = "select distinct " + tableField +
                      " , count(*) " +
                      " from " + tableName + conditions +
                      " group by " + tableField +
                      step.conds.orderString;
            }
            SQLite.NET.SQLiteResultSet results = DBTVSeries.Execute(sql);
            MPTVSeriesLog.Write("View: GetGroupItems: SQL complete", MPTVSeriesLog.LogLevel.Debug);
            if (results.Rows.Count > 0)
            {
                for (int index = 0; index < results.Rows.Count; index++)
                {
                    string tmpItem = results.Rows[index].fields[0];
                    // assume we now have a list of all distinct ones
                    if (step.groupedBy.attempSplit)
                    {
                        // we want to try to split by "|" eg. for actors/genres
                        string[] split = DBOnlineEpisode.splitField(tmpItem);
                        foreach (string item in split)
                        {
                            if (item.Trim().Length == 0)
                            {
                                // display "Unknown" if field is empty"
                                items.Add(Translation.Unknown);
                            }
                            else
                            {
                                items.Add(item.Trim());
                            }
                        }
                    }
                    else
                    {
                        if (tmpItem.Trim().Length == 0)
                        {
                            items.Add(Translation.Unknown);
                        }
                        else
                        {
                            items.Add(tmpItem.Trim());
                        }
                    }
                }
                if (step.groupedBy.attempSplit)
                {
                    // have to check for dups (because we split eg. Drama|Action so "Action" might be in twice
                    items = Helper.RemoveDuplicates(items);
                }
                // now we have to sort them again (Unknown/splitting above)
                items.Sort();
                if (step.groupedBy.attempSplit)
                {
                    // and limit in memory here (again because those splits are hard to deal with)
                    if (step.limitItems > 0)
                    {
                        Helper.LimitList(ref items, step.limitItems);
                    }
                }
            }
            MPTVSeriesLog.Write("View: GetGroupItems: Complete", MPTVSeriesLog.LogLevel.Debug);
            return(items);
        }
 public UserInputResultSeriesActionPair(UserInputResults.SeriesAction RequestedAction, DBOnlineSeries series)
 {
     this.RequestedAction = RequestedAction;
     this.ChosenSeries    = series;
 }
Exemple #20
0
        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);
        }
Exemple #21
0
 public DBSeries(String SeriesName)
     : base(cTableName)
 {
     InitColumns();
     if (!ReadPrimary(SeriesName))
         InitValues();
     if (this[cID] == 0)
     {
         m_onlineSeries = new DBOnlineSeries(s_nLastLocalID);
         s_nLastLocalID--;
         DBOption.SetOptions(DBOption.cDBSeriesLastLocalID, s_nLastLocalID);
         this[cID] = m_onlineSeries[DBOnlineSeries.cID];
         if (String.IsNullOrEmpty(m_onlineSeries[DBOnlineSeries.cPrettyName]))
         {
             m_onlineSeries[DBOnlineSeries.cPrettyName] = this[cParsedName];
             m_onlineSeries[DBOnlineSeries.cSortName] = this[cParsedName];
             m_onlineSeries.Commit();
         }
     }
     else
     {
         m_onlineSeries = new DBOnlineSeries(this[cID]);
     }
 }
Exemple #22
0
 public void ChangeSeriesID(int nSeriesID)
 {
     DBOnlineSeries newOnlineSeries = new DBOnlineSeries(nSeriesID);
     if (m_onlineSeries[DBOnlineSeries.cHasLocalFilesTemp])
         newOnlineSeries[DBOnlineSeries.cHasLocalFilesTemp] = 1;
     if (m_onlineSeries[DBOnlineSeries.cHasLocalFiles])
         newOnlineSeries[DBOnlineSeries.cHasLocalFiles] = 1;
     newOnlineSeries[DBOnlineSeries.cEpisodeOrders] = m_onlineSeries[DBOnlineSeries.cEpisodeOrders];
     newOnlineSeries[DBOnlineSeries.cChosenEpisodeOrder] = m_onlineSeries[DBOnlineSeries.cChosenEpisodeOrder];
     m_onlineSeries = newOnlineSeries;
     this[cID] = nSeriesID;
 }
Exemple #23
0
 public static void UpdateUnWatched(DBEpisode episode)
 {
     DBOnlineSeries series = new DBOnlineSeries(episode[DBEpisode.cSeriesID]);
     DBEpisode FirstUnwatchedEpisode = DBEpisode.GetFirstUnwatched(series[DBSeries.cID]);
     if (FirstUnwatchedEpisode != null)
         series[DBOnlineSeries.cUnwatchedItems] = true;
     else
         series[DBOnlineSeries.cUnwatchedItems] = false;
     series.Commit();
 }
Exemple #24
0
 static void getTableFieldname(string what, out DBTable table, out string fieldname)
 {
     string sTable = string.Empty;
     fieldname = string.Empty;
     table = null;
     what = what.Replace("<", "").Replace(">", "").Trim();
     sTable = what.Split('.')[0];
     switch (sTable)
     {
         case "Series":
             if(new DBOnlineSeries().FieldNames.Contains(what.Split('.')[1]))
             {
                 table = new DBOnlineSeries();
                 fieldname = what.Split('.')[1];
             }
             else
             {
                 table = new DBSeries();
                 fieldname = what.Split('.')[1];
             }
             break;
         case "Season":
             table = new DBSeason();
             fieldname = what.Split('.')[1];
             break;
         case "Episode":
             if (new DBOnlineEpisode().FieldNames.Contains(what.Split('.')[1]))
             {
                 table = new DBOnlineEpisode();
                 fieldname = what.Split('.')[1];
             }
             else
             {
                 table = new DBEpisode();
                 fieldname = what.Split('.')[1];
             }
             break;
     }
 }
Exemple #25
0
        static DBOnlineSeries()
        {
            ///////////////////////////////////////////////////
            #region Pretty Names displayed in Configuration Details Tab
            s_FieldToDisplayNameMap.Add(cID, "Online Series ID");
            s_FieldToDisplayNameMap.Add(cPrettyName, "Title");
            s_FieldToDisplayNameMap.Add(cStatus, "Show Status");
            s_FieldToDisplayNameMap.Add(cGenre, "Genre");
            s_FieldToDisplayNameMap.Add(cSummary, "Show Overview");
            s_FieldToDisplayNameMap.Add(cAirsDay, "Aired Day");
            s_FieldToDisplayNameMap.Add(cAirsTime, "Aired Time");
            s_FieldToDisplayNameMap.Add(cSortName, "Sort By");
            s_FieldToDisplayNameMap.Add(cLanguage, "Language");
            s_FieldToDisplayNameMap.Add(cIMDBID, "IMDB ID");
            s_FieldToDisplayNameMap.Add(cEpisodeOrders, "Episode Orders");
            s_FieldToDisplayNameMap.Add(cChosenEpisodeOrder, "Episode Order");
            s_FieldToDisplayNameMap.Add(cContentRating, "Content Rating");
            s_FieldToDisplayNameMap.Add(cMyRating, "My Rating");
            s_FieldToDisplayNameMap.Add(cFirstAired, "First Aired");
            s_FieldToDisplayNameMap.Add(cEpisodeCount, "Episodes");
            s_FieldToDisplayNameMap.Add(cEpisodesUnWatched, "Episodes UnWatched");
            #endregion
            ///////////////////////////////////////////////////

            //////////////////////////////////////////////////
            #region Local DB field mapping to Online DB
            s_OnlineToFieldMap.Add("id", cID);
            s_OnlineToFieldMap.Add("SeriesName", cPrettyName);
            s_OnlineToFieldMap.Add("Status", cStatus);
            s_OnlineToFieldMap.Add("Genre", cGenre);
            s_OnlineToFieldMap.Add("Overview", cSummary);
            s_OnlineToFieldMap.Add("Airs_DayOfWeek", cAirsDay);
            s_OnlineToFieldMap.Add("Airs_Time", cAirsTime);
            s_OnlineToFieldMap.Add("SortName", cSortName);
            #endregion
            //////////////////////////////////////////////////

            // make sure the table is created on first run
            DBOnlineSeries dummy = new DBOnlineSeries();
        }
Exemple #26
0
 public DBSeries(bool bCreateEmptyOnline)
     : base(cTableName)
 {
     InitColumns();
     InitValues();
     if (bCreateEmptyOnline)
         m_onlineSeries = new DBOnlineSeries();
 }
Exemple #27
0
        public void addSQLCondition(string what, string type, string condition)
        {
            if ((!what.Contains("<") || !what.Contains(".")) && !what.Contains("custom:"))
            {
                return;
            }

            SQLConditionType condtype;

            switch (type)
            {
            case "=":
                condtype = SQLConditionType.Equal;
                break;

            case ">":
                condtype = SQLConditionType.GreaterThan;
                break;

            case ">=":
                condtype = SQLConditionType.GreaterEqualThan;
                break;

            case "<":
                condtype = SQLConditionType.LessThan;
                break;

            case "<=":
                condtype = SQLConditionType.LessEqualThan;
                break;

            case "!=":
                condtype = SQLConditionType.NotEqual;
                break;

            case "like":
                condtype = SQLConditionType.Like;
                break;

            default:
                condtype = SQLConditionType.Equal;
                break;
            }

            DBTable table      = null;
            string  tableField = string.Empty;

            getTableFieldname(what, out table, out tableField);
            Type lType = table.GetType();

            SQLCondition fullSubCond = new SQLCondition();

            if (logicalViewStep.type.series == Type && (lType != typeof(DBSeries) && lType != typeof(DBOnlineSeries)))
            {
                if (lType == typeof(DBSeason))
                {
                    fullSubCond.AddCustom(DBSeason.Q(DBSeason.cSeriesID), DBOnlineSeries.Q(DBOnlineSeries.cID), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBSeason.Q(tableField), condition, condtype, true);

                    conds.AddCustom(" exists( " + DBSeason.stdGetSQL(fullSubCond, false) + " )");
                }
                else if (lType == typeof(DBOnlineEpisode))
                {
                    fullSubCond.AddCustom(DBOnlineEpisode.Q(tableField), condition, condtype, true);
                    conds.AddCustom(" online_series.id in ( " + DBEpisode.stdGetSQL(fullSubCond, false, true, DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID)) + " )");
                }
                else if (lType == typeof(DBEpisode))
                {
                    fullSubCond.AddCustom(DBEpisode.Q(tableField), condition, condtype, true);
                    conds.AddCustom(" online_series.id in ( " + DBEpisode.stdGetSQL(fullSubCond, false, true, DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID)) + " )");
                }
            }
            else if (logicalViewStep.type.season == Type && lType != typeof(DBSeason))
            {
                if (lType == typeof(DBOnlineSeries) || lType == typeof(DBSeries))
                {
                    fullSubCond.AddCustom(DBOnlineSeries.Q(DBOnlineSeries.cID), DBSeason.Q(DBSeason.cSeriesID), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBOnlineSeries.Q(tableField), condition, condtype, true);
                    conds.AddCustom(" exists( " + DBSeries.stdGetSQL(fullSubCond, false) + " )");
                }
                else if (lType == typeof(DBOnlineEpisode))
                {
                    // we rely on the join in dbseason for this (much, much faster)
                    conds.AddCustom(DBOnlineEpisode.Q(tableField), condition, condtype, true);
                }
                else if (lType == typeof(DBEpisode))
                {
                    fullSubCond.AddCustom(DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), DBSeason.Q(DBSeason.cSeriesID), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBOnlineEpisode.Q(DBOnlineEpisode.cSeasonIndex), DBSeason.Q(DBSeason.cIndex), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBEpisode.Q(tableField), condition, condtype);
                    conds.AddCustom(" exists( " + DBEpisode.stdGetSQL(fullSubCond, false) + " )");
                }
            }
            else if (logicalViewStep.type.episode == Type && (lType != typeof(DBEpisode) && lType != typeof(DBOnlineEpisode)))
            {
                if (lType == typeof(DBOnlineSeries) || lType == typeof(DBSeries))
                {
                    fullSubCond.AddCustom(DBOnlineSeries.Q(DBOnlineSeries.cID), DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBOnlineSeries.Q(tableField), condition, condtype, true);
                    conds.AddCustom(" exists( " + DBSeries.stdGetSQL(fullSubCond, false) + " )");
                }
                if (lType == typeof(DBSeason))
                {
                    fullSubCond.AddCustom(DBSeason.Q(DBSeason.cSeriesID), DBOnlineEpisode.Q(DBOnlineEpisode.cSeriesID), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBSeason.Q(DBSeason.cIndex), DBOnlineEpisode.Q(DBOnlineEpisode.cSeasonIndex), SQLConditionType.Equal);
                    fullSubCond.AddCustom(DBSeason.Q(tableField), condition, condtype, true);
                    conds.AddCustom(" exists( " + DBSeason.stdGetSQL(fullSubCond, false) + " )");
                }
            }
            else
            {
                // condition is on current table itself
                conds.Add(table, tableField, condition.Trim(), condtype);
            }
        }
Exemple #28
0
        private IEnumerable <DBOnlineSeries> Work(String sSeriesID, String languageID, bool aOverride = false)
        {
            if (sSeriesID.Length > 0)
            {
                int result;
                if (int.TryParse(sSeriesID, out result))
                {
                    MPTVSeriesLog.Write(string.Format("Retrieving updated Metadata for series {0}", Helper.getCorrespondingSeries(result)), MPTVSeriesLog.LogLevel.Debug);
                }

                XmlNode node = null;
                if (String.IsNullOrEmpty(languageID))
                {
                    node = Online_Parsing_Classes.OnlineAPI.UpdateSeries(sSeriesID);
                }
                else
                {
                    node = Online_Parsing_Classes.OnlineAPI.UpdateSeries(sSeriesID, languageID, aOverride);
                }

                if (node != null)
                {
                    foreach (XmlNode itemNode in node.SelectNodes("/Data"))
                    {
                        bool           hasDVDOrdering      = false;
                        bool           hasAbsoluteOrdering = false;
                        DBOnlineSeries series = new DBOnlineSeries();
                        foreach (XmlNode seriesNode in itemNode)
                        {
                            // first return item SHOULD ALWAYS be the series
                            if (seriesNode.Name.Equals("Series", StringComparison.InvariantCultureIgnoreCase))
                            {
                                foreach (XmlNode propertyNode in seriesNode.ChildNodes)
                                {
                                    if (propertyNode.Name == "Language") // work around inconsistancy (language = Language)
                                    {
                                        series["language"] = propertyNode.InnerText;
                                    }
                                    else if (DBOnlineSeries.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                                    {
                                        series[DBOnlineSeries.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                                    }
                                    else
                                    {
                                        // we don't know that field, add it to the series table
                                        series.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                                        series[propertyNode.Name] = propertyNode.InnerText;
                                    }
                                }
                                if (series != null)
                                {
                                    mSeriesList.Add(series);
                                }
                            }
                            else if (!hasDVDOrdering || !hasAbsoluteOrdering || seriesNode.Name.Equals("Episode", StringComparison.InvariantCultureIgnoreCase))
                            {
                                foreach (XmlNode propertyNode in seriesNode.ChildNodes)
                                {
                                    switch (propertyNode.Name)
                                    {
                                    case "DVD_episodenumber":
                                    case "DVD_season":
                                        if (!String.IsNullOrEmpty(propertyNode.InnerText))
                                        {
                                            hasDVDOrdering = true;
                                        }
                                        break;

                                    case "absolute_number":
                                        if (!String.IsNullOrEmpty(propertyNode.InnerText))
                                        {
                                            hasAbsoluteOrdering = true;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        if ((hasAbsoluteOrdering || hasDVDOrdering))
                        {
                            string ordering = series[DBOnlineSeries.cEpisodeOrders] == string.Empty ? "Aired|" : (string)series[DBOnlineSeries.cEpisodeOrders];
                            if (hasAbsoluteOrdering)
                            {
                                ordering += "Absolute|";
                            }
                            if (hasDVDOrdering)
                            {
                                ordering += "DVD";
                            }
                            series[DBOnlineSeries.cEpisodeOrders] = ordering;
                        }
                        if (series != null)
                        {
                            yield return(series);
                        }
                    }
                }
            }
        }
Exemple #29
0
        public static logicalViewStep parseFromDB(string viewStep, bool hasSeriesBeforeIt)
        {
            logicalViewStep thisView = new logicalViewStep();

            thisView.hasSeriesBeforeIt = hasSeriesBeforeIt;
            string[] viewSteps = System.Text.RegularExpressions.Regex.Split(viewStep, s_intSeperator);
            thisView.setType(viewSteps[0]);
            thisView.addConditionsFromString(viewSteps[1]);
            if (viewSteps[2].Length > 0)
            {
                string[] orderFields = System.Text.RegularExpressions.Regex.Split(viewSteps[2], ";");
                thisView.inLineSpecials    = orderFields[0] == "<Episode.EpisodeIndex>";
                thisView.inLineSpecialsAsc = orderFields[0] != "desc";
                for (int i = 0; i < orderFields.Length; i += 2)
                {
                    if (thisView.Type != type.group)
                    {
                        DBTable table      = null;
                        string  tableField = string.Empty;
                        getTableFieldname(orderFields[i], out table, out tableField);
                        tableField = getQTableNameFromUnknownType(table, tableField);

                        // example of how the user can order by a different table
                        // needs to be enabled once definable views are ready

                        /*
                         * if (thisView.Type == type.season && table.GetType() != typeof(DBSeason))
                         * {
                         *  Type lType = table.GetType();
                         *  if (lType == typeof(DBOnlineSeries))
                         *      tableField = "( select " + tableField + " from " + DBOnlineSeries.cTableName
                         + " where " + DBOnlineSeries.Q(DBOnlineSeries.cID) + " = " + DBSeason.Q(DBSeason.cSeriesID) + ")";
                         + }*/

                        //if (thisView.Type == type.episode && ( table.GetType() == typeof(DBEpisode) || table.GetType() == typeof(DBOnlineEpisode)))
                        //{
                        //    // for perf reason a subquery is build, otherwise custom orders and the nessesary join really slow down sqllite!
                        //    SQLCondition subQueryConditions = thisView.conds.Copy(); // have to have all conds too
                        //    subQueryConditions.AddOrderItem(tableField, (orderFields[i + 1] == "asc" ? SQLCondition.orderType.Ascending : SQLCondition.orderType.Descending));
                        //    if (viewSteps[3].Length > 0) // set the limit too
                        //    {
                        //        try
                        //        {
                        //            subQueryConditions.SetLimit(System.Convert.ToInt32(viewSteps[3]));
                        //        }
                        //        catch (Exception)
                        //        {
                        //        }
                        //    }
                        //    thisView.conds.AddSubQuery("compositeid", table, subQueryConditions, table.m_tableName + "." + DBEpisode.cCompositeID, SQLConditionType.In);

                        //}

                        thisView.conds.AddOrderItem(tableField, (orderFields[i + 1] == "asc" ? SQLCondition.orderType.Ascending : SQLCondition.orderType.Descending));
                    }
                }
            }
            if (thisView.Type == type.group && thisView.groupedBy != null) // for groups always by their values (ignore user setting!)
            {
                if (thisView.groupedBy.table.GetType() == typeof(DBSeries))
                {
                    if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
                    {
                        thisView.conds.Add(new DBSeries(), DBSeries.cHidden, 1, SQLConditionType.NotEqual);
                    }
                }
                else if (thisView.groupedBy.table.GetType() == typeof(DBOnlineSeries))
                {
                    if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
                    {
                        thisView.conds.AddCustom(" not exists ( select * from " + DBSeries.cTableName + " where id = " + DBOnlineSeries.Q(DBOnlineSeries.cID) + " and " + DBSeries.Q(DBSeries.cHidden) + " = 1)");
                    }
                }
                else if (thisView.groupedBy.table.GetType() == typeof(DBSeason))
                {
                    if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
                    {
                        thisView.conds.Add(new DBSeason(), DBSeason.cHidden, 1, SQLConditionType.NotEqual);
                    }
                }
                thisView.conds.AddOrderItem(thisView.groupedBy.tableField, SQLCondition.orderType.Descending); // tablefield includes tablename itself!
            }
            try
            {
                if (viewSteps[3].Length > 0)
                {
                    thisView.limitItems = System.Convert.ToInt32(viewSteps[3]);
                    thisView.conds.SetLimit(thisView.limitItems);
                }
            }
            catch (Exception)
            {
                MPTVSeriesLog.Write("Cannot interpret limit in logicalview, limit was: " + viewSteps[3]);
            }
            return(thisView);
        }
Exemple #30
0
        private IEnumerable<DBOnlineSeries> Work(String sSeriesID, String languageID)
        {
            if (sSeriesID.Length > 0)
            {
                int result;
                if (int.TryParse(sSeriesID,out result))
                    MPTVSeriesLog.Write(string.Format("Retrieving updated Metadata for series {0}",Helper.getCorrespondingSeries(result)), MPTVSeriesLog.LogLevel.Debug);

                XmlNode node = null;
                if (String.IsNullOrEmpty(languageID))
                {
                    node = Online_Parsing_Classes.OnlineAPI.UpdateSeries(sSeriesID);
                }
                else
                {
                    node = Online_Parsing_Classes.OnlineAPI.UpdateSeries(sSeriesID, languageID);
                }

                if (node != null)
                {
                    foreach (XmlNode itemNode in node.SelectNodes("/Data"))
                    {
                        bool hasDVDOrdering = false;
                        bool hasAbsoluteOrdering = false;
                        DBOnlineSeries series = new DBOnlineSeries();
                        foreach (XmlNode seriesNode in itemNode)
                        {
                            // first return item SHOULD ALWAYS be the series
                            if (seriesNode.Name.Equals("Series", StringComparison.InvariantCultureIgnoreCase))
                            {
                                foreach (XmlNode propertyNode in seriesNode.ChildNodes)
                                {
                                    if (propertyNode.Name == "Language") // work around inconsistancy (language = Language)
                                    {
                                        series["language"] = propertyNode.InnerText;
                                    }
                                    else if (DBOnlineSeries.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                                        series[DBOnlineSeries.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                                    else
                                    {
                                        // we don't know that field, add it to the series table
                                        series.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                                        series[propertyNode.Name] = propertyNode.InnerText;
                                    }
                                }
                                if (series != null) listSeries.Add(series);
                            }
                            else if(!hasDVDOrdering || !hasAbsoluteOrdering || seriesNode.Name.Equals("Episode", StringComparison.InvariantCultureIgnoreCase))
                            {
                                foreach (XmlNode propertyNode in seriesNode.ChildNodes)
                                {
                                    switch (propertyNode.Name)
                                    {
                                        case "DVD_episodenumber":
                                        case "DVD_season":
                                            if(!String.IsNullOrEmpty(propertyNode.InnerText)) hasDVDOrdering = true;
                                            break;
                                        case "absolute_number":
                                            if (!String.IsNullOrEmpty(propertyNode.InnerText)) hasAbsoluteOrdering = true;
                                            break;
                                    }
                                }
                            }
                        }
                        if ((hasAbsoluteOrdering || hasDVDOrdering))
                        {
                            string ordering = series[DBOnlineSeries.cEpisodeOrders] == string.Empty ? "Aired|" : (string)series[DBOnlineSeries.cEpisodeOrders];
                            if (hasAbsoluteOrdering) ordering += "Absolute|";
                            if (hasDVDOrdering) ordering += "DVD";
                            series[DBOnlineSeries.cEpisodeOrders] = ordering;
                        }
                        if(series != null) yield return series;
                    }
                }
            }
        }