public FriendlyTorrentFileInfo(TransmissionTorrentFiles torrentFile, TorrentInfo parentTorrent) { this.InitialPath = torrentFile.Name; this.NewestName = InitialPath; this.TorrentFile = torrentFile; this.ParentTorrent = parentTorrent; }
private void 开始搜索_Click(object sender, EventArgs e) { new TaskFactory().StartNew(async() => { var conn = new SQLiteConnection(@"data source=.\Nyaa"); conn.Open(); var cmd = new SQLiteCommand(conn); cmd.CommandText = @"select * from NyaaDB where Name like '%" + 搜索字符.Text + "%'"; var read = await cmd.ExecuteReaderAsync(); if (read.HasRows) { List <TorrentInfo> sa = new List <TorrentInfo>(); while (read.Read()) { TorrentInfo Temp = new TorrentInfo(); Temp.Class = read.GetString(0); Temp.Catagory = read.GetString(1); Temp.Address = read.GetString(2); Temp.Name = read.GetString(3); Temp.Torrent = read.GetString(4); Temp.Magnet = read.GetString(5); Temp.Size = read.GetString(6); Temp.Date = read.GetDateTime(7); Temp.Up = read.GetString(8); Temp.Leeches = read.GetString(9); Temp.Complete = read.GetString(10); sa.Add(Temp); } BeginInvoke(new Action(() => { 主窗口.AddContent(new Document(搜索字符.Text, sa)); })); } }); }
public void ParsesCreationDateFromFile() { TorrentInfo torrentInfo = ReadAndParsetorrentInfo(TestFiles.ProjectEuler); Assert.Equal(1558810233, torrentInfo.CreationTimeStamp); Assert.Equal(new DateTime(2019, 5, 25, 18, 50, 33), torrentInfo.CreationDate); }
public void ParsesCorrectVersions(string torrentInfoName, bool v1, bool v2) { TorrentInfo torrentInfo = ReadAndParsetorrentInfo(torrentInfoName); Assert.Equal(v1, torrentInfo.Version.HasFlag(BitTorrentVersion.V1)); Assert.Equal(v2, torrentInfo.Version.HasFlag(BitTorrentVersion.V2)); }
public void should_prefer_first_release_if_peers_and_size_are_too_similar() { var remoteMovie1 = GivenRemoteMovie(new QualityModel(Quality.HDTV720p)); var remoteMovie2 = GivenRemoteMovie(new QualityModel(Quality.HDTV720p)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 1000; torrentInfo1.Peers = 10; torrentInfo1.Size = 200.Megabytes(); var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 1100; torrentInfo2.Peers = 10; torrentInfo1.Size = 250.Megabytes(); remoteMovie1.Release = torrentInfo1; remoteMovie1.Release.Title = "A Movie 1998"; remoteMovie2.Release = torrentInfo2; remoteMovie2.Release.Title = "A Movie 1998"; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteMovie1)); decisions.Add(new DownloadDecision(remoteMovie2)); var qualifiedReports = Subject.PrioritizeDecisionsForMovies(decisions); ((TorrentInfo)qualifiedReports.First().RemoteMovie.Release).Should().Be(torrentInfo1); }
public void LoadTorrent(string filename) { if (!Directory.Exists(torrentDir)) { Directory.CreateDirectory(torrentDir); } try { TorrentInfo info = new TorrentInfo(filename); string torrentFileName = Path.Combine(torrentDir, info.Name + ".torrent"); File.Copy(filename, torrentFileName, true); var result = from t in Torrents where t.InfoHash == info.InfoHash select t; if (result == null || result.Count() == 0) { var addParams = new AddTorrentParams { SavePath = Properties.Settings.Default.Location, TorrentInfo = info }; var torrent = Torrent.Create(addParams, session); torrent.TorrentFileName = torrentFileName; AddTorrent(torrent); } else { Error?.Invoke(this, "This torrent already exists"); } } catch { Error?.Invoke(this, "Error parsing file"); } }
public MetricsTorrent(TorrentInfo trackedTorrent, CLOptions options) { TorrentName = trackedTorrent.Name; Hash = trackedTorrent.Hash; this.options = options; TorrentDeleted = false; }
public void TorrentInfo_UbuntuFile() { TorrentInfo torrentFile = new TorrentInfo(); torrentFile.Announce = "http://torrent.ubuntu.com:6969/announce"; torrentFile.Comment = "Ubuntu CD releases.ubuntu.com"; torrentFile.PieceLength = 524288; torrentFile.AnnounceList = new System.Collections.Generic.List <string> { "http://torrent.ubuntu.com:6969/announce", "http://ipv6.torrent.ubuntu.com:6969/announce" }; torrentFile.Files = new System.Collections.Generic.List <(string, long)> { ("ubuntu-19.04-desktop-amd64.iso", 2097152000) }; BencodeParser parser = new BencodeParser(_ubuntuFIlePath); TorrentInfo expectedTorrentFile = parser.GetTorrentInfo(); torrentFile.InfoHash = new Sha1Encryptor().GetHash(parser.ReadInfoValue()); Assert.AreEqual(expectedTorrentFile.Announce, torrentFile.Announce); Assert.AreEqual(expectedTorrentFile.Comment, torrentFile.Comment); Assert.AreEqual(expectedTorrentFile.PieceLength, torrentFile.PieceLength); CollectionAssert.AreEqual(expectedTorrentFile.AnnounceList, torrentFile.AnnounceList); CollectionAssert.AreEqual(expectedTorrentFile.Files, expectedTorrentFile.Files); }
public void TorrentInfo_ViyFile() { TorrentInfo torrentFile = new TorrentInfo(); torrentFile.Announce = "http://bt4.rutracker.org/ann?uk=wa36F12BA3"; torrentFile.Comment = "http://rutracker.org/forum/viewtopic.php?t=4390356"; torrentFile.PieceLength = 262144; torrentFile.AnnounceList = new System.Collections.Generic.List <string> { "http://bt4.rutracker.org/ann?uk=wa36F12BA3", "http://retracker.local/announce" }; torrentFile.Files = new System.Collections.Generic.List <(string, long)> { ("Soft7/DirectX14/dxwebsetup.exe", 299864), ("Soft6/Redist16/vcredist_x86.exe", 4995416), ("Soft6/Redist16/vcredist_x64.exe", 4877648), ("Data.bin", 180935132), ("Setup.exe", 7389257), ("Survivors Viy.ico", 118921), ("autorun.inf", 70), }; BencodeParser parser = new BencodeParser(_viyFilePath); TorrentInfo expectedTorrentFile = parser.GetTorrentInfo(); torrentFile.InfoHash = new Sha1Encryptor().GetHash(parser.ReadInfoValue()); Assert.AreEqual(expectedTorrentFile.Announce, torrentFile.Announce); Assert.AreEqual(expectedTorrentFile.Comment, torrentFile.Comment); Assert.AreEqual(expectedTorrentFile.PieceLength, torrentFile.PieceLength); CollectionAssert.AreEqual(expectedTorrentFile.AnnounceList, torrentFile.AnnounceList); CollectionAssert.AreEqual(expectedTorrentFile.Files, expectedTorrentFile.Files); }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var results = new List <ReleaseInfo>(); switch (indexerResponse.HttpResponse.StatusCode) { default: if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode); } break; } var jsonResponse = new HttpResponse <TorrentPotatoResponse>(indexerResponse.HttpResponse); foreach (var torrent in jsonResponse.Resource.results) { var torrentInfo = new TorrentInfo(); torrentInfo.Guid = GetGuid(torrent); torrentInfo.Title = torrent.release_name; torrentInfo.Size = (long)torrent.size * 1000 * 1000; torrentInfo.DownloadUrl = torrent.download_url; torrentInfo.InfoUrl = torrent.details_url; torrentInfo.PublishDate = torrent.publish_date.ToUniversalTime(); torrentInfo.Seeders = torrent.seeders; torrentInfo.Peers = torrent.leechers + torrent.seeders; torrentInfo.Freeleech = torrent.freeleech; results.Add(torrentInfo); } return(results); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TorrentInfo.TryLoad(@".\..\..\Test\TorrentClientTest.Data\TorrentFile.torrent", out torrent); torrentClient = new TorrentClient.TorrentClient(4000, @".\Test"); // listening port, base torrent data directory torrentClient.DownloadSpeedLimit = 100 * 1024; // 100 KB/s torrentClient.UploadSpeedLimit = 200 * 1024; // 200 KB/s torrentClient.TorrentHashing += TorrentClient_TorrentHashing; torrentClient.TorrentLeeching += TorrentClient_TorrentLeeching; torrentClient.TorrentSeeding += TorrentClient_TorrentSeeding; torrentClient.TorrentStarted += TorrentClient_TorrentStarted; torrentClient.TorrentStopped += TorrentClient_TorrentStopped; torrentClient.Start(); // start torrent client torrentClient.Start(torrent); // start torrent file // setup checkout timer var timer = new System.Timers.Timer(); timer.Interval = 10000; timer.Elapsed += Timer_Elapsed; timer.Enabled = true; timer.Start(); Thread.Sleep(10000000); }
public void should_prefer_releases_with_more_peers_no_seeds() { var remoteEpisode1 = GivenRemoteEpisode(new List <Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p)); var remoteEpisode2 = GivenRemoteEpisode(new List <Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.Size = 0; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 0; torrentInfo1.Peers = 10; var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 0; torrentInfo2.Peers = 100; remoteEpisode1.Release = torrentInfo1; remoteEpisode2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteEpisode1)); decisions.Add(new DownloadDecision(remoteEpisode2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteEpisode.Release).Peers.Should().Be(torrentInfo2.Peers); }
public void should_prefer_quality_over_the_number_of_peers() { var remoteEpisode1 = GivenRemoteEpisode(new List <Episode> { GivenEpisode(1) }, new QualityModel(Quality.Bluray1080p)); var remoteEpisode2 = GivenRemoteEpisode(new List <Episode> { GivenEpisode(1) }, new QualityModel(Quality.SDTV)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 100; torrentInfo1.Peers = 10; torrentInfo1.Size = 200.Megabytes(); var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 1100; torrentInfo2.Peers = 10; torrentInfo1.Size = 250.Megabytes(); remoteEpisode1.Release = torrentInfo1; remoteEpisode2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteEpisode1)); decisions.Add(new DownloadDecision(remoteEpisode2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteEpisode.Release).Should().Be(torrentInfo1); }
public static ReleaseInfo ToModel(this ReleaseResource resource) { ReleaseInfo model; if (resource.Protocol == DownloadProtocol.Torrent) { model = new TorrentInfo { MagnetUrl = resource.MagnetUrl, InfoHash = resource.InfoHash, Seeders = resource.Seeders, Peers = (resource.Seeders.HasValue && resource.Leechers.HasValue) ? (resource.Seeders + resource.Leechers) : null }; } else { model = new ReleaseInfo(); } model.Guid = resource.Guid; model.Title = resource.Title; model.Size = resource.Size; model.DownloadUrl = resource.DownloadUrl; model.InfoUrl = resource.InfoUrl; model.CommentUrl = resource.CommentUrl; model.IndexerId = resource.IndexerId; model.Indexer = resource.Indexer; model.DownloadProtocol = resource.DownloadProtocol; model.TvdbId = resource.TvdbId; model.TvRageId = resource.TvRageId; model.PublishDate = resource.PublishDate; return(model); }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var results = new List <ReleaseInfo>(); switch (indexerResponse.HttpResponse.StatusCode) { case HttpStatusCode.Unauthorized: throw new ApiKeyException("API Key invalid or not authorized"); case HttpStatusCode.NotFound: throw new IndexerException(indexerResponse, "Indexer API call returned NotFound, the Indexer API may have changed."); case HttpStatusCode.ServiceUnavailable: throw new RequestLimitReachedException("Cannot do more than 150 API requests per hour."); default: if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK) { throw new IndexerException(indexerResponse, "Indexer API call returned an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode); } break; } var jsonResponse = new HttpResponse <JsonRpcResponse <BroadcastheNetTorrents> >(indexerResponse.HttpResponse).Resource; if (jsonResponse.Error != null || jsonResponse.Result == null) { throw new IndexerException(indexerResponse, "Indexer API call returned an error [{0}]", jsonResponse.Error); } if (jsonResponse.Result.Results == 0) { return(results); } foreach (var torrent in jsonResponse.Result.Torrents.Values) { var torrentInfo = new TorrentInfo(); torrentInfo.Guid = String.Format("BTN-{0}", torrent.TorrentID); torrentInfo.Title = torrent.ReleaseName; torrentInfo.Size = torrent.Size; torrentInfo.DownloadUrl = torrent.DownloadURL; torrentInfo.InfoUrl = String.Format("https://broadcasthe.net/torrents.php?id={0}&torrentid={1}", torrent.GroupID, torrent.TorrentID); //torrentInfo.CommentUrl = if (torrent.TvrageID.HasValue) { torrentInfo.TvRageId = torrent.TvrageID.Value; } torrentInfo.PublishDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime().AddSeconds(torrent.Time); //torrentInfo.MagnetUrl = torrentInfo.InfoHash = torrent.InfoHash; torrentInfo.Seeders = torrent.Seeders; torrentInfo.Peers = torrent.Leechers + torrent.Seeders; results.Add(torrentInfo); } return(results); }
public void should_prefer_releases_with_more_peers_given_equal_number_of_seeds() { var remoteMovie1 = GivenRemoteMovie(new QualityModel(Quality.HDTV720p)); var remoteMovie2 = GivenRemoteMovie(new QualityModel(Quality.HDTV720p)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.Size = 0; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 10; torrentInfo1.Peers = 10; var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Peers = 100; remoteMovie1.Release = torrentInfo1; remoteMovie1.Release.Title = "A Movie 1998"; remoteMovie2.Release = torrentInfo2; remoteMovie2.Release.Title = "A Movie 1998"; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteMovie1)); decisions.Add(new DownloadDecision(remoteMovie2)); var qualifiedReports = Subject.PrioritizeDecisionsForMovies(decisions); ((TorrentInfo)qualifiedReports.First().RemoteMovie.Release).Peers.Should().Be(torrentInfo2.Peers); }
private IList <TorrentInfo> ParseRelease(IndexerResponse indexerResponse) { var torrentInfos = new List <TorrentInfo>(); var parser = new HtmlParser(); var dom = parser.ParseDocument(indexerResponse.Content); foreach (var t in dom.QuerySelectorAll("#tabs .torrent_c > div")) { var release = new TorrentInfo { Title = GetTitle(dom, t), InfoUrl = indexerResponse.Request.Url.ToString(), DownloadVolumeFactor = 0, UploadVolumeFactor = 1, Guid = indexerResponse.Request.Url.ToString() + t.Id, Seeders = GetReleaseSeeders(t), Peers = GetReleaseSeeders(t) + GetReleaseLeechers(t), Grabs = GetReleaseGrabs(t), Categories = ParseCategories(indexerResponse.Request.Url.Path), PublishDate = GetDateFromShowPage(dom), DownloadUrl = GetReleaseLink(t), Size = GetReleaseSize(t), Resolution = GetQuality(t) }; torrentInfos.Add(release); } return(torrentInfos); }
public void should_prefer_releases_with_more_seeders() { var remoteBook1 = GivenRemoteBook(new List <Book> { GivenBook(1) }, new QualityModel(Quality.MP3_320)); var remoteBook2 = GivenRemoteBook(new List <Book> { GivenBook(1) }, new QualityModel(Quality.MP3_320)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.Size = 0; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 10; var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 100; remoteBook1.Release = torrentInfo1; remoteBook2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteBook1)); decisions.Add(new DownloadDecision(remoteBook2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteBook.Release).Seeders.Should().Be(torrentInfo2.Seeders); }
public async void TorrentChanged(ListView obj, TorrentInfo inf) { try { SelectedTorrents = obj.SelectedItems.Cast <TorrentInfo>().ToArray(); _moreInfoCancelTokeSource?.Cancel(); _moreInfoCancelTokeSource = new CancellationTokenSource(); await Task.Delay(250, _moreInfoCancelTokeSource.Token); if (_moreInfoCancelTokeSource.Token.IsCancellationRequested) { return; } selectedIDs = SelectedTorrents.Select(x => x.Id).ToArray(); if (ConfigService.Instanse.MoreInfoShow) { UpdateMoreInfoPosition(SelectedTorrents.Any()); UpdateMoreInfoView(_moreInfoCancelTokeSource.Token); } } catch (TaskCanceledException) { } }
private void refreshTorrentOptions() { // Written, 17.09.2020 if (this.movies_listView.SelectedItems.Count == 1) { if (this.torrents_listView.SelectedItems.Count == 1) { MovieInfo selectedInfo = this.movies_listView.SelectedItems[0].Tag as MovieInfo; TorrentInfo selectedTorrentInfo = this.torrents_listView.SelectedItems[0].Tag as TorrentInfo; this.startDownload_button.Text = String.Format("Download: {0} in {1}", selectedInfo.title, selectedTorrentInfo.quality); this.startDownload_button.Enabled = true; } else { this.startDownload_button.Text = "Download"; this.startDownload_button.Enabled = false; } } else { this.torrents_listView.Items.Clear(); } }
private void refreshTorrentListView() { // Written, 17.09.2020 if (this.movies_listView.SelectedItems.Count == 1) { MovieInfo selectedInfo = this.movies_listView.SelectedItems[0].Tag as MovieInfo; if (selectedInfo != null) { for (int i = 0; i < selectedInfo.torrents.Length; i++) { TorrentInfo torrentInfo = selectedInfo.torrents[i]; string[] subItems = new string[] { String.Format("{0} ({1})", torrentInfo.type, torrentInfo.quality), torrentInfo.size, torrentInfo.date_uploaded.ToString(), torrentInfo.seeds.ToString(), torrentInfo.peers.ToString(), torrentInfo.hash }; this.torrents_listView.Items.Add(new ListViewItem(subItems) { Tag = torrentInfo }); } } } else { this.torrents_listView.Items.Clear(); } }
public void should_prefer_quality_over_the_number_of_peers() { var remoteBook1 = GivenRemoteAlbum(new List <Book> { GivenAlbum(1) }, new QualityModel(Quality.MP3_320)); var remoteBook2 = GivenRemoteAlbum(new List <Book> { GivenAlbum(1) }, new QualityModel(Quality.AZW3)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 100; torrentInfo1.Peers = 10; torrentInfo1.Size = 200.Megabytes(); var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 1100; torrentInfo2.Peers = 10; torrentInfo1.Size = 250.Megabytes(); remoteBook1.Release = torrentInfo1; remoteBook2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteBook1)); decisions.Add(new DownloadDecision(remoteBook2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteBook.Release).Should().Be(torrentInfo1); }
public AddStreamRequest SetFile(System.IO.Stream inputStream) { Contract.Requires(inputStream != null); Contract.Requires(inputStream.CanRead); if (inputStream == null) { throw new ArgumentNullException("inputStream"); } if (!inputStream.CanRead) { throw new ArgumentException("Argument inputStream must be readable"); } _inputStream = new Tools.ChunkedMemoryStream(); inputStream.CopyTo(_inputStream); _inputStream.Position = 0; var result = File.Bencoding.BencodeDecoder.Decode(_inputStream); _inputStream.Position = 0; if (result == null || result.Length == 0 || !(result[0] is File.Bencoding.BDictionary)) { throw new InvalidOperationException("Invalid torrent stream"); } var torrent = TorrentInfo.Parse((File.Bencoding.BDictionary)result[0]); _torrentInfo = torrent; return(this); }
public void should_prefer_releases_with_more_peers_given_equal_number_of_seeds() { var remoteAlbum1 = GivenRemoteAlbum(new List <Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_256)); var remoteAlbum2 = GivenRemoteAlbum(new List <Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_256)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.Size = 0; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 10; torrentInfo1.Peers = 10; var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Peers = 100; remoteAlbum1.Release = torrentInfo1; remoteAlbum2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteAlbum1)); decisions.Add(new DownloadDecision(remoteAlbum2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteAlbum.Release).Peers.Should().Be(torrentInfo2.Peers); }
public void should_prefer_first_release_if_peers_and_size_are_too_similar() { var remoteAlbum1 = GivenRemoteAlbum(new List <Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_256)); var remoteAlbum2 = GivenRemoteAlbum(new List <Album> { GivenAlbum(1) }, new QualityModel(Quality.MP3_256)); var torrentInfo1 = new TorrentInfo(); torrentInfo1.PublishDate = DateTime.Now; torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent; torrentInfo1.Seeders = 1000; torrentInfo1.Peers = 10; torrentInfo1.Size = 200.Megabytes(); var torrentInfo2 = torrentInfo1.JsonClone(); torrentInfo2.Seeders = 1100; torrentInfo2.Peers = 10; torrentInfo1.Size = 250.Megabytes(); remoteAlbum1.Release = torrentInfo1; remoteAlbum2.Release = torrentInfo2; var decisions = new List <DownloadDecision>(); decisions.Add(new DownloadDecision(remoteAlbum1)); decisions.Add(new DownloadDecision(remoteAlbum2)); var qualifiedReports = Subject.PrioritizeDecisions(decisions); ((TorrentInfo)qualifiedReports.First().RemoteAlbum.Release).Should().Be(torrentInfo1); }
/// <summary> /// Defines the entry point of the application. /// </summary> /// <param name="args">The arguments.</param> public static void Main(string[] args) { string Torrent_path = Generate_torrent.generate_torrent_F(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TorrentInfo.TryLoad(Torrent_path, out torrent); torrentClient = new TorrentClient.TorrentClient("Enter port you want to use", @"Enter where your torrent file is saved"); torrentClient.DownloadSpeedLimit = 1000000 * 1024; // 100 KB/s torrentClient.UploadSpeedLimit = 2000000 * 1024; // 200 KB/s torrentClient.TorrentHashing += TorrentClient_TorrentHashing; torrentClient.TorrentLeeching += TorrentClient_TorrentLeeching; torrentClient.TorrentSeeding += TorrentClient_TorrentSeeding; torrentClient.TorrentStarted += TorrentClient_TorrentStarted; torrentClient.TorrentStopped += TorrentClient_TorrentStopped; torrentClient.Start(); // start torrent client torrentClient.Start(torrent); // start torrent file // setup checkout timer var timer = new System.Timers.Timer(); timer.Interval = 1; timer.Elapsed += Timer_Elapsed; timer.Enabled = true; timer.Start(); Thread.Sleep(10000000); }
private void SetContent(TorrentInfo ti) { label1.Text = ti.Title; label2.Text = ti.User; label3.Text = $"{ti.Published.ToShortDateString()} {ti.Published.ToLongTimeString()}"; label6.Text = " " + ti.Likes; richTextBox1.Text = ti.Text; }
public IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse) { var torrentInfos = new List <TorrentInfo>(); var indexerHttpResponse = indexerResponse.HttpResponse; if (indexerHttpResponse.StatusCode != HttpStatusCode.OK) { throw new IndexerException(indexerResponse, $"Unexpected response status {indexerHttpResponse.StatusCode} code from API request"); } if (!indexerHttpResponse.Headers.ContentType.Contains(HttpAccept.Json.Value)) { throw new IndexerException(indexerResponse, $"Unexpected response header {indexerHttpResponse.Headers.ContentType} from API request, expected {HttpAccept.Json.Value}"); } if (indexerResponse.Content.ContainsIgnoreCase("Invalid API Key")) { throw new IndexerAuthException("API Key invalid or not authorized"); } var jsonResponse = new HttpResponse <BeyondHDResponse>(indexerHttpResponse); foreach (var row in jsonResponse.Resource.Results) { var details = row.InfoUrl; var link = row.DownloadLink; // BHD can return crazy values for tmdb var tmdbId = row.TmdbId.IsNullOrWhiteSpace() ? 0 : ParseUtil.TryCoerceInt(row.TmdbId.Split("/")[1], out var tmdbResult) ? tmdbResult : 0; var imdbId = ParseUtil.GetImdbID(row.ImdbId).GetValueOrDefault(); var release = new TorrentInfo { Title = row.Name, DownloadUrl = link, InfoHash = row.InfoHash, InfoUrl = details, Guid = details, Categories = _categories.MapTrackerCatDescToNewznab(row.Category), PublishDate = DateTime.Parse(row.CreatedAt, CultureInfo.InvariantCulture), Size = row.Size, Grabs = row.Grabs, Seeders = row.Seeders, ImdbId = imdbId, TmdbId = tmdbId, Peers = row.Leechers + row.Seeders, DownloadVolumeFactor = row.Freeleech || row.Limited ? 0 : row.Promo75 ? 0.25 : row.Promo50 ? 0.5 : row.Promo25 ? 0.75 : 1, UploadVolumeFactor = 1, MinimumRatio = 1, MinimumSeedTime = 172800, // 120 hours }; torrentInfos.Add(release); } // order by date return(torrentInfos.OrderByDescending(o => o.PublishDate).ToArray()); }
public FriendlyTorrentInfo(TorrentInfo torrent) { Torrent = torrent; QueuePosition = SetFriendlyQueuePosition(torrent.QueuePosition); Name = torrent.Name; Status = SetFriendlyStatus(torrent.Status); Size = SetFriendlySize(torrent.TotalSize); Progress = SetFriendlyProgress(torrent.PercentDone); }
private bool SameTorrent(Blacklist item, TorrentInfo release) { if (release.InfoHash.IsNotNullOrWhiteSpace()) { return(release.InfoHash.Equals(item.TorrentInfoHash)); } return(item.Indexer.Equals(release.Indexer, StringComparison.InvariantCultureIgnoreCase)); }
public AddTorrentViewModel(IEventAggregator eventAggregator, TorrentInfo torrentInfo) { if (eventAggregator == null) throw new ArgumentNullException("eventAggregator"); _eventAggregator = eventAggregator; _addParams = new AddTorrentParams { TorrentInfo = torrentInfo }; _addParams.SavePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); }
/// <summary> /// The caller should stop/start/whatever on the torrent, since it's no longer in the queue /// </summary> public void DeQueueTorrent(TorrentInfo ti) { if (queue_info_store.ContainsKey(ti.InfoHash)) { var cake = queue_info_store[ti.InfoHash]; cake.Dequeue(); queue_info_store.Remove(ti.InfoHash); } else { ti.QueueState = QueueState.NotQueued; } }
public TorrentPropertiesEditor(TorrentInfo torrent) { InitializeComponent(); if (torrent != null) { this.ti = torrent; this.TorrentProperties = torrent.TorrentSettings; this.Title = string.Format("{0} - ({1})", this.Title, this.ti.Name); } else { throw new System.ArgumentNullException("torrent"); } }
private void HandleAddTorrent(TorrentInfo info, string filePath) { var par = new AddTorrentParams { SavePath = "C:/Downloads", TorrentInfo = info }; if (!this.ParentWindow.TorrentModel.Session.TorrentExist(par)) { this.ParentWindow.TorrentModel.Session.AddTorrent(par); using (var db = new TorLiteDatabase()) { var fadded = db.FileStorage.Upload(Guid.NewGuid().ToString(), filePath); var cools = db.GetCollection<Torrent>("Torrents"); cools.Insert(new Torrent { Name = par.TorrentInfo.Name, UTC_CreationDate = DateTime.UtcNow, File = fadded.Id, Hash = par.TorrentInfo.InfoHash, Path = par.SavePath }); } } }
public void Save(TorrentInfo info) { var torrentsPath = _environment.GetApplicationDataPath().Combine("Torrents"); using (var creator = new TorrentCreator(info)) { var data = creator.Generate(); var filePath = torrentsPath.CombineWithFilePath(string.Format("{0}.torrent", info.InfoHash)); var file = _fileSystem.GetFile(filePath); using (var fileStream = file.Open(FileMode.Create, FileAccess.Write, FileShare.None)) { fileStream.Write(data, 0, data.Length); } } }
/// <summary> /// No use outside of TorrentInfo.PopulateFileList() /// </summary> /// <param name="branch"></param> /// <param name="trunk"></param> public static void ProcessFile(string branch, DirectoryKey trunk, TorrentInfo owner, Ragnar.FileEntry f, int index) { string[] parts = branch.Split('\\'); if (parts.Length == 1) { //((FileList)trunk[DirectoryKey.FILE_MARKER]).Add(new FileInfo(owner, f)); trunk.Add(f.Path, new FileInfo(owner, f, index)); } else { string node = parts[0]; string other = branch.Substring(node.Length + 1); if (!trunk.ContainsKey(node)) { trunk[node] = new DirectoryKey(node, owner); } ProcessFile(other, (DirectoryKey)trunk[node], owner, f, index); } }
private async void FilesPanel_OnDropPanel_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { // Note that you can have more than one file. string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { try { TorrentInfo info = new TorrentInfo(file); if (info.IsValid) { var piecelengthConv = (string)new Converter.FileSizeConverter().Convert(info.PieceLength, info.PieceLength.GetType(), null, CultureInfo.CurrentCulture); var totsizzeConv = (string)new Converter.FileSizeConverter().Convert(info.TotalSize, info.TotalSize.GetType(), null, CultureInfo.CurrentCulture); string torrInfo = string.Format("Commento: {0}\n" + "Data Creazione: {1}\n" + "Creatore: {2}\n" + "Hash: {3}\n" + "Nome: {4}\n" + "Files: {5}\n" + "Parti: {6} x {7}\n" + "Server Privato: {8}\n" + "Certificato SSL: {9}\n" + "Dimensione Totale: {10}", info.Comment, info.CreationDate, info.Creator, info.InfoHash, info.Name, info.NumFiles, info.NumPieces, piecelengthConv, new Converter.BoolConverter().Convert(info.Private, info.Private.GetType(), null, CultureInfo.CurrentCulture), info.SslCert, totsizzeConv); var data = await this.ParentWindow.ShowMessageAsync("Aggiungi Nuovo torrent", torrInfo, MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AnimateHide = true, AnimateShow = true }); if (data.Equals(MessageDialogResult.Affirmative)) HandleAddTorrent(info, file); } } catch { } } } }
public void UnregisterTorrent(TorrentInfo ti) { if (this.Name != null) { my_torrent_list.Remove(ti); } }
private bool can_be_queued(TorrentInfo ti) { return !(ti.IsComplete || ti.QueueState == QueueState.NotQueued); }
/// <summary> /// This will bring up the AddTorrentDialog, ask the user about the download path /// and enable file selection. This will only work if the torrent has metadata. /// </summary> /// <param name="ti"></param> private void handle_torrent_file_selection(TorrentInfo ti) { uiContext.Send(x => { App.Current.MainWindow.Activate(); AddTorrentDialog atd = new AddTorrentDialog(ti) { Owner = App.Current.MainWindow, Icon = App.Current.MainWindow.Icon }; atd.ShowDialog(); if (atd.UserOK) { ti.Name = atd.TorrentName; if (atd.TorrentSavePath != ti.SavePath) { ti.ChangeSavePath(atd.TorrentSavePath); } if (atd.AutoStartTorrent) { ti.Start(); } else { ti.Stop(); } ti.RatioLimit = atd.RatioLimit; if (!this._torrents.ContainsKey(ti.InfoHash)) { this._torrents.Add(ti.InfoHash, ti); this.Torrents.Add(ti); } } else { this.Torrents.Remove(ti); this._torrents.Remove(ti.InfoHash); this.LibtorrentSession.RemoveTorrent(ti.Torrent, true); this.DeleteTorrentStateData(ti.InfoHash); ti.OffMyself(); } }, null); }
void LibTorrentAlerts_TorrentAdded(Ragnar.TorrentHandle handle) { App.Current.Dispatcher.Invoke(new Action(() => { if (!_torrents.ContainsKey(handle.InfoHash.ToHex())) { TorrentInfo ti = new TorrentInfo(handle); this._torrents.Add(handle.InfoHash.ToHex(), ti); this.Torrents.Add(ti); } })); }
private void HandleBtnOpen() { var dialog = new OpenFileDialog() { Filter = "Torrents (*.torrent)|*.torrent", Title = "Select a .torrent file to open", Multiselect = false, }; var d = dialog.ShowDialog(this.ParentWindow); if (d.HasValue && d == true) { try { var info = new TorrentInfo(dialog.FileName); if (info.IsValid) HandleAddTorrent(info, dialog.FileName); } catch { } } }
public bool TorrentHasAnyLabel(TorrentInfo ti) { for (int i = 1 /*skip the null label*/; i < Labels.Count; i++) { if (Labels[i].HasTorrent(ti)) return true; } return false; }
public bool TorrentHasLabel(TorrentInfo ti, string label) { return check_label(label).HasTorrent(ti); }
public bool HasTorrent(TorrentInfo ti) { if (this.Name == null) { return false; } else { return my_torrent_list.Contains(ti); } }
public void RegisterTorrent(TorrentInfo ti) { if (this.Name != null) { if (!my_torrent_list.Contains(ti)) { my_torrent_list.Add(ti); } } }
public DirectoryKey(string name, TorrentInfo ti) { this.Name = name.FixUTF8(); this.OwnerTorrent = ti; }
public FileInfo(TorrentInfo owner, Ragnar.FileEntry file, int file_index) { this.file_path = file.Path.FixUTF8(); this.RawSize = file.Size; this.Owner = owner; this.FileIndex = file_index; if (this.Owner != null) { this.Owner.FileInfoList.Add(this); } }
public string[] GetLabelsForTorrent(TorrentInfo ti) { List<string> a = new List<string>(); for (int i = 1 /*skip the null label*/; i < Labels.Count; i++) { TorrentLabel label = Labels[i]; if (label.HasTorrent(ti)) a.Add(label.Name); } return a.ToArray(); }
public void AddTorrentByPath(string path, bool notifyIfAdded = true) { Ragnar.TorrentInfo torrent = null; try { torrent = new Ragnar.TorrentInfo(File.ReadAllBytes(path)); if (!torrent.IsValid) { torrent.Dispose(); MessageBox.Show(string.Format("Invalid torrent file {0}", path), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (this.ContainTorrent(torrent.InfoHash)) { if (notifyIfAdded) { NotificationManager.Notify(new TorrentAlreadyAddedNotification(torrent.Name, torrent.InfoHash)); } return; } path = BackupTorrent(path, torrent); } catch (Exception ex) { MessageBox.Show(string.Format("Could not load torrent {0}\n{1}", path, ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } var handle = this.LibtorrentSession.AddTorrent(new Ragnar.AddTorrentParams() { TorrentInfo = torrent, SavePath = App.Settings.DefaultDownloadPath }); handle.AutoManaged = false; handle.Pause(); TorrentInfo ti = new TorrentInfo(handle); ti.OriginalTorrentFilePath = path; ti.ApplyTorrentSettings(App.Settings.DefaultTorrentProperties); // we don't want all files to have a "lowest" file priorities since initialize priorities with the value 1 // we change it to 3, the priority "normal" as considered by byteflood. set_files_priorities(handle, 3); handle_torrent_file_selection(ti); }
public string GetFirstLabelForTorrent(TorrentInfo ti) { for (int i = 1 /*skip the null label*/; i < Labels.Count; i++) { if (Labels[i].HasTorrent(ti)) return Labels[i].Name; } return null; }
public int GetTorrentIndex(TorrentInfo ti) { if (App.Settings.EnableQueue && queue_info_store.ContainsKey(ti.InfoHash)) { return Array.IndexOf(queue_info_store.Keys.ToArray(), ti.InfoHash); } return -1; }
public void ClearLabels(TorrentInfo ti) { for (int i = 1 /*skip the null label*/; i < Labels.Count; i++) { Labels[i].UnregisterTorrent(ti); } Labels[0].RegisterTorrent(ti); // the null label }
private bool is_inactive(TorrentInfo ti) { if (ti.Torrent != null) { return ti.Torrent.State == MonoTorrent.Common.TorrentState.Stopped || ti.Torrent.State == MonoTorrent.Common.TorrentState.Error || ti.Torrent.State == MonoTorrent.Common.TorrentState.Stopping || !App.Settings.SeedingTorrentsAreActive && ti.Torrent.State == MonoTorrent.Common.TorrentState.Seeding; } return false; }
public TrackerInfo(Ragnar.AnnounceEntry t, TorrentInfo parent) { this.Tracker = t; this.Parent = parent; }
public void AddLabelForTorrent(TorrentInfo ti, TorrentLabel label) { label.RegisterTorrent(ti); Labels[0].RefreshCount(); }
public void QueueTorrent(TorrentInfo ti) { if (!App.Settings.SeedingTorrentsAreActive && ti.IsComplete) { //simply start it ti.QueueState = QueueState.Queued; ti.Torrent.Start(); return; } if (App.Settings.EnableQueue) { if (!queue_info_store.ContainsKey(ti.InfoHash)) { QueueCake cake = new QueueCake(); cake.Torrent = ti; ti.QueueState = QueueState.Queued; ti.Torrent.Stop(); cake.WorkerThread = new Amib.Threading.Action(() => { cake.ThreadBGRunning = true; ti.Torrent.Start(); ti.is_going_to_start = false; ti.UpdateList("Status"); while (ti.QueueState == QueueState.Queued) { if (is_inactive(ti)) { // The torrent is either: // stopped or has an error. // or is complete break; } else { //wait until something happen, while keeping the queue busy Thread.Sleep(1000); } } cake.ThreadBGRunning = false; //if we get here, then either the torrent was dequeued, or it is inactive //if (ti.IsComplete) { return; } }); ti.is_going_to_start = true; cake.ThreadBG = this.slots.QueueWorkItem(cake.WorkerThread); this.queue_info_store.Add(ti.InfoHash, cake); ti.UpdateList("Status"); } else { //torrent is inside the queue store var cake = queue_info_store[ti.InfoHash]; if (cake.ThreadBGRunning) { //this happen if the torrent was {downloading} and it was {paused}. //in this case, we start it. //in other words, the torrent still have a slot inside the queue, so we can start it ti.Torrent.Start(); } else { //let's seen how can this happen: //- if the user has stopped the torrent, the TorrentInfo class will dequeue the torrent, so the queue_info_store doesn't // contain this torrent, so this should never happen. //- if the user hasn't stopped the torrent but an error has been occured, the torrent queue thread will be stopped, but // the torrent cake will remain inside the queue_info_store. //- if the torrent entered seeding state, and seeding is configured as inactive. //tl;dr torrent either has an error or it is seeding if (ti.Torrent.State == MonoTorrent.Common.TorrentState.Error) { //Attempt to start it again this.queue_info_store.Remove(ti.InfoHash); this.QueueTorrent(ti); } //if (ti.Torrent.State == MonoTorrent.Common.TorrentState.Seeding) //{ // //the torrent is seeding and the user clicked start, so do nothing // //except maybe remove the torrent cake, but I am not sure yet. //} } } } else { ti.Torrent.Start(); } }
public void AddLabelForTorrent(TorrentInfo ti, string label) { var t = check_label(label); t.RegisterTorrent(ti); Labels[0].RefreshCount(); }
public bool Can_I_ShowUP(TorrentInfo ti) { if (this.EnableFilter) { if (_sl != null) { return TorrentHasLabel(ti, SelectedLabel); } else { return !TorrentHasAnyLabel(ti); } } return true; }