Beispiel #1
0
 static void Main(string[] args)
 {
     string site1 = "http://rutor.org";
     string site2 = "http://opensharing.org";
     string site3 = "http://kinopoisk.ru";
     //Tools.GetURIContent(new Uri(site3));
     //Console.WriteLine(Tools.IsSiteAvailable(site));
     //Film film = new Film("The Wolf of Wall Street");
     //Film film2 = new Film("Железный человек 2", "2010");
     Film film3 = new Film("Титаник");
     TrackerSearch.Search(film3);
     //KinopoiskSearch.GetFilmID("Iron Man", "2013");
     Console.ReadKey();
 }
 //private static readonly Regex TableRegex = new Regex("<table.?*</table>", RegexOptions.Singleline);
 private static List<TrackerTopic> RutorSearch(Film film)
 {
     Uri uri = new Uri("http://rutor.org/search/0/0/300/2/" + film.InfoTable["name"][0] + " BDRemux");
     var htmlCode = Tools.GetURIContent(uri);
     var htmlDoc = new HtmlDocument();
     htmlDoc.LoadHtml(htmlCode);
     var results = htmlDoc.GetElementById("index");
     if (results.InnerText.IndexOf("Результатов поиска") == -1) return null;
     Regex searchResCount = new Regex(@"Результатов поиска \d+");
     var ResCount = searchResCount.Match(results.InnerText);
     if (!ResCount.Success) return null;
     int resultsCount = Convert.ToInt32(ResCount.Value.Substring(ResCount.Value.IndexOf("а ") + 2));
     if (resultsCount == 0)
         return new List<TrackerTopic>();
     //main part
     var magnet_tmp = "";
     var scr_tmp = "";
     var tor_file = "";
     var name_tmp = "";
     var size_tmp = "";
     int found = 0;
     var row = 1;
     List<TrackerTopic> TorFound = new List<TrackerTopic>();
     var table = results.Element("table");
     List<HtmlNode> x = table.Elements("tr").ToList();
     foreach (HtmlNode node in x)
     {
         if (node.Attributes.Contains("class") && node.Attributes["class"].Value == "backgr" ||
             row == 5)
             continue;
         List<HtmlNode> s = node.Elements("td").ToList();
         foreach (HtmlNode item in s)
         {
             switch (row)
             {
                 case 2:
                 {
                     var hrefs = item.Descendants("a").Where(t => t.Attributes.Contains("href")).ToList();
                     magnet_tmp = hrefs[0].Attributes["href"].Value;
                     scr_tmp = "http://rutor.org" + hrefs[1].Attributes["href"].Value;
                     name_tmp = item.InnerText.Replace("&nbsp;", " ").Trim();
                     break;
                 }
                 case 4:
                 case 3: //if there is no comments
                 {
                     Match szMatch = sz.Match(item.InnerText.Replace("&nbsp;", " "));
                     if (szMatch.Success)
                         size_tmp = item.InnerText.Replace("&nbsp;", " ");
                     break;
                 }
             }
             Console.WriteLine(item.InnerText.Replace("&nbsp;", " ")); //DEBUG
             row++;
         }
         if (IsCorrectFilmTorrent(name_tmp, film))
         {
             Regex rutogFilmIdRegex = new Regex(@"/torrent/[\d]+/");
             var rutorFilmIdMatch = rutogFilmIdRegex.Match(scr_tmp);
             var rutorFilmId = "";
             if (rutorFilmIdMatch.Success)
             {
                 rutorFilmId = rutorFilmIdMatch.Value.Substring("/torrent/".Length,
                     rutorFilmIdMatch.Value.Length - "/torrent/".Length - 1);
                 tor_file = "http://d.rutor.org/download/" + rutorFilmId;
                 TorFound.Add(new TrackerTopic(name_tmp, scr_tmp, tor_file, size_tmp, magnet_tmp));
                 found++;
                 scr_tmp = name_tmp = size_tmp = tor_file = magnet_tmp = "";
             }
         }
         row = 1;
         if (found >= Settings.MAX_SEARCH_RESULT)
             break;
         Console.WriteLine("-------"); //DEBUG
     }
     return TorFound;
 }
 private static bool IsCorrectFilmTorrent(string name, Film film)
 {
     return (name.Contains(film.InfoTable["name"][0]) && name.Contains(film.InfoTable["year"][0]));
 }
 public static List<TrackerTopic> Search(Film film)
 {
     return RutorSearch(film);
 }
 private static void SetPosterInfo(Film film)
 {
     film.InfoTable.Add("poster", new List<string>()
     {
         "www.kinopoisk.ru/images/film_big/" + film.Id + ".jpg",
         "www.kinopoisk.ru/images/film/" + film.Id + ".jpg"
     });
 }
 private static void ParseInfoTable(string htmlCode, Film film)
 {
     var htmlDoc = new HtmlDocument();
     htmlDoc.LoadHtml(htmlCode);
     var names = htmlDoc.GetElementById("headerFilm");
     if (names == null) return;
     var _names = names.Descendants()
         .Where(t => t.Attributes.Contains("itemprop")).ToArray();
     film.InfoTable.Add("name",
         new List<string>()
         {
             MakeValueClear(_names[0].InnerText),
             MakeValueClear(_names[1].InnerText)
         });
     SetPosterInfo(film);
     var table = htmlDoc.GetElementById("infoTable");
     ClearHTMLCode(table);
     table = table.Element("table");
     string tmp = "";
     bool key = true;
     string cur_key = "";
     List<HtmlNode> x = table.Elements("tr").ToList();
     foreach (HtmlNode node in x)
     {
         List<HtmlNode> s = node.Elements("td").ToList();
         foreach (HtmlNode item in s)
         {
             tmp = MakeValueClear(item.InnerText);
             if (!String.IsNullOrWhiteSpace(tmp))
             {
                 if (key && Constants.KeyWords.ContainsKey(tmp))
                 {
                     film.InfoTable.Add(Constants.KeyWords[tmp], new List<string>());
                     cur_key = tmp;
                     key = false;
                 }
                 else
                 {
                     if (!key)
                     {
                         if (cur_key != "слоган")
                         {
                             var Arr_tmp = tmp.Split(',');
                             foreach (var i in Arr_tmp)
                             {
                                 film.InfoTable[Constants.KeyWords[cur_key]].Add(i.Trim());
                             }
                         }
                         else
                             film.InfoTable[Constants.KeyWords[cur_key]].Add(tmp);
                     }
                 }
             }
             Console.WriteLine(tmp); //DEBUG
         }
         Console.WriteLine("-------"); //DEBUG
         key = true;
     }
     //Console.ReadKey();
 }
 public static void GetFilmInfo(Film film)
 {
     if (film.Id == -1)
         return;
     var uri = new Uri("http://www.kinopoisk.ru/film/" + Convert.ToString(film.Id) + '/');
     string HTMLCode = Tools.GetURIContent(uri);
     ParseInfoTable(HTMLCode, film);
 }