Example #1
0
        public void crawl(String title)
        {
            SearchTitle = title;
            List <TitleData> results = getSearchResults2(title, 10);
            TitleData        narrowedResult;

            if (narrowSearch(results, title, out narrowedResult))
            {
                Result = narrowedResult;// Console.WriteLine("Found result: " + title + "--\t" + narrowedResult.Title);
            }
            else
            {
                Console.WriteLine("No result found for " + title);
                if (results.Count > 0)
                {
                    using (SearchResultChoiceForm form = new SearchResultChoiceForm(results, title))
                    {
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            Result = results.ElementAt(form.listIndex % results.Count);
                        }
                    }
                }
            }
        }
Example #2
0
        public Dictionary <String, TitleData> loadWebData()
        {
            Dictionary <String, TitleData> data = new Dictionary <String, TitleData>();

            try
            {
                connection.Open();
                String        sqlString = "select * from WebData";
                SQLiteCommand command   = new SQLiteCommand(sqlString, connection);

                using (SQLiteDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        TitleData item = new TitleData(reader["usertitle"].ToString());
                        item.Title    = reader["title"].ToString();
                        item.Synopsis = reader["synopsis"].ToString();
                        item.ImageURL = reader["image"].ToString();
                        data.Add(item.UserTitle, item);
                    }
                }

                connection.Close();
            }
            catch (SQLiteException e)
            {
                Console.WriteLine(e.Message);
            }
            return(data);
        }
Example #3
0
        public bool narrowSearch(List <TitleData> results, String title, out TitleData result)
        {
            if (title.Contains("Ranpo"))
            {
                ;
            }

            foreach (TitleData data in results)
            {
                String titleTemp   = simpleFileName(data.Title.ToLower());
                String searchTemp  = simpleFileName(title.ToLower());
                String englishTemp = simpleFileName(data.English.ToLower());


                if (titleTemp.Equals(searchTemp) || englishTemp.Equals(searchTemp))
                {
                    result = data;
                    return(true);
                }
                if (levDist(titleTemp, searchTemp) > 90 || levDist(englishTemp, searchTemp) > 90)
                {
                    result = data;
                    return(true);
                }
                foreach (String syn in data.Synonyms)
                {
                    String synTemp = syn.ToLower();

                    if (synTemp.Equals(searchTemp))
                    {
                        result = data;
                        return(true);
                    }
                    if (levDist(synTemp, searchTemp) > 90)
                    {
                        result = data;
                        return(true);
                    }
                }
            }

            if (results.Count == 1)
            {
                result = results.ElementAt(0);
                return(true);
            }

            result = new TitleData(title);
            return(false);
        }
Example #4
0
        private void updateComponents()
        {
            if (searchResults.Count > 0)
            {
                TitleData item = searchResults.ElementAt(listIndex % searchResults.Count);

                pictureBox.ImageLocation = item.ImageURL;
                pictureBox.Load();
                pictureBox.Update();

                titleLabel.Text = item.Title;
                titleLabel.Update();

                descLabel.Text = item.Synopsis;
                descLabel.Update();
            }
        }
Example #5
0
        public List <TitleData> getSearchResults2(String searchTitle, int maxResults)
        {
            String[]         splitTitle    = searchTitle.Split(' ');
            List <TitleData> searchResults = new List <TitleData>();
            int  retryCount      = 0;
            bool requestFinished = false;

            while (!requestFinished && retryCount < 5)
            {
                try
                {
                    String         base64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("Distributor:MALdistro"));
                    HttpWebRequest client = (HttpWebRequest)WebRequest.Create("http://myanimelist.net/api/anime/search.xml?q=" + searchTitle.ToLower());
                    client.ContentType = "application/xml";
                    client.Method      = "GET";
                    client.Headers.Add("Authorization", "Basic " + base64);
                    client.Timeout = 5000;

                    HttpWebResponse response = (HttpWebResponse)client.GetResponse();


                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        StreamReader sr      = new StreamReader(response.GetResponseStream());
                        String       xml     = sr.ReadToEnd();
                        StringReader sreader = new StringReader(xml);
                        using (XmlReader reader = XmlReader.Create(sreader))
                        {
                            String   title, english, type, synopsis, imageURL;
                            String[] synonyms;
                            try
                            {
                                for (int count = 0; count < maxResults && reader.ReadToFollowing("entry");)
                                {
                                    reader.ReadToFollowing("title");
                                    title = reader.ReadElementContentAsString();
                                    TitleData item = new TitleData(title);
                                    if (!title.Equals(""))
                                    {
                                        reader.ReadToFollowing("english");
                                        english = reader.ReadElementContentAsString();

                                        reader.ReadToFollowing("synonyms");
                                        synonyms = reader.ReadElementContentAsString().Split(new[] { "; " }, StringSplitOptions.None);

                                        reader.ReadToFollowing("type");
                                        type = reader.ReadElementContentAsString();

                                        reader.ReadToFollowing("synopsis");
                                        synopsis = reader.ReadElementContentAsString();

                                        reader.ReadToFollowing("image");
                                        imageURL = reader.ReadElementContentAsString();

                                        item.UserTitle = searchTitle;
                                        item.Title     = title;
                                        item.English   = english;
                                        item.Synonyms  = synonyms;
                                        item.Type      = type;
                                        item.Synopsis  = synopsis;
                                        item.ImageURL  = imageURL;

                                        searchResults.Add(item);
                                        //Console.WriteLine(title + "\t" + english + "\t" + type);
                                    }
                                }
                            }
                            catch (XmlException xmlE)
                            {
                                Console.WriteLine(xmlE.Message);
                            }
                        }
                    }
                    response.Close();
                    requestFinished = true;
                }
                catch (WebException e)
                {
                    retryCount++;
                    requestFinished = false;
                    Console.WriteLine("Failed, retrying: " + retryCount);
                    Console.WriteLine(e.Message);
                }
            }

            if (searchResults.Count == 0 && splitTitle.Length > 1)
            {
                return(getSearchResults2(splitTitle[0], 15));
            }

            return(searchResults);
        }