void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) { Announce = Announces [0] [0]; } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList(); #if NETSTANDARD1_5 seedlist.AddRange(getrightHttpSeeds.ConvertAll <string, BEncodedValue>(delegate(string s) { return((BEncodedString)s); })); #else seedlist.AddRange(getrightHttpSeeds.ConvertAll <BEncodedValue>(delegate(string s) { return((BEncodedString)s); })); #endif torrent["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime(1970, 1, 1); torrent ["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
private void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces[0].Count > 0) { Announce = Announces[0][0]; } if (_getrightHttpSeeds.Count > 0) { var seedlist = new BEncodedList(); seedlist.AddRange(_getrightHttpSeeds.ConvertAll <BEncodedValue>(s => (BEncodedString)s)); torrent["url-list"] = seedlist; } var span = DateTime.Now - new DateTime(1970, 1, 1); torrent["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) { Announce = Announces [0] [0]; } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList(); seedlist.AddRange(getrightHttpSeeds.Cast <BEncodedString>()); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime(1970, 1, 1); torrent ["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count == 0 || (Announces.Count == 1 && Announces[0].Count <= 1)) { RemoveCustom("announce-list"); } if (Announces.Count > 0 && Announces[0].Count > 0) { Announce = Announces[0][0]; } if (GetrightHttpSeeds.Count > 0) { var seedlist = new BEncodedList(); seedlist.AddRange(GetrightHttpSeeds.Select(s => (BEncodedString)s)); torrent["url-list"] = seedlist; } TimeSpan span = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); torrent["creation date"] = new BEncodedNumber((long)span.TotalSeconds); }
private void AddCommonStuff(BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces[0].Count > 0) Announce = Announces[0][0]; if (GetrightHttpSeeds.Count > 0) { var seedlist = new BEncodedList(); seedlist.AddRange( GetrightHttpSeeds.ConvertAll<BEncodedValue>(delegate(string s) { return (BEncodedString) s; })); torrent["url-list"] = seedlist; } var span = DateTime.Now - new DateTime(1970, 1, 1); torrent["creation date"] = new BEncodedNumber((long) span.TotalSeconds); }
private void ProcessTorrentGen(string sContentUniqueId, ContentGenRecipes oRecipes, EventHandler <TorrentCreatorEventArgs> callbackHashed, out string sContentHashCode) { long lPieceLengthKB = AppConfig.ContentGenJob.PieceLengthKB; string sCreatedBy = AppConfig.ContentGenJob.CreatedBy; string sTrackerAnnounceUrl = AppConfig.ContentGenJob.TrackerAnnounceUrl; string sInternalTrackerAnnounceUrl = AppConfig.ContentGenJob.InternalTrackerAnnounceUrl; // Initialization _InterruptFlag = false; sContentHashCode = ""; // Initialize the torrent creation task MetafileGenTask oMG = new MetafileGenTask(); oMG.Hashed += callbackHashed; // Set the torrent info oMG.PieceLength = lPieceLengthKB * 1024; // Torrent info: PieceLength oMG.StoreMD5 = false; // Don't store MD5SUM in the torrent file oMG.Private = true; // Always be private torrent oMG.CreatedBy = sCreatedBy; // Torrent info: CreatedBy if (oRecipes.HttpSeedsUrl != null && oRecipes.HttpSeedsUrl.Length > 0) { List <string> listUrls = oRecipes.HttpSeedsUrlList; listUrls.ForEach(sUrl => { oMG.GetrightHttpSeeds.Add(sUrl); }); // URL seed } List <string> oAnn = new List <string>(); oAnn.Add(sTrackerAnnounceUrl); oMG.Announces.Add(oAnn); // Torrent Info: Tracker Server // Assign the custom fields to the "info" section of the torrent oMG.AddCustomSecure("ga account name", new BEncodedString(oRecipes.GAProfileId)); oMG.AddCustomSecure("ga host name", new BEncodedString("http://www.gamania.com")); oMG.AddCustomSecure("custom display name", new BEncodedString(oRecipes.DownloaderDisplayName)); // Begin the async torrent creation process IAsyncResult asyncResult = oMG.BeginCreate( oRecipes.ContentSourceUrl, // Content Source URL null, // No callback needed oRecipes.ContentSourceUrl // Async state ); // Wait for the completion or the aborting if (!asyncResult.IsCompleted) { while (!asyncResult.AsyncWaitHandle.WaitOne(1000)) { if (_InterruptFlag) { oMG.AbortCreation(); // Try to abort the task } } } // End of the async torre creation BEncodedDictionary oTorrentBenDict = oMG.EndCreate(asyncResult); // Get the content hash code from the torrent file sContentHashCode = Torrent.Load(oTorrentBenDict).InfoHash.ToHex(); lock (sigLock) { // ========= Save 3 types of torrent files for 3 different usages ============== // 1. Save the torrent file which contains the public tracker announce URL File.WriteAllBytes( ContentWorkingPath + "\\" + sContentUniqueId + "\\" + sContentHashCode + TorrentExtension, oTorrentBenDict.Encode()); // 2. Save the VIP torrent file contains the public tracker announce URL if (oRecipes.VipHttpSeedsUrl != null && oRecipes.VipHttpSeedsUrl.Length > 0) { // Add more Url Seed Urls List <string> listUrls = oRecipes.VipHttpSeedsUrlList; listUrls.ForEach(sUrl => { oMG.GetrightHttpSeeds.Add(sUrl); }); // Add more URL seed // Convert to Ben-Encoded List BEncodedList listUrlSeeds = new BEncodedList(); listUrlSeeds.AddRange(oMG.GetrightHttpSeeds.ConvertAll <BEncodedValue>(s => { return((BEncodedString)s); })); oTorrentBenDict[TorrentInfoUrlListKey] = listUrlSeeds; } // Save the VIP Torrent file File.WriteAllBytes( ContentWorkingPath + "\\" + sContentUniqueId + "\\" + sContentHashCode + TorrentVipExtension, oTorrentBenDict.Encode()); // 3. Save the FQDN torrent file which contains the internal tracker announce URL // First, add the content source URL to the torrent to accelerate the download speed if (-1 == oRecipes.HttpSeedsUrlList.FindIndex(x => { return(x.Equals(oRecipes.ContentSourceUrl)); }) && -1 == oRecipes.VipHttpSeedsUrlList.FindIndex(x => { return(x.Equals(oRecipes.ContentSourceUrl)); })) { // Add the content source URL to the TorrentInfoUrlListKey // together with the VIP URL seeds just added previously oMG.GetrightHttpSeeds.Add(oRecipes.ContentSourceUrl); // Convert to Ben-Encoded List BEncodedList listUrlSeeds = new BEncodedList(); listUrlSeeds.AddRange(oMG.GetrightHttpSeeds.ConvertAll <BEncodedValue>(s => { return((BEncodedString)s); })); oTorrentBenDict[TorrentInfoUrlListKey] = listUrlSeeds; } // Second, replace the tracker announce URL with the internal tracker announce URL oTorrentBenDict[TorrentInfoAnnounceKey] = new BEncodedString(sInternalTrackerAnnounceUrl); // Save the FQDN Torrent file File.WriteAllBytes( ContentWorkingPath + "\\" + sContentUniqueId + "\\" + sContentHashCode + TorrentFqdnExtension, oTorrentBenDict.Encode()); } }
void AddCommonStuff (BEncodedDictionary torrent) { if (announces.Count > 0 && announces [0].Count > 0) torrent.Add ("announce", new BEncodedString (announces [0] [0])); // If there is more than one tier or the first tier has more than 1 tracker if (announces.Count > 1 || (announces.Count > 0 && announces [0].Count > 1)) { BEncodedList announceList = new BEncodedList (); for (int i = 0; i < this.announces.Count; i++) { BEncodedList tier = new BEncodedList (); for (int j = 0; j < this.announces [i].Count; j++) tier.Add (new BEncodedString (this.announces [i] [j])); announceList.Add (tier); } torrent.Add ("announce-list", announceList); } if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList (); seedlist.AddRange (getrightHttpSeeds.ConvertAll<BEncodedValue> (delegate (string s) { return (BEncodedString) s; })); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime (1970, 1, 1); torrent ["creation date"] = new BEncodedNumber ((long) span.TotalSeconds); }
void AddCommonStuff (BEncodedDictionary torrent) { if (Announces.Count > 0 && Announces [0].Count > 0) Announce = Announces [0] [0]; if (getrightHttpSeeds.Count > 0) { BEncodedList seedlist = new BEncodedList (); seedlist.AddRange (getrightHttpSeeds.Cast<BEncodedString>()); torrent ["url-list"] = seedlist; } TimeSpan span = DateTime.Now - new DateTime (1970, 1, 1); torrent ["creation date"] = new BEncodedNumber ((long) span.TotalSeconds); }