public override List <TvEpisodeTorrent> GetAvailableTvTorrents(TvEpisode episode) { // Download show episodes page string showPageUrl = BASE_URL + "/search/" + episode.BuildEpString().Replace(" ", "%20"); Limiter.DoWait(); WebClient client = new WebClient(); client.Headers.Add("User-Agent: Other"); string data = client.DownloadString(showPageUrl); Regex baseRegex = new Regex("<div\\s+class=\\\"detName\\\">\\s+<a\\s+href=\\\"[^\\\"]+\\\"[^>]+>([^>]+)</a>\\s+</div>\\s+<a href=\\\"(magnet:[^\\\"]+)\\\""); MatchCollection matches = baseRegex.Matches(data); List <TvEpisodeTorrent> torrents = new List <TvEpisodeTorrent>(); foreach (Match match in matches) { string name = match.Groups[1].Value; string magnet = match.Groups[2].Value; MatchCollection showMatches = episode.Show.MatchFileToContent(name); bool matchShow = showMatches != null && showMatches.Count > 0; int season, ep1, ep2; if (matchShow && FileHelper.GetEpisodeInfo(name, episode.Show.DisplayName, out season, out ep1, out ep2, true) && episode.Season == season && episode.DisplayNumber == ep1) { // Don't want to get torrent with a bunch of episodes (double is okay) if (ep2 > 0 && ep2 - ep1 > 1) { continue; } TorrentQuality quality = TorrentQuality.Sd480p; if (name.ToLower().Contains("720p")) { quality = TorrentQuality.Hd720p; } else if (name.ToLower().Contains("1080p")) { quality = TorrentQuality.Hd1080p; } TvEpisodeTorrent torrentEp = new TvEpisodeTorrent(); torrentEp.Url = showPageUrl; torrentEp.Season = season; torrentEp.Episode = ep1; torrentEp.Episode2 = ep2; torrentEp.Quality = quality; torrentEp.Title = name; torrentEp.Magnet = magnet; torrents.Add(torrentEp); } } return(torrents); }
public void Clone(GeneralSettings settings) { this.NumProcessingThreads = settings.NumProcessingThreads; this.NumSimultaneousSearches = settings.NumSimultaneousSearches; this.DefaultMovieDatabase = settings.DefaultMovieDatabase; this.DefaultTvDatabase = settings.DefaultTvDatabase; this.TorrentDirectory = settings.TorrentDirectory; this.PreferredTorrentQuality = settings.PreferredTorrentQuality; this.TorrentDownload = settings.TorrentDownload; }
/// <summary> /// Searches 1337x.to for a single torrent with specified quality. Use with causion - you might get banned /// </summary> /// <param name="series">Series to search for</param> /// <param name="episode">Episode to search for</param> /// <param name="quality">Quality to search for</param> /// <returns>The one with most seeders</returns> public async static Task <Torrent> SearchSingle(Series series, Episode episode, TorrentQuality quality) { var tor = await Search(series, episode); if (tor != null) { return(tor.Where(x => x.Quality == quality).OrderByDescending(x => x.Seeders).FirstOrDefault()); } return(null); }
/// <summary> /// Searches 1337x.to for torrents with specified quality. Use with causion - you might get banned /// </summary> /// <param name="series">Series to search for</param> /// <param name="episode">Episode to search for</param> /// <param name="quality">Quality to search for</param> /// <returns></returns> public async static Task <List <Torrent> > Search(Series series, Episode episode, TorrentQuality quality) { return((await Search(series, episode))?.Where(x => x.Quality == quality).ToList()); }
public TvEpisodeTorrent GetBestTvTorrent(TvEpisode episode) { List <TvEpisodeTorrent> availableTorrents = GetAvailableTvTorrents(episode); if (availableTorrents.Count == 0) { return(null); } Dictionary <TorrentQuality, TvEpisodeTorrent> qualityTorrents = new Dictionary <TorrentQuality, TvEpisodeTorrent>(); foreach (TvEpisodeTorrent torrent in availableTorrents) { TorrentQuality quality = torrent.Quality; if (!qualityTorrents.ContainsKey(quality)) { qualityTorrents.Add(quality, null); } if (qualityTorrents[quality] == null) { qualityTorrents[quality] = torrent; } } // Go through matches to find closest quality to preferred TorrentQuality closestQuality = TorrentQuality.Sd480p; if (qualityTorrents.ContainsKey(Settings.General.PreferredTorrentQuality)) { closestQuality = Settings.General.PreferredTorrentQuality; } else { switch (Settings.General.PreferredTorrentQuality) { case TorrentQuality.Sd480p: if (qualityTorrents.ContainsKey(TorrentQuality.Hd720p)) { closestQuality = TorrentQuality.Hd720p; } else { closestQuality = TorrentQuality.Hd1080p; } break; case TorrentQuality.Hd720p: if (qualityTorrents.ContainsKey(TorrentQuality.Sd480p)) { closestQuality = TorrentQuality.Sd480p; } else { closestQuality = TorrentQuality.Hd1080p; } break; case TorrentQuality.Hd1080p: if (qualityTorrents.ContainsKey(TorrentQuality.Hd720p)) { closestQuality = TorrentQuality.Hd720p; } else { closestQuality = TorrentQuality.Sd480p; } break; default: throw new Exception("Unknown torrent quality"); } } TvEpisodeTorrent closestTorrent = qualityTorrents[closestQuality]; UpdateTorrentLinks(closestTorrent); return(closestTorrent); }
/// <summary> /// Loads instance properties from XML. /// </summary> /// <param name="itemNode">Node to load XML from</param> /// <returns>true if sucessfully loaded from XML</returns> public bool Load(XmlNode fileNameNode) { // Loop through sub-nodes foreach (XmlNode propNode in fileNameNode.ChildNodes) { // Get element/property type XmlElements element;; if (!Enum.TryParse <XmlElements>(propNode.Name, out element)) { continue; } // Get value string string value = propNode.InnerText; // Load value into appropriate property switch (element) { case XmlElements.NumProcessingThreads: int numProc; if (int.TryParse(value, out numProc)) { this.NumProcessingThreads = numProc; } break; case XmlElements.NumSimultaneousSearches: int numSearch; if (int.TryParse(value, out numSearch)) { this.NumSimultaneousSearches = numSearch; } break; case XmlElements.DefaultMovieDatabase: MovieDatabaseSelection movieDb; if (Enum.TryParse <MovieDatabaseSelection>(value, out movieDb)) { this.DefaultMovieDatabase = movieDb; } break; case XmlElements.DefaultTvDatabase: TvDataBaseSelection tvDb; if (Enum.TryParse <TvDataBaseSelection>(value, out tvDb)) { this.DefaultTvDatabase = tvDb; } break; case XmlElements.TorrentDirectory: this.TorrentDirectory = value; break; case XmlElements.PreferredTorrentQuality: TorrentQuality torrentQual; if (Enum.TryParse <TorrentQuality>(value, out torrentQual)) { this.PreferredTorrentQuality = torrentQual; } break; case XmlElements.TorrentDownload: TorrentDownload torrentDwnld; if (Enum.TryParse <TorrentDownload>(value, out torrentDwnld)) { this.TorrentDownload = torrentDwnld; } break; } } // Success return(true); }
public override List <TvEpisodeTorrent> GetAvailableTvTorrents(TvEpisode episode) { // Download show episodes page string showPageUrl = BASE_URL + "/torrents.php?search=" + episode.BuildEpString().Replace(" ", "+"); Console.WriteLine("RARBG Pre " + DateTime.Now.ToString()); Limiter.DoWait(); Console.WriteLine("RARBG Post " + DateTime.Now.ToString()); WebClient client = new WebClient(); client.Headers.Add("User-Agent: Other"); string data = client.DownloadString(showPageUrl); Regex baseRegex = new Regex(@"<tr\s+class=.lista2.>\s*(<td.*?/td>)\s*(<td.*?/td>)\s*(<td.*?/td>)\s*(<td.*?/td>)\s*(<td.*?/td>)\s*(<td.*?/td>)\s*(<td.*?/td>)\s*</tr>"); Regex titleRegex = new Regex(@"title=""([^""]+)"""); Regex urlRegex = new Regex("href=\"(/torrent/[^\"]+)\""); Regex sizeRegex = new Regex(@">(\S+)\s+MB<"); MatchCollection matches = baseRegex.Matches(data); List <TvEpisodeTorrent> torrents = new List <TvEpisodeTorrent>(); foreach (Match match in matches) { string name; Match titleMatch = titleRegex.Match(match.Groups[2].Value); if (titleMatch.Success) { name = titleMatch.Groups[1].Value; } else { continue; } string pageUrl; Match urlMatch = urlRegex.Match(match.Groups[2].Value); if (urlMatch.Success) { pageUrl = BASE_URL + urlMatch.Groups[1].Value; } else { continue; } MatchCollection showMatches = episode.Show.MatchFileToContent(name); bool matchShow = showMatches != null && showMatches.Count > 0; int season, ep1, ep2; if (matchShow && FileHelper.GetEpisodeInfo(name, episode.Show.DisplayName, out season, out ep1, out ep2, true) && episode.Season == season && episode.DisplayNumber == ep1) { // Don't want to get torrent with a bunch of episodes (double is okay) if (ep2 > 0 && ep2 - ep1 > 1) { continue; } TorrentQuality quality = TorrentQuality.Sd480p; if (name.ToLower().Contains("720p")) { quality = TorrentQuality.Hd720p; } else if (name.ToLower().Contains("1080p")) { quality = TorrentQuality.Hd1080p; } TvEpisodeTorrent torrentEp = new TvEpisodeTorrent(); torrentEp.Url = showPageUrl; torrentEp.Season = season; torrentEp.Episode = ep1; torrentEp.Episode2 = ep2; torrentEp.Quality = quality; torrentEp.Title = name; torrentEp.PageUrl = pageUrl; torrents.Add(torrentEp); } } return(torrents); }