Exemple #1
0
 public static string ExtractTextValues(NamedValues <ZValue> infos, string s)
 {
     // French | PDF | 107 MB -*- French | PDF |  22 Pages | 7 MB -*- PDF | 116 pages | 53 Mb | French -*- Micro Application | 2010 | ISBN: 2300028441 | 221 pages | PDF
     // pb : |I|N|F|O|S|, |S|Y|N|O|P|S|I|S|, |T|E|L|E|C|H|A|R|G|E|R|
     // example http://www.telechargement-plus.com/e-book-magazines/bande-dessines/136846-season-one-100-marvel-syrie-en-cours-10-tomes-comicmulti.html
     if (s.Contains('|'))
     {
         //Trace.CurrentTrace.WriteLine("info \"{0}\"", s);
         foreach (string s2 in zsplit.Split(s, '|', true))
         {
             string s3 = s2;
             NamedValues <ZValue> values = _textInfoRegexList.ExtractTextValues(ref s3);
             infos.SetValues(values);
             s3 = s3.Trim();
             if (s3 != "")
             {
                 infos.SetValue(s3, null);
             }
         }
         return("");
     }
     else
     {
         NamedValues <ZValue> values = _textInfoRegexList.ExtractTextValues(ref s);
         infos.SetValues(values);
         return(s);
     }
 }
Exemple #2
0
        public PrintTitleInfos ExtractTitleInfos(string title)
        {
            // LES JOURNAUX -  MERCREDI 29 / 30 OCTOBRE 2014 & + [PDF][Lien Direct]
            // extract [PDF][Lien Direct]
            //string title = post.title;
            if (title == null)
            {
                return new PrintTitleInfos {
                           foundInfo = false
                }
            }
            ;
            NamedValues <ZValue> infos = new NamedValues <ZValue>();
            bool foundInfo             = false;

            while (true)
            {
                Match match = __rgTitleInfo.Match(title);

                if (!match.Success)
                {
                    break;
                }
                foundInfo = true;
                infos.SetValue(match.Groups[1].Value, null);
                title = match.zReplace(title, "_");
            }
            if (foundInfo)
            {
                title = Trim(title);
                return(new PrintTitleInfos {
                    foundInfo = true, title = title, infos = infos
                });
            }
            else
            {
                return new PrintTitleInfos {
                           foundInfo = false
                }
            };
        }
