public JsonResult GetMagnet(string data) { if (string.IsNullOrEmpty(data)) { return(Json(null)); } return(Json(TorrentHelper.GetMagnetURL(System.Convert.FromBase64String(data)))); }
private static void Main(string[] args1) { //Please fill folder c:\windows\temp\downloads\a with test files for the torrent to be created and shared var config = Catalog.Factory.Resolve <IConfig>(); var downloadPath = config[BitTorrentSettings.DownloadFolder]; var torrentPath = config[BitTorrentSettings.TrackerTorrentFolder]; var contentFilename = Path.Combine(downloadPath, "test.txt"); var fileId = "out";// Guid.NewGuid(); var relativePath = "DigitalSignage\\Package\\" + fileId + ".7z"; var absolutePath = Path.Combine(downloadPath, relativePath); if (!File.Exists(absolutePath)) { var dirName = Path.GetDirectoryName(absolutePath); if (dirName != null && !Directory.Exists(dirName)) { Directory.CreateDirectory(dirName); } using (var sw = new StreamWriter(absolutePath)) { sw.WriteLine("It is just a test! " + absolutePath); } } if (!Directory.Exists(torrentPath)) { Directory.CreateDirectory(torrentPath); } var seeder = TorrentHelper.ClientManager.GetSeeder(); seeder.StartSeedingFile += (sender, args) => { Debug.WriteLine("Seeding file " + args.TorrentFileUri); System.Console.WriteLine("Seeding {0}", args.TorrentFileUri); }; if (!seeder.IsRunning) { seeder.Start(); } var torrent = TorrentHelper.CreateTorrent(downloadPath, relativePath, torrentPath); System.Console.WriteLine("Torrent Created {0}", torrent.TorrentFileUri); //torrent = TorrentHelper.CreateTorrent(downloadPath, "DigitalSignage\\Package\\out.7z", torrentPath); //System.Console.WriteLine("Torrent Created {0}", torrent.TorrentFileUri); System.Console.ReadLine(); seeder.Stop(); }
private static void Main(string[] args) { var tracker = TorrentHelper.RunTracker(); //var torrent = TorrentHelper.CreateTorrent(@"C:\Windows\Temp\toTorrent\a", @"C:\Windows\Temp\torrents"); //var testTorrentUri = torrent.TorrentFileUri; //tracker.AddTorrent(TorrentHelper.LoadTorrent(@"C:\Windows\Temp\torrents\tmp947A.torrent")); //tracker.AddTorrent(@"C:\Windows\Temp\torrents\tmp947A.torrent"); // tracker.AddTorrent(@"C:\Windows\Temp\torrents\tmp947A.torrent"); System.Console.ReadLine(); tracker.Stop(); }
public ReleaseSource GetBestReleaseSource(string title, int year) { HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "http://www.imdb.com"); var bestRelease = new ReleaseSource() { Quality = -1 }; var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }); var url = string.Format( "http://kickass.to/usearch/{0}%20{1}%20category%3Amovies/?field=seeders&sorder=desc", HttpUtility.UrlEncode(title), year); var response = client.GetAsync(url).Result; CQ document = response.Content.ReadAsStringAsync().Result; var rows = document[".data tr"]; foreach (var row in rows) { var rowCq = row.Cq(); if (rowCq.HasClass("firstr")) { continue; } var torrentLink = rowCq.Find("div.torrentname > a.normalgrey"); var torrentTitle = torrentLink.Text(); var releaseSource = TorrentHelper.GetReleaseSource(torrentTitle); if (releaseSource.Quality > bestRelease.Quality) { bestRelease = releaseSource; } } return(bestRelease); }
public static void ConfigureUnityContainer(IUnityContainer container) { #region Common var dhtTrackerListenerPort = Int32.Parse(ConfigurationManager.AppSettings["DhtTrackerListeningPort"]); var infoServerListeningPort = Int32.Parse(ConfigurationManager.AppSettings[ "HttpPieceInfoServerListeningPort"]); // listeningPort #endregion #region TorrentSettings // Create the default settings which a torrent will have. // 4 Upload slots - a good ratio is one slot per 5kB of upload speed // 50 open connections - should never really need to be changed // Unlimited download speed - valid range from 0 -> int.Max // Unlimited upload speed - valid range from 0 -> int.Max TorrentSettings torrentDefaults = new TorrentSettings(4, 150, 0, 0); container.RegisterInstance <TorrentSettings>(torrentDefaults); #endregion #region ClientEngine // DefaultListenPort = 52138; var engineSettings = new EngineSettings(); engineSettings.PreferEncryption = false; engineSettings.AllowedEncryption = EncryptionTypes.All; var clientEngine = new ClientEngine(engineSettings); container.RegisterInstance <ClientEngine>(clientEngine); #endregion #region DhtProxy var peerTtlSecs = 60 * 50; container.RegisterType <DictionaryServiceProxy>( new InjectionConstructor(typeof(DictionaryServiceBase), peerTtlSecs)); #endregion #region DhtTracker // Singleton. container.RegisterType <DictionaryServiceTracker>(new ContainerControlledLifetimeManager(), new InjectionConstructor( typeof(DictionaryServiceProxy), string.Format("http://*:{0}/", dhtTrackerListenerPort))); // listeningPrefix #endregion #region TorrentHelper // Singleton. var cacheBaseDirPath = ConfigurationManager.AppSettings["BitTorrentManagerBaseDirPath"]; IPAddress ip = NetUtil.GetLocalIPByInterface( ConfigurationManager.AppSettings["DhtTrackerIface"]); int gsserverPort = Int32.Parse(ConfigurationManager.AppSettings["GSServerPort"]); var bittorrentCache = new BitTorrentCache(cacheBaseDirPath); container.RegisterInstance <BitTorrentCache>(bittorrentCache); var torrentHelper = new TorrentHelper( bittorrentCache, ip, dhtTrackerListenerPort, gsserverPort); container.RegisterInstance <TorrentHelper>(torrentHelper); #endregion #region BitTorrentManager // Singleton. container.RegisterType <BitTorrentManager>( new ContainerControlledLifetimeManager(), new InjectionConstructor( typeof(BitTorrentCache), ConfigurationManager.AppSettings["BitTorrentManagerSelfNamespace"], typeof(DictionaryServiceProxy), typeof(DictionaryServiceTracker), typeof(ClientEngine), typeof(TorrentSettings), typeof(TorrentHelper), Boolean.Parse(ConfigurationManager.AppSettings[ "BitTorrentManagerStartSeedingAtStartup"]) )); #endregion #region IPieceInfoServer // Singleton. //container.RegisterType<IPieceInfoServer, HttpPieceInfoServer>( // new ContainerControlledLifetimeManager(), // new InjectionConstructor( // infoServerListeningPort, // typeof(PieceLevelTorrentManager))); #endregion #region PieceLevelTorrentManager container.RegisterType <PieceLevelTorrentManager>( new ContainerControlledLifetimeManager(), new InjectionConstructor( typeof(BitTorrentManager), typeof(BitTorrentCache), typeof(DictionaryServiceProxy), typeof(TorrentHelper), infoServerListeningPort)); #endregion }