示例#1
0
        static DBOnlineEpisode()
        {
            //////////////////////////////////////////////////
            #region Pretty Names displayed in Configuration Details Tab
            s_FieldToDisplayNameMap.Add(cID, "Episode ID");
            s_FieldToDisplayNameMap.Add(cEpisodeSummary, "Overview");
            s_FieldToDisplayNameMap.Add(cMyRating, "My Rating");
            s_FieldToDisplayNameMap.Add(cFirstAired, "Air Date");
            s_FieldToDisplayNameMap.Add(cGuestStars, "Guest Stars");
            s_FieldToDisplayNameMap.Add(cDVDEpisodeNumber, "DVD Episode Number");
            s_FieldToDisplayNameMap.Add(cDVDSeasonNumber, "DVD Season Number");
            s_FieldToDisplayNameMap.Add(cAirsAfterSeason, "Airs After Season");
            s_FieldToDisplayNameMap.Add(cAirsBeforeSeason, "Airs Before Season");
            s_FieldToDisplayNameMap.Add(cAirsBeforeEpisode, "Airs Before Episode");
            #endregion
            //////////////////////////////////////////////////

            //////////////////////////////////////////////////
            #region Local DB field mapping to Online DB
            s_OnlineToFieldMap.Add("SeasonNumber", cSeasonIndex);
            s_OnlineToFieldMap.Add("EpisodeNumber", cEpisodeIndex);
            s_OnlineToFieldMap.Add("EpisodeName", cEpisodeName);
            s_OnlineToFieldMap.Add("id", cID);
            s_OnlineToFieldMap.Add("Overview", cEpisodeSummary);
            s_OnlineToFieldMap.Add("FirstAired", cFirstAired);
            s_OnlineToFieldMap.Add("filename", cEpisodeThumbnailUrl);
            #endregion
            //////////////////////////////////////////////////

            // lately it also returns seriesID (which we already had before - but unfortunatly not in all lower case, prevents an error msg, thats all
            s_OnlineToFieldMap.Add("seriesid", cSeriesID);

            // make sure the table is created on first run
            DBOnlineEpisode dummy = new DBOnlineEpisode();
        }
示例#2
0
        public void doWork(int nSeriesID)
        {
            XmlNode node = Online_Parsing_Classes.OnlineAPI.UpdateEpisodes(nSeriesID);

            if (node == null)
            {
                return;
            }

            foreach (XmlNode episodeNode in node.SelectNodes("Episode"))
            {
                DBOnlineEpisode episode = new DBOnlineEpisode();
                foreach (XmlNode propertyNode in episodeNode.ChildNodes)
                {
                    if (DBOnlineEpisode.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                    {
                        episode[DBOnlineEpisode.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
                    }
                    else
                    {
                        // we don't know that field, add it to the table
                        episode.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                        episode[propertyNode.Name] = propertyNode.InnerText;
                    }
                }
                listEpisodes.Add(episode);
            }
        }
示例#3
0
 static string replaceEpisodeTags(DBOnlineEpisode s, string what)
 {
     if (s == null || what.Length < epIdentifier.Length)
     {
         return(what);
     }
     return(getValuesOfType(s, what, epParse, epIdentifier));
 }
示例#4
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;
            }
        }
示例#5
0
 public void doWork(int nSeriesID)
 {            
     XmlNode node = Online_Parsing_Classes.OnlineAPI.UpdateEpisodes(nSeriesID);
     if (node == null) return;
     
     foreach (XmlNode episodeNode in node.SelectNodes("Episode"))
     {
         DBOnlineEpisode episode = new DBOnlineEpisode();
         foreach (XmlNode propertyNode in episodeNode.ChildNodes)
         {
             if (DBOnlineEpisode.s_OnlineToFieldMap.ContainsKey(propertyNode.Name))
                 episode[DBOnlineEpisode.s_OnlineToFieldMap[propertyNode.Name]] = propertyNode.InnerText;
             else
             {
                 // we don't know that field, add it to the table
                 episode.AddColumn(propertyNode.Name, new DBField(DBField.cTypeString));
                 episode[propertyNode.Name] = propertyNode.InnerText;
             }
         }                            
         listEpisodes.Add(episode);
     }                             
     
 }
示例#6
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);
            }
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
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;
     }
 }
示例#10
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));
        }
示例#11
0
 static string replaceEpisodeTags(DBOnlineEpisode s, string what)
 {
     if (s == null || what.Length < epIdentifier.Length) return what;
     return getValuesOfType(s, what, epParse, epIdentifier);
 }
示例#12
0
        static DBOnlineEpisode()
        {
            //////////////////////////////////////////////////
            #region Pretty Names displayed in Configuration Details Tab
            s_FieldToDisplayNameMap.Add(cID, "Episode ID");
            s_FieldToDisplayNameMap.Add(cEpisodeSummary, "Overview");
            s_FieldToDisplayNameMap.Add(cMyRating, "My Rating");
            s_FieldToDisplayNameMap.Add(cFirstAired, "Air Date");
            s_FieldToDisplayNameMap.Add(cGuestStars, "Guest Stars");
            s_FieldToDisplayNameMap.Add(cDVDEpisodeNumber, "DVD Episode Number");
            s_FieldToDisplayNameMap.Add(cDVDSeasonNumber, "DVD Season Number");
            s_FieldToDisplayNameMap.Add(cAirsAfterSeason, "Airs After Season");
            s_FieldToDisplayNameMap.Add(cAirsBeforeSeason, "Airs Before Season");
            s_FieldToDisplayNameMap.Add(cAirsBeforeEpisode, "Airs Before Episode");
            #endregion
            //////////////////////////////////////////////////

            //////////////////////////////////////////////////
            #region Local DB field mapping to Online DB
            s_OnlineToFieldMap.Add("SeasonNumber", cSeasonIndex);
            s_OnlineToFieldMap.Add("EpisodeNumber", cEpisodeIndex);
            s_OnlineToFieldMap.Add("EpisodeName", cEpisodeName);
            s_OnlineToFieldMap.Add("id", cID);
            s_OnlineToFieldMap.Add("Overview", cEpisodeSummary);
            s_OnlineToFieldMap.Add("FirstAired", cFirstAired);
            s_OnlineToFieldMap.Add("filename", cEpisodeThumbnailUrl);
            #endregion
            //////////////////////////////////////////////////

            // lately it also returns seriesID (which we already had before - but unfortunatly not in all lower case, prevents an error msg, thats all
            s_OnlineToFieldMap.Add("seriesid", cSeriesID);

            // make sure the table is created on first run
            DBOnlineEpisode dummy = new DBOnlineEpisode();
        }
示例#13
0
        public static void SynchronizeLibrary(List <DBEpisode> episodes, TraktSyncModes mode)
        {
            if (episodes.Count == 0)
            {
                return;
            }

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

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

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

                TraktSync traktSync = GetTraktSyncObject(series, episodes);

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

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

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

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

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

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

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

                    case TraktSyncModes.unlibrary:
                        break;
                    }
                }

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