Exemple #3
0
        public static NamedValues<ZValue> ParseValues(string values, bool useLowercaseKey = false)
        {
            // datetime yyyy-mm-jj hh:mm:ss(.fff), datetime yyyy-mm-jj hh:mm:ss(.fff), date jj/mm/yyyy, date yyyy-mm-jj, time ((d.)hh:)mm:ss(.fff), double 1.(234), int 123, text 'text', text "text"
            // "datetime1 = 01/01/2015 01:35:52.123, datetime2 = 2015-01-01 01:35:52.123, date1 = 01/01/2015, date2 = 2015-01-01, time = 1.01:35:52.1234567, double = 1.123, int = 3, bool1 = true, bool2 =  false, text1 = 'toto', text2 = \"toto\""
            // "version = 3, date = 01/01/2015, text1 = 'toto', text2 = \"toto\", time = 01:35:52"
            NamedValues<ZValue> namedValues = new NamedValues<ZValue>(useLowercaseKey);
            if (values == null)
                return namedValues;
            Match match = __parseValues.Match(values);
            while (match.Success)
            {
                string name = match.Groups[1].Value;
                ZValue value = null;
                if (match.Groups[2].Value != "")
                {
                    // datetime jj/mm/yyyy hh:mm:ss(.fff) : Groups[2] day, Groups[3] month, Groups[4] year, Groups[5] hour, Groups[6] minute, Groups[7] second, Groups[8] millisecond
                    value = new DateTime(int.Parse(match.Groups[4].Value), int.Parse(match.Groups[3].Value), int.Parse(match.Groups[2].Value), int.Parse(match.Groups[5].Value),
                        int.Parse(match.Groups[6].Value), int.Parse(match.Groups[7].Value), int.Parse(match.Groups[8].Value.PadRight(3, '0')));
                }
                else if (match.Groups[9].Value != "")
                {
                    // datetime yyyy-mm-jj hh:mm:ss(.fff) : Groups[9] year, Groups[10] month, Groups[11] day, Groups[12] hour, Groups[13] minute, Groups[14] second, Groups[15] millisecond
                    value = new DateTime(int.Parse(match.Groups[9].Value), int.Parse(match.Groups[10].Value), int.Parse(match.Groups[11].Value), int.Parse(match.Groups[12].Value),
                        int.Parse(match.Groups[13].Value), int.Parse(match.Groups[14].Value), int.Parse(match.Groups[15].Value.PadRight(3, '0')));
                }
                else if (match.Groups[16].Value != "")
                {
                    // date jj/mm/yyyy : Groups[16] day, Groups[17] month, Groups[18] year
                    value = new DateTime(int.Parse(match.Groups[18].Value), int.Parse(match.Groups[17].Value), int.Parse(match.Groups[16].Value));
                }
                else if (match.Groups[19].Value != "")
                {
                    // date yyyy-mm-jj : Groups[19] year, Groups[20] month, Groups[21] day
                    value = new DateTime(int.Parse(match.Groups[19].Value), int.Parse(match.Groups[20].Value), int.Parse(match.Groups[21].Value));
                }
                else if (match.Groups[22].Value != "")
                {
                    // time ((d.)hh:)mm:ss(.fffffff) : Groups[22] days, Groups[23] hours, Groups[24] minutes, Groups[25] seconds, Groups[26] seconds decimales
                    int days = 0;
                    string group = match.Groups[22].Value;
                    if (group != "")
                        days = int.Parse(group);

                    int hours = 0;
                    group = match.Groups[23].Value;
                    if (group != "")
                        hours = int.Parse(group);

                    int minutes = 0;
                    group = match.Groups[24].Value;
                    if (group != "")
                        minutes = int.Parse(group);

                    int seconds = 0;
                    group = match.Groups[25].Value;
                    if (group != "")
                        seconds = int.Parse(group);

                    // ticks 1 234 567
                    int ticks = 0;
                    group = match.Groups[26].Value;
                    if (group != "")
                        ticks = int.Parse(group.PadRight(7, '0'));

                    value = zparse.CreateTimeSpan(days, hours, minutes, seconds, ticks);
                }
                else if (match.Groups[27].Value != "")
                {
                    // double 1.(234) : Groups[27] double
                    value = double.Parse(match.Groups[27].Value);
                }
                else if (match.Groups[28].Value != "")
                {
                    // int 123 : Groups[28] int
                    value = int.Parse(match.Groups[28].Value);
                }
                else if (match.Groups[29].Value != "")
                {
                    // bool true false : Groups[29] bool
                    value = bool.Parse(match.Groups[29].Value);
                }
                else if (match.Groups[30].Value != "")
                {
                    // text 'text' : Groups[30] text
                    value = match.Groups[30].Value;
                }
                else if (match.Groups[31].Value != "")
                {
                    // text "text" : Groups[31] text
                    value = match.Groups[31].Value;
                }
                //namedValues.Add(name, value);
                namedValues.SetValue(name, value);
                match = match.NextMatch();
            }
            return namedValues;
        }
 public PrintTitleInfos ExtractTitleInfos(string title)
 {
     // LES JOURNAUX -  MERCREDI 29 / 30 OCTOBRE 2014 & + [PDF][Lien Direct]
     // extract [PDF][Lien Direct]
     //string title = post.title;
     if (title == null)
         return new PrintTitleInfos { foundInfo = false };
     NamedValues<ZValue> infos = new NamedValues<ZValue>();
     bool foundInfo = false;
     while (true)
     {
         Match match = __rgTitleInfo.Match(title);
         if (!match.Success)
             break;
         foundInfo = true;
         infos.SetValue(match.Groups[1].Value, null);
         title = match.zReplace(title, "_");
     }
     if (foundInfo)
     {
         title = Trim(title);
         return new PrintTitleInfos { foundInfo = true, title = title, infos = infos };
     }
     else
         return new PrintTitleInfos { foundInfo = false };
 }
 private string ExtractTextValues(NamedValues<ZValue> infos, string s)
 {
     // French | PDF | 107 MB -*- French | PDF |  22 Pages | 7 MB -*- PDF | 116 pages | 205/148 pages | 53 Mb | French -*- Micro Application | 2010 | ISBN: 2300028441 | 221 pages | PDF
     // pb : |I|N|F|O|S|, |S|Y|N|O|P|S|I|S|, |T|E|L|E|C|H|A|R|G|E|R|
     // example http://www.telechargement-plus.com/e-book-magazines/bande-dessines/136846-season-one-100-marvel-syrie-en-cours-10-tomes-comicmulti.html
     if (s.Contains('|'))
     {
         //Trace.CurrentTrace.WriteLine("info \"{0}\"", s);
         foreach (string s2 in zsplit.Split(s, '|', true))
         {
             string s3 = s2;
             NamedValues<ZValue> values = _textInfoRegexList.ExtractTextValues(ref s3);
             infos.SetValues(values);
             //s3 = s3.Trim();
             s3 = Trim(s3);
             if (s3 != "")
             {
                 string name;
                 string value;
                 if (ExtractTextValues2(s3, out name, out value))
                     infos.SetValue(name, value);
                 else
                     infos.SetValue(s3, null);
             }
         }
         return "";
     }
     else
     //{
     //    NamedValues<ZValue> values = _textInfoRegexList.ExtractTextValues(ref s);
     //    infos.SetValues(values);
     //    return s;
     //}
     return s;
 }
