static void Main(string[] args) { var tpb = new Tpb(); Console.Title = "TPB Crawler"; while (true) { Console.Clear(); Console.Write("Search query: "); var query = new Query(Console.ReadLine()); query.Category = TorrentCategory.AllGames; var searchResults = tpb.Search(query); Console.Clear(); searchResults = searchResults.OrderByDescending(r => r.IsVip).ThenByDescending(r => r.IsTrusted).ThenByDescending(r => r.Uploaded).ToList(); int index = 1; foreach (var res in searchResults) { if (res.IsVip) { Console.ForegroundColor = ConsoleColor.Green; } if (res.IsTrusted) { Console.ForegroundColor = ConsoleColor.Magenta; } Console.WriteLine($"[{index}] [{res.Uploaded.ToString("dd-MM-yyyy")}] [{Math.Round((double)res.SizeBytes / 1073741824.0, 2)} GB] {res.Name}"); Console.ForegroundColor = ConsoleColor.Gray; System.Threading.Thread.Sleep(20); index++; } Console.ReadKey(); } }
void SearchTorrents(string searchname, string category, int searchPage) { int intRetryCounter = 0; startSearch: try { Query q = new Query(searchname.Trim(), searchPage, getTorrentCategory(category)); Debug.WriteLine("URL: " + q.TranslateToUrl()); writeToLog(DateTime.Now + ": Searching for torrent at: '" + q.TranslateToUrl() + "'"); sr = new frmSearchResults(Tpb.Search(q).ToList()); BeginInvoke((MethodInvoker) delegate() { if (pnlDelayed.Visible) { pnlDelayed.Visible = false; } this.Visible = false; writeToLog(" Searching took " + currentSearchTime + " ms."); }); sr.ShowDialog(); } catch (WebException e) { intRetryCounter++; if (intRetryCounter < 3) { BeginInvoke((MethodInvoker) delegate() { if (!pnlDelayed.Visible) { pnlDelayed.Visible = true; } }); goto startSearch; } writeToLog(Environment.NewLine + DateTime.Now + ":" + Environment.NewLine + "Network error while searching for torrent: " + Environment.NewLine + e.ToString() + Environment.NewLine); MessageBox.Show("Network error. " + Environment.NewLine + "Retrying 3 times failed." + Environment.NewLine + "Check the log for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); BeginInvoke((MethodInvoker) delegate() { if (pnlDelayed.Visible) { pnlDelayed.Visible = false; } }); } catch (Exception ee) { writeToLog(Environment.NewLine + DateTime.Now + ":" + Environment.NewLine + "System error while searching for torrent: " + Environment.NewLine + ee.ToString() + Environment.NewLine); MessageBox.Show("System error. " + Environment.NewLine + "Check the log for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); BeginInvoke((MethodInvoker) delegate() { if (pnlDelayed.Visible) { pnlDelayed.Visible = false; } }); } }
/// <summary> /// Finds the torrents. /// </summary> /// <param name="searchQuery">The search query.</param> /// <param name="page">The page.</param> /// <param name="category">The category.</param> /// <returns>Task<ResponseContainer<SearchResult>>.</returns> public IEnumerable <Torrent> FindTorrents(string searchQuery, int page, string category) { var cat = 0; switch (category) { case "Applications": cat = TorrentCategory.AllApplication; break; case "Music": cat = TorrentCategory.Audio.Music; break; case "Movies": cat = TorrentCategory.Video.Movies; break; case "Games": cat = TorrentCategory.AllGames; break; case "Other": cat = TorrentCategory.AllOther; break; case "TV": cat = TorrentCategory.Video.TVshows; break; case "XXX": cat = TorrentCategory.AllPorn; break; default: cat = TorrentCategory.All; break; } //TODO!! Fix setting for queryorder var results = Tpb.Search(new Query(searchQuery, page, cat, QueryOrder.BySeeds)); return(results); }
static void Main(string[] args) { IEnumerable <Torrent> torrents = Tpb.Search(new Query("frozen", 0, QueryOrder.BySeeds)); }