Beispiel #1
0
        public void Search(string text)
        {
            text = Helpers.RemoveDiacritics(text); // API doesn't like accented characters

            // http://www.thetvdb.com/api/GetSeries.php?seriesname=prison
            // by default, english only.  add &language=all

            bool isNumber = Regex.Match(text, "^[0-9]+$").Success;

            if (isNumber)
            {
                this.DownloadSeriesNow(int.Parse(text), false);
            }

            // but, the number could also be a name, so continue searching as usual
            text = text.Replace(".", " ");

            byte[] p = this.GetPage("GetSeries.php?seriesname=" + text + "&language=all", false, typeMaskBits.tmXML, true);

            if (p == null)
            {
                return;
            }

            MemoryStream ms = new MemoryStream(p);

            this.ProcessTVDBResponse(ms, null);
        }
Beispiel #2
0
 public static string CompareName(string n)
 {
     //TODO consider whether merge with above
     n = Helpers.RemoveDiacritics(n);
     n = Regex.Replace(n, "[^\\w ]", "");
     return(SimplifyName(n));
 }
Beispiel #3
0
        private void DoFind(bool chooseOnlyMatch)
        {
            if (this.mInternal)
            {
                return;
            }

            this.lvMatches.BeginUpdate();

            string what = this.txtFindThis.Text;

            what = Helpers.RemoveDiacritics(what);
            what = what.Replace(".", " ");

            this.lvMatches.Items.Clear();
            if (!string.IsNullOrEmpty(what))
            {
                what = what.ToLower();

                bool numeric  = Regex.Match(what, "^[0-9]+$").Success;
                int  matchnum = 0;
                try
                {
                    matchnum = numeric ? int.Parse(what) : -1;
                }
                catch (OverflowException)
                {
                }

                what = Helpers.RemoveDiacritics(what);

                if (!this.mTVDB.GetLock("DoFind"))
                {
                    return;
                }

                foreach (KeyValuePair <int, SeriesInfo> kvp in this.mTVDB.GetSeriesDict())
                {
                    int    num  = kvp.Key;
                    string show = kvp.Value.Name;
                    show = Helpers.RemoveDiacritics(show);
                    string s = num + " " + show;

                    string simpleS = Regex.Replace(s.ToLower(), "[^\\w ]", "");

                    bool numberMatch = numeric && num == matchnum;

                    if (numberMatch || (!numeric && (simpleS.Contains(Regex.Replace(what, "[^\\w ]", "")))) || (numeric && show.Contains(what)))
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = num.ToString();
                        lvi.SubItems.Add(show);
                        lvi.SubItems.Add(kvp.Value.FirstAired != null ? kvp.Value.FirstAired.Value.Year.ToString() : "");

                        lvi.Tag = num;
                        if (numberMatch)
                        {
                            lvi.Selected = true;
                        }
                        this.lvMatches.Items.Add(lvi);
                    }
                }
                this.mTVDB.Unlock("DoFind");

                if ((this.lvMatches.Items.Count == 1) && numeric)
                {
                    this.lvMatches.Items[0].Selected = true;
                }

                int n = this.lvMatches.Items.Count;
                this.txtSearchStatus.Text = "Found " + n + " show" + ((n != 1) ? "s" : "");
            }
            else
            {
                this.txtSearchStatus.Text = "";
            }

            this.lvMatches.EndUpdate();

            if ((this.lvMatches.Items.Count == 1) && chooseOnlyMatch)
            {
                this.lvMatches.Items[0].Selected = true;
            }
        }