Exemple #6
0
        public void SetTextValues(IEnumerable <string> texts)
        {
            string name = null;
            string text = null;

            foreach (string s in texts)
            {
                // PDF | 116 pages | 53 Mb | French
                //Trace.CurrentTrace.WriteLine("SetTextValues : \"{0}\"", s);
                if (s == "\r\n")
                {
                    if (text != null)
                    {
                        if (name != null)
                        {
                            infos.SetValue(name, new ZString(text));
                        }
                        else
                        {
                            description.Add(text);
                        }
                        text = null;
                    }
                    name = null;
                }
                else
                {
                    //string s2 = TelechargementPlus.TrimString(TelechargementPlus.ExtractTextValues(infos, s));
                    string s2 = TelechargementPlus.TrimFunc1(TelechargementPlus.ExtractTextValues(infos, s));
                    if (infos.ContainsKey("language"))
                    {
                        language = (string)infos["language"];
                        infos.Remove("language");
                    }
                    else if (infos.ContainsKey("size"))
                    {
                        size = (string)infos["size"];
                        infos.Remove("size");
                    }
                    else if (infos.ContainsKey("page_nb"))
                    {
                        nbPages = int.Parse((string)infos["page_nb"]);
                        infos.Remove("page_nb");
                    }
                    //Trace.WriteLine("text \"{0}\" => \"{1}\"", s, s2);
                    bool foundName = false;
                    if (s2.EndsWith(":"))
                    {
                        string s3 = s2.Substring(0, s2.Length - 1).Trim();
                        if (s3 != "")
                        {
                            name      = s3;
                            foundName = true;
                        }
                    }
                    //else if (s2 != "" && s2 != title)
                    if (!foundName && s2 != "" && s2 != title)
                    {
                        if (text == null)
                        {
                            text = s2;
                        }
                        else
                        {
                            text += " " + s2;
                        }
                    }
                }
            }
            if (text != null)
            {
                if (name != null)
                {
                    infos.SetValue(name, new ZString(text));
                }
                else
                {
                    description.Add(text);
                }
            }
        }