Ejemplo n.º 1
0
        public static void AddDefaults()
        {
            DBExpression expression = new DBExpression();

            expression[DBExpression.cEnabled]    = "1";
            expression[DBExpression.cIndex]      = "0";
            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^(?:.*\\)?(?<series>[^\\]+?)[ _.\-\[]+(?:[s]?(?<season>\d+)[ _.\-\[\]]*[ex](?<episode>\d+)|(?:\#|\-\s)(?<season>(?!(?:\d{4}.\d{2}.\d{2}|\d{2}.\d{2}.\d{4}))\d+)\.(?<episode>\d+))(?:[ _.+-]+(?:[s]?\k<season>[ _.\-\[\]]*[ex](?<episode2>\d+)|(?:\#|\-\s)\k<season>\.(?<episode2>\d+))|(?:[ _.+-]*[ex+-]+(?<episode2>\d+)))*[ _.\-\[\]]*(?<title>(?![^\\].*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cIndex]      = "1";
            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^.*?\\?(?<series>[^\\$]+?)(?:s(?<season>[0-3]?\d)\s?ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?![^\\]*?sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cIndex]      = "2";
            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^(?<series>[^\\$]+)\\[^\\$]*?(?:s(?<season>[0-1]?\d)ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?!.*sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cIndex]      = "3";
            expression[DBExpression.cExpression] = @"(?<series>[^\\\[]*) - \[(?<season>[0-9]{1,2})x(?<episode>[0-9\W]+)\](( |)(-( |)|))(?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)";
            expression.Commit();

            expression[DBExpression.cIndex]      = "4";
            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"(?<series>[^\\$]*) - season (?<season>[0-9]{1,2}) - (?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)";
            expression.Commit();

            expression[DBExpression.cIndex]      = "5";
            expression[DBExpression.cType]       = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"(^.*?\\?(?<series>[^\\$]+?)[ .-]+(?<firstaired>\d{2,4}[.-]\d{2}[.-]\d{2,4})[ .-]*(?<title>(?![^\\]*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$)";
            expression.Commit();

            expression[DBExpression.cIndex]      = "6";
            expression[DBExpression.cType]       = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series> - <season>x<episode> - <title>.<ext>";
            expression.Commit();

            expression[DBExpression.cIndex]      = "7";
            expression[DBExpression.cType]       = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series>\Season <season>\Episode <episode> - <title>.<ext>";
            expression.Commit();

            expression[DBExpression.cIndex]      = "8";
            expression[DBExpression.cType]       = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series>\<season>x<episode> - <title>.<ext>";
            expression.Commit();
        }
Ejemplo n.º 2
0
        static DBExpression()
        {
            // make sure the table is created - create a dummy object
            DBExpression dummy = new DBExpression();

            DBExpression[] expressions = DBExpression.GetAll();

            if (expressions == null || expressions.Length == 0)
            {
                // no expressions in the db, add defaults
                AddDefaults();
            }
            else
            {
                // upgrade, add any new expressions
                int nCurrentDBVersion = cDBVersion;
                int nUpgradeDBVersion = DBOption.GetOptions(DBOption.cDBExpressionsVersion);

                while (nUpgradeDBVersion != nCurrentDBVersion)
                {
                    DBExpression expression = new DBExpression();
                    switch (nUpgradeDBVersion)
                    {
                    case 4:
                        expression[DBExpression.cEnabled]    = "1";
                        expression[DBExpression.cIndex]      = expressions.Length;
                        expression[DBExpression.cType]       = DBExpression.cType_Regexp;
                        expression[DBExpression.cExpression] = @"(^.*?\\?(?<series>[^\\$]+?)[ .-]+(?<firstaired>\d{2,4}[.-]\d{2}[.-]\d{2,4})[ .-]*(?<title>(?![^\\]*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$)";
                        expression.Commit();
                        break;
                    }
                    nUpgradeDBVersion++;
                }

                DBOption.SetOptions(DBOption.cDBExpressionsVersion, nCurrentDBVersion);
            }
        }
Ejemplo n.º 3
0
 public static DBExpression[] GetAll()
 {
     try
     {
         // retrieve all fields in the table
         String          sqlQuery = "select * from " + cTableName + " order by " + cIndex;
         SQLiteResultSet results  = DBTVSeries.Execute(sqlQuery);
         if (results.Rows.Count > 0)
         {
             DBExpression[] expressions = new DBExpression[results.Rows.Count];
             for (int index = 0; index < results.Rows.Count; index++)
             {
                 expressions[index] = new DBExpression();
                 expressions[index].Read(ref results, index);
             }
             return(expressions);
         }
     }
     catch (Exception ex)
     {
         MPTVSeriesLog.Write("Error in DBExpression.Get (" + ex.Message + ").");
     }
     return(null);
 }
Ejemplo n.º 4
0
        static DBExpression()
        {
            // make sure the table is created - create a dummy object
            DBExpression dummy = new DBExpression();
            DBExpression[] expressions = DBExpression.GetAll();

            if (expressions == null || expressions.Length == 0)
            {
                // no expressions in the db, add defaults
                AddDefaults();
            }
            else
            {
                // upgrade, add any new expressions
                int nCurrentDBVersion = cDBVersion;
                int nUpgradeDBVersion = DBOption.GetOptions(DBOption.cDBExpressionsVersion);

                while (nUpgradeDBVersion != nCurrentDBVersion)
                {
                    DBExpression expression = new DBExpression();
                    switch (nUpgradeDBVersion)
                    {
                        case 4:
                            expression[DBExpression.cEnabled] = "1";
                            expression[DBExpression.cIndex] = expressions.Length;
                            expression[DBExpression.cType] = DBExpression.cType_Regexp;
                            expression[DBExpression.cExpression] = @"(^.*?\\?(?<series>[^\\$]+?)[ .-]+(?<firstaired>\d{2,4}[.-]\d{2}[.-]\d{2,4})[ .-]*(?<title>(?![^\\]*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$)";
                            expression.Commit();
                            break;
                    }
                    nUpgradeDBVersion++;
                }

                DBOption.SetOptions(DBOption.cDBExpressionsVersion, nCurrentDBVersion);
            }
        }
Ejemplo n.º 5
0
        private void button_MoveExpUp_Click(object sender, EventArgs e)
        {               
            int nCurrentRow = dataGridView_Expressions.CurrentCellAddress.Y;
            int nCurrentCol = dataGridView_Expressions.CurrentCellAddress.X;

            if (nCurrentRow > 0)
            {                           
                DBExpression expressionGoingUp = new DBExpression(nCurrentRow);
                DBExpression expressionGoingDown = new DBExpression(nCurrentRow - 1);
                
                DBExpression.Clear(nCurrentRow - 1);
                DBExpression.Clear(nCurrentRow);
                
                expressionGoingUp[DBExpression.cIndex] = Convert.ToString(nCurrentRow - 1);                                
                expressionGoingUp.Commit();

                expressionGoingDown[DBExpression.cIndex] = Convert.ToString(nCurrentRow);
                expressionGoingDown.Commit();

                LoadExpressions();

                dataGridView_Expressions.CurrentCell = dataGridView_Expressions.Rows[nCurrentRow - 1].Cells[nCurrentCol];
            }
        }
Ejemplo n.º 6
0
        private void SaveAllExpressions()
        {
            // need to save back all the rows
            DBExpression.ClearAll();

            foreach (DataGridViewRow row in dataGridView_Expressions.Rows)
            {
                if (row.Index != dataGridView_Expressions.NewRowIndex)
                {
                    DBExpression expression = new DBExpression();
                    expression[DBExpression.cIndex] = row.Index.ToString();
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        if (cell.Value == null)
                            return;
                        if (cell.ValueType.Name == "Boolean")
                            expression[cell.OwningColumn.Name] = (Boolean)cell.Value;
                        else
                            expression[cell.OwningColumn.Name] = (String)cell.Value;
                    }
                    expression.Commit();
                }
            }
        }
Ejemplo n.º 7
0
 private void dataGridView_Expressions_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     DBExpression expression = new DBExpression();
     expression[DBExpression.cIndex] = e.RowIndex.ToString();
     foreach (DataGridViewCell cell in dataGridView_Expressions.Rows[e.RowIndex].Cells)
     {
         if (cell.Value == null)
             return;
         if (cell.ValueType.Name == "Boolean")
             expression[cell.OwningColumn.Name] = (Boolean)cell.Value;
         else
             expression[cell.OwningColumn.Name] = (String)cell.Value;
     }
     expression.Commit();
 }
Ejemplo n.º 8
0
        private void linkImpParsingExpressions_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            OpenFileDialog fd = new OpenFileDialog();
            fd.Filter = "Exported Parsing Expressions (*.expr)|*.expr";
            if (fd.ShowDialog() == DialogResult.OK && System.IO.File.Exists(fd.FileName))
            {
                StreamReader r = new StreamReader(fd.FileName);
                DBExpression expr;

                //Dialog box to make sure they want to clear out current expressions to import new ones.
                if (DialogResult.Yes ==
                    MessageBox.Show("You are about to delete all current parsing expressions," + Environment.NewLine +
                        "and replace them with the imported file." + Environment.NewLine + Environment.NewLine +
                        "Any current Expressions will be lost.  Would you like to proceed?", "Import Expressions", MessageBoxButtons.YesNo))
                {
                    dataGridView_Expressions.Rows.Clear();
                    DBExpression.ClearAll();
                    MPTVSeriesLog.Write("Expressions cleared");
                }

                string line = string.Empty;
                string[] parts;
                int index = 0;

                // now set watched for all in file
                while ((line = r.ReadLine()) != null)
                {
                    char[] c = {';'};
                    parts = line.Split(c, 3);
                    if (parts.Length != 3) continue;

                    expr = new DBExpression();
                    //if (Convert.ToInt32(parts[0]) >= 0) expr[DBExpression.cIndex] = parts[0]; else continue;
                    expr[DBExpression.cIndex] = index;
                    if (Convert.ToInt32(parts[0]) == 0 || Convert.ToInt32(parts[0]) == 1) expr[DBExpression.cEnabled] = parts[0]; else continue;
                    if (parts[1] == DBExpression.cType_Regexp || parts[1] == DBExpression.cType_Simple) expr[DBExpression.cType] = parts[1]; else continue;
                    expr[DBExpression.cExpression] = parts[2];
                   
                    if (expr.Commit()) index++;
                }

                r.Close();
                MPTVSeriesLog.Write("Parsing Expressions succesfully imported!");
                
                LoadExpressions();                
            }
        }
Ejemplo n.º 9
0
        private void button_MoveExpDown_Click(object sender, EventArgs e)
        {
            int nCurrentRow = dataGridView_Expressions.CurrentCellAddress.Y;
            int nCurrentCol = dataGridView_Expressions.CurrentCellAddress.X;

            // don't take in account the new line
            if (nCurrentRow < dataGridView_Expressions.Rows.Count - 2) 
            {
                DBExpression expressionGoingDown = new DBExpression(nCurrentRow);
                DBExpression expressionGoingUp = new DBExpression(nCurrentRow + 1);
                
                DBExpression.Clear(nCurrentRow);
                DBExpression.Clear(nCurrentRow + 1);

                expressionGoingUp[DBExpression.cIndex] = Convert.ToString(nCurrentRow);
                expressionGoingUp.Commit();

                expressionGoingDown[DBExpression.cIndex] = Convert.ToString(nCurrentRow + 1);
                expressionGoingDown.Commit();
                
                LoadExpressions();

                dataGridView_Expressions.CurrentCell = dataGridView_Expressions.Rows[nCurrentRow + 1].Cells[nCurrentCol];
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads and compile Parsing Expressions and also String Replacements
        /// </summary>
        /// <returns></returns>
        public static bool reLoadExpressions()
        {
            // build a list of all the regular expressions to apply
            bool error = false;

            try
            {
                MPTVSeriesLog.Write("Compiling Parsing Expressions");
                sExpressions.Clear();
                regularExpressions.Clear();
                replacementRegexAfter.Clear();
                replacementRegexBefore.Clear();
                DBExpression[] expressions = DBExpression.GetAll();
                foreach (DBExpression expression in expressions)
                {
                    if (expression[DBExpression.cEnabled] != 0)
                    {
                        String sExpression = String.Empty;
                        switch ((String)expression[DBExpression.cType])
                        {
                        case DBExpression.cType_Simple:
                            sExpression = ConvertSimpleExpressionToRegEx(expression[DBExpression.cExpression]);
                            break;

                        case DBExpression.cType_Regexp:
                            sExpression = expression[DBExpression.cExpression];
                            break;
                        }
                        sExpression = sExpression.ToLower();
                        // replace series, season and episode by the valid DBEpisode column names
                        sExpression = sExpression.Replace("<series>", "<" + DBSeries.cParsedName + ">");
                        sExpression = sExpression.Replace("<season>", "<" + DBEpisode.cSeasonIndex + ">");
                        sExpression = sExpression.Replace("<episode>", "<" + DBEpisode.cEpisodeIndex + ">");
                        sExpression = sExpression.Replace("<episode2>", "<" + DBEpisode.cEpisodeIndex2 + ">");
                        sExpression = sExpression.Replace("<title>", "<" + DBEpisode.cEpisodeName + ">");
                        sExpression = sExpression.Replace("<firstaired>", "<" + DBOnlineEpisode.cFirstAired + ">");

                        // we precompile the expressions here which is faster in the end
                        try
                        {
                            regularExpressions.Add(new Regex(sExpression, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.Compiled));
                            sExpressions.Add(sExpression);
                        }
                        catch (Exception e)
                        {
                            // wrong regex
                            MPTVSeriesLog.Write("Cannot use the following Expression: " + e.Message);
                        }
                    }
                }
                MPTVSeriesLog.Write("Finished Compiling Parsing Expressions, found " + sExpressions.Count.ToString() + " valid expressions");
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("Error loading Parsing Expressions: " + ex.Message);
                error = true;
            }
            // now go for the replacements
            try
            {
                MPTVSeriesLog.Write("Compiling Replacement Expressions");

                foreach (DBReplacements replacement in DBReplacements.GetAll())
                {
                    try
                    {
                        if (replacement[DBReplacements.cEnabled])
                        {
                            String searchString = replacement[DBReplacements.cToReplace];
                            searchString = searchString
                                           .Replace("<space>", " ");
                            string regexSearchString = searchString;
                            if (!replacement[DBReplacements.cIsRegex])
                            {
                                regexSearchString = Regex.Escape(searchString);
                            }

                            String replaceString = replacement[DBReplacements.cWith];
                            replaceString = replaceString
                                            .Replace("<space>", " ")
                                            .Replace("<empty>", "");

                            var replaceRegex = new Regex(regexSearchString, RegexOptions.Compiled | RegexOptions.IgnoreCase);

                            if (replacement[DBReplacements.cBefore])
                            {
                                replacementRegexBefore.Add(replaceRegex, replaceString);
                            }
                            else
                            {
                                replacementRegexAfter.Add(replaceRegex, replaceString);
                            }

                            if (replacement[DBReplacements.cTagEnabled])
                            {
                                tags.Add(searchString);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        MPTVSeriesLog.Write("Cannot use the following Expression: " + e.Message);
                    }
                }
                MPTVSeriesLog.Write("Finished Compiling Replacement Expressions, found " + (replacementRegexBefore.Count + replacementRegexAfter.Count).ToString() + " valid expressions");

                return(error);
            }
            catch (Exception ex)
            {
                MPTVSeriesLog.Write("Error loading String Replacements: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 11
0
        public static void Clear(int Index)
        {
            DBExpression dummy = new DBExpression(Index);

            Clear(dummy, new SQLCondition(dummy, DBExpression.cIndex, Index, SQLConditionType.Equal));
        }
Ejemplo n.º 12
0
        public static void AddDefaults()
        {
            DBExpression expression = new DBExpression();
            expression[DBExpression.cEnabled] = "1";
            expression[DBExpression.cIndex] = "0";
            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^(?:.*\\)?(?<series>[^\\]+?)[ _.\-\[]+(?:[s]?(?<season>\d+)[ _.\-\[\]]*[ex](?<episode>\d+)|(?:\#|\-\s)(?<season>(?!(?:\d{4}.\d{2}.\d{2}|\d{2}.\d{2}.\d{4}))\d+)\.(?<episode>\d+))(?:[ _.+-]+(?:[s]?\k<season>[ _.\-\[\]]*[ex](?<episode2>\d+)|(?:\#|\-\s)\k<season>\.(?<episode2>\d+))|(?:[ _.+-]*[ex+-]+(?<episode2>\d+)))*[ _.\-\[\]]*(?<title>(?![^\\].*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cIndex] = "1";
            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^.*?\\?(?<series>[^\\$]+?)(?:s(?<season>[0-3]?\d)\s?ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?![^\\]*?sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cIndex] = "2";
            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"^(?<series>[^\\$]+)\\[^\\$]*?(?:s(?<season>[0-1]?\d)ep?(?<episode>\d\d)|(?<season>(?:[0-1]\d|(?<!\d)\d))x?(?<episode>\d\d))(?!\d)(?:[ .-]?(?:s\k<season>e?(?<episode2>\d{2}(?!\d))|\k<season>x?(?<episode2>\d{2}(?!\d))|(?<episode2>\d\d(?!\d))|E(?<episode2>\d\d))|)[ -.]*(?<title>(?!.*sample)[^\\]*?[^\\]*?)\.(?<ext>[^.]*)$";
            expression.Commit();

            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cIndex] = "3";
            expression[DBExpression.cExpression] = @"(?<series>[^\\\[]*) - \[(?<season>[0-9]{1,2})x(?<episode>[0-9\W]+)\](( |)(-( |)|))(?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)";
            expression.Commit();

            expression[DBExpression.cIndex] = "4";
            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"(?<series>[^\\$]*) - season (?<season>[0-9]{1,2}) - (?<title>(?![^\\]*?sample)[^$]*?)\.(?<ext>[^.]*)";
            expression.Commit();

            expression[DBExpression.cIndex] = "5";
            expression[DBExpression.cType] = DBExpression.cType_Regexp;
            expression[DBExpression.cExpression] = @"(^.*?\\?(?<series>[^\\$]+?)[ .-]+(?<firstaired>\d{2,4}[.-]\d{2}[.-]\d{2,4})[ .-]*(?<title>(?![^\\]*?(?<!the)[ .(-]sample[ .)-]).*?)\.(?<ext>[^.]*)$)";
            expression.Commit();

            expression[DBExpression.cIndex] = "6";
            expression[DBExpression.cType] = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series> - <season>x<episode> - <title>.<ext>";
            expression.Commit();

            expression[DBExpression.cIndex] = "7";
            expression[DBExpression.cType] = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series>\Season <season>\Episode <episode> - <title>.<ext>";
            expression.Commit();

            expression[DBExpression.cIndex] = "8";
            expression[DBExpression.cType] = DBExpression.cType_Simple;
            expression[DBExpression.cExpression] = @"<series>\<season>x<episode> - <title>.<ext>";
            expression.Commit();
            
        }
Ejemplo n.º 13
0
 public static DBExpression[] GetAll()
 {
     try
     {
         // retrieve all fields in the table
         String sqlQuery = "select * from " + cTableName + " order by " + cIndex;
         SQLiteResultSet results = DBTVSeries.Execute(sqlQuery);
         if (results.Rows.Count > 0)
         {
             DBExpression[] expressions = new DBExpression[results.Rows.Count];
             for (int index = 0; index < results.Rows.Count; index++)
             {
                 expressions[index] = new DBExpression();
                 expressions[index].Read(ref results, index);
             }
             return expressions;
         }
     }
     catch (Exception ex)
     {
         MPTVSeriesLog.Write("Error in DBExpression.Get (" + ex.Message + ").");
     }
     return null;
 }
Ejemplo n.º 14
0
 public static void Clear(int Index) {
     DBExpression dummy = new DBExpression(Index);
     Clear(dummy, new SQLCondition(dummy, DBExpression.cIndex, Index, SQLConditionType.Equal));            
 }