/// <summary> /// Implements the <see cref="ProcessRecord"/> method for <see cref="RenameTransmissionTorrentPathCmdlet"/>. /// </summary> protected override void ProcessRecord() { try { var torrentSvc = new TorrentService(); RenamedTorrent renamedTorrents = Task.Run(async() => await torrentSvc.RenameTorrentPath(TorrentId, TorrentPath, TorrentName)).Result; if (renamedTorrents == null) { ThrowTerminatingError(new ErrorRecord(new Exception("Failed to rename torrent path"), null, ErrorCategory.OperationStopped, null)); } if (Json) { WriteObject(JsonConvert.SerializeObject(renamedTorrents)); } else { WriteObject(renamedTorrents); } } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to rename torrent path with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
public void GetHash_NotPass_UpperCase() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:08c2c30ca85cf78ed147488a431d9aee50824a7b"; var hash = service.GetHash(magnet); Assert.AreNotEqual("08C2C30CA85CF78ED147488A431D9AEE50824A7B", hash); }
public void GetHash_Pass_32() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:BDBMGDFILT3Y5UKHJCFEGHM25ZIIEST3"; var hash = service.GetHash(magnet); Assert.AreEqual("08c2c30ca85cf78ed147488a431d9aee50824a7b", hash); }
public void GetHash_Pass_40() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:08c2c30ca85cf78ed147488a431d9aee50824a7b"; var hash = service.GetHash(magnet); Assert.AreEqual("08c2c30ca85cf78ed147488a431d9aee50824a7b", hash); }
public void NormalizeMagnetUrl_Pass_32() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:BDBMGDFILT3Y5UKHJCFEGHM25ZIIEST3"; var after = service.NormalizeMagnetUrl(magnet); Assert.AreEqual("magnet:?xt=urn:btih:08c2c30ca85cf78ed147488a431d9aee50824a7b", after); }
public void NormalizeMagnetUrl_Pass_40() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:08c2c30ca85cf78ed147488a431d9aee50824a7b"; var after = service.NormalizeMagnetUrl(magnet); Assert.AreEqual(magnet, after); }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="AssertTransmissionTorrentsVerifiedCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { // validate a torrent id has been supplied if (!_torrentIds.Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("The TorrentIds parameter must be supplied."), null, ErrorCategory.InvalidArgument, null)); } var torrentSvc = new TorrentService(); bool success = Task.Run(async() => await torrentSvc.VerifyTorrents(_torrentIds)).Result; if (AsBool.IsPresent) { WriteObject(success); return; } if (!success) { ThrowTerminatingError(new ErrorRecord(new Exception("Torrent(s) verification failed"), null, ErrorCategory.OperationStopped, null)); } WriteObject("Torrent(s) verification successful"); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to verify torrent(s) with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
//[TestMethod] public async Task DownloadTorrent_Pass_Online() { var api = RestService.For<IMagnetApi>("https://m2t.chinacloudsites.cn"); var service = new TorrentService(api, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:08c2c30ca85cf78ed147488a431d9aee50824a7b"; var torrentBytes = await service.DownloadTorrent(magnet); Assert.IsTrue(service.IsTorrentFileValid(torrentBytes)); }
public void NormalizeMagnetUrl_Pass_Tracker() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var magnet = "magnet:?xt=urn:btih:4cda49aa1c28db946e89ecb6e18482c8d347b41d&tr=udp://9.rarbg.to:2710/announce&tr=udp://9.rarbg.me:2710/announce&tr=http://tr.cili001.com:8070/announce&tr=http://tracker.trackerfix.com:80/announce&tr=udp://open.demonii.com:1337&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://p4p.arenabg.com:1337&tr=wss://tracker.openwebtorrent.com&tr=wss://tracker.btorrent.xyz&tr=wss://tracker.fastcast.nz"; var after = service.NormalizeMagnetUrl(magnet); Assert.AreEqual("magnet:?xt=urn:btih:4cda49aa1c28db946e89ecb6e18482c8d347b41d", after); }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="SetTransmissionTorrentsCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { // validate a torrent id has been supplied if (!(TorrentIds ?? new List <int>()).Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("The TorrentIds parameter must be supplied."), null, ErrorCategory.InvalidArgument, null)); } var torrentSvc = new TorrentService(); var request = new TorrentSettings { BandwidthPriority = BandwidthPriority, DownloadLimit = DownloadLimit, DownloadLimited = DownloadLimited, HonorsSessionLimits = HonoursSessionLimits, Ids = _torrentIds.ToArray(), Location = Location, PeerLimit = PeerLimit, QueuePosition = QueuePosition, SeedIdleLimit = SeedIdleLimit, SeedIdleMode = SeedIdleMode, SeedRatioLimit = SeedRatioLimit, SeedRatioMode = SeedRatioMode, UploadLimit = UploadLimit, UploadLimited = UploadLimited, TrackerAdd = (TrackerAdd ?? new List <string>()).Any() ? TrackerAdd.ToArray() : null, TrackerRemove = (TrackerRemove ?? new List <int>()).Any() ? TrackerRemove.ToArray() : null }; bool success = Task.Run(async() => await torrentSvc.SetTorrents(request)).Result; if (AsBool.IsPresent) { WriteObject(success); return; } if (!success) { ThrowTerminatingError(new ErrorRecord(new Exception("Set torrent(s) failed"), null, ErrorCategory.OperationStopped, null)); } WriteObject("Set torrent(s) successful"); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to set torrent(s) with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
public void IsTorrentFileValid_NotPass() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var torrentBytes = File.ReadAllBytes("valid.torrent"); //修改一些文件内容 for (int i = 100; i < 200; i++) { torrentBytes[i] = 0; } Assert.IsFalse(service.IsTorrentFileValid(torrentBytes)); }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="RemoveTransmissionTorrentsCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { if (!All.IsPresent && !Completed.IsPresent && !Incomplete.IsPresent && !(TorrentIds ?? new List <int>()).Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("One of the following parameters must be supplied: All, Completed, Incomplete, TorrentIds"), null, ErrorCategory.InvalidArgument, null)); } var torrentSvc = new TorrentService(); (bool success, int torrentCount)response; string info = ""; if (All.IsPresent) { response = Task.Run(async() => await torrentSvc.RemoveTorrents(null, DeleteData.IsPresent)).Result; } else if (Completed.IsPresent) { response = Task.Run(async() => await torrentSvc.RemoveCompletedTorrents(DeleteData.IsPresent)).Result; info = "completed "; } else if (Incomplete.IsPresent) { response = Task.Run(async() => await torrentSvc.RemoveIncompleteTorrents(DeleteData.IsPresent)).Result; info = "incomplete "; } else { response = Task.Run(async() => await torrentSvc.RemoveTorrents(_torrentIds, DeleteData.IsPresent)).Result; } if (!response.success) { ThrowTerminatingError(new ErrorRecord(new Exception("Failed to remove torrents"), null, ErrorCategory.OperationStopped, null)); } if (response.torrentCount == 0) { WriteWarning("No torrents found."); } else { WriteObject($"{response.torrentCount} {info} torrent{(response.torrentCount > 1 ? "s" : "")} removed."); } } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to remove torrents with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
public TorrentsModule( TorrentService torrentService ) : base("/api/torrents") { _torrentService = torrentService; Get["/"] = Index; Get["/{torrentID}"] = Details; Put["/{torrentID}"] = Update; Delete["/{torrentID}"] = DeleteTorrent; }
private static async Task Main(string[] args) { _provider = SetupDependencies(); _semaphore = new SemaphoreSlim(1, 1); _logger = _provider.GetRequiredService <ILogger <object> >(); _fileService = _provider.GetRequiredService <FileService>(); _torrentService = _provider.GetRequiredService <TorrentService>(); _rssService = _provider.GetRequiredService <RssService>(); _logger.LogInformation("Application Startup Complete."); await Task.WhenAll(PollFeeds(), PollCompleteFiles()); }
public static IServiceCollection AddTorrentServices(this IServiceCollection services, IConfiguration configuration) { var dataServiceOptions = new DataService.DataServiceOptions(); var torrentServiceOptions = new TorrentService.TorrentServiceOptions(); configuration.GetSection("DataService").Bind(dataServiceOptions); configuration.GetSection("TorrentService").Bind(torrentServiceOptions); services.AddSingleton <ITorrentService>(p => { var ts = new TorrentService(torrentServiceOptions, p.GetService <ILoggerFactory>()); ts.Connect(); return(ts); }); services.AddTransient <IDataService>(p => new DataService(dataServiceOptions)); services.AddTransient <ITorrentRepository, TorrentRepository>(); return(services); }
public IndexModule( SearchService searchService, TorrentService torrentService ) { _torrentService = torrentService; Get["/"] = parameters => { var user = this.GetUser() ?? new User(); var model = new { User = user, UserPresent = user.ID != null, FilterVideo = (int)user.FilterVideo, FilterAudio = (int)user.FilterAudio, FilterTraslation = (int)user.FilterTraslation, FilterSizes = user.FilterSizes, LibScript = Bundle.JavaScript().RenderCachedAssetTag("lib"), AppScript = Bundle.JavaScript().RenderCachedAssetTag("app"), LibCss = Bundle.Css().RenderCachedAssetTag("css") }; return(View["index", model]); }; Get["/test"] = parameters => { using (var db = new DbTorronto()) { var user = db.User.FirstOrDefault(x => x.ID == 3); var message = new StringBuilder() .AppendLine("оПХБЕР"); EmailService.SendMail(user, "test", message); } return(200); }; Get["/rss/{userHash}"] = GetUserRss; }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="MoveTransmissionTorrentsQueueCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { // validate queue move parameter has been supplied if (!Up.IsPresent && !Down.IsPresent && !Top.IsPresent && !Bottom.IsPresent) { ThrowTerminatingError(new ErrorRecord(new Exception("One of the following parameters must be supplied: Up, Down, Top, Bottom"), null, ErrorCategory.InvalidArgument, null)); } // validate a torrent id has been supplied if (!(TorrentIds ?? new List <int>()).Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("The TorrentIds parameter must be supplied."), null, ErrorCategory.InvalidArgument, null)); } var torrentSvc = new TorrentService(); if (Up.IsPresent) { Task.Run(async() => await torrentSvc.MoveTorrents(MoveInQueue.Up, _torrentIds)); } else if (Down.IsPresent) { Task.Run(async() => await torrentSvc.MoveTorrents(MoveInQueue.Down, _torrentIds)); } else if (Top.IsPresent) { Task.Run(async() => await torrentSvc.MoveTorrents(MoveInQueue.Top, _torrentIds)); } else if (Bottom.IsPresent) { Task.Run(async() => await torrentSvc.MoveTorrents(MoveInQueue.Bottom, _torrentIds)); } WriteObject("Torrent(s) moved."); } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to move torrent(s) with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="GetTransmissionTorrentsCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { var torrentSvc = new TorrentService(); Torrent[] torrents; if (Completed.IsPresent) { torrents = Task.Run(async() => await torrentSvc.GetCompletedTorrents()).Result; } else if (Incomplete.IsPresent) { torrents = Task.Run(async() => await torrentSvc.GetIncompleteTorrents()).Result; } else if (_torrentIds.Any()) { torrents = Task.Run(async() => await torrentSvc.GetTorrents(_torrentIds)).Result; } else { torrents = Task.Run(async() => await torrentSvc.GetTorrents()).Result; } if (Json) { WriteObject(JsonConvert.SerializeObject(torrents)); } else { WriteObject(torrents); } } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to retrieve torrents with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
public void IsTorrentFileValid_Pass() { var service = new TorrentService(null, new NullLogger<TorrentService>()); var torrentBytes = File.ReadAllBytes("valid.torrent"); Assert.IsTrue(service.IsTorrentFileValid(torrentBytes)); }
public RootHandler(TorrentService torrent, IServiceScopeFactory scopeFactory) { _torrent = torrent; _scopeFactory = scopeFactory; }
public CallbackHandler(TorrentService torrent, IServiceScopeFactory scopeFactory) { _torrent = torrent; _scopeFactory = scopeFactory; }
public TorrentController() { this.torrentService = new TorrentService(); }
/// <summary> /// Implements the <see cref="EndProcessing"/> method for <see cref="AddTransmissionTorrentsCmdlet"/>. /// Retrieve all torrents /// </summary> protected override void EndProcessing() { try { // build an array of all supplied torrents to validate against var allTorrents = _urls .Union(_files) .Union(_metas) .ToList(); // validate files, urls or metainfos have been supplied if (!allTorrents.Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("At least one of the following parameters must be supplied: Urls, Files, MetaInfos"), null, ErrorCategory.InvalidArgument, null)); } // validate FilesWanted, FilesUnwanted, PriorityHigh, PriorityLow & PriorityNormal haven't been supplied if multiple torrents are to be added if (allTorrents.Count > 1 && (FilesWanted ?? new List <int>()).Any() || (FilesUnwanted ?? new List <int>()).Any() || (PriorityHigh ?? new List <int>()).Any() || (PriorityLow ?? new List <int>()).Any() || (PriorityNormal ?? new List <int>()).Any()) { ThrowTerminatingError(new ErrorRecord(new Exception("If multiple torrents are supplied then none of the following parameters should be supplied: FilesWanted, FilesUnwanted, PriorityHigh, PriorityLow, PriorityNormal"), null, ErrorCategory.InvalidArgument, null)); } var torrentSvc = new TorrentService(); List <NewTorrent> newTorrents = _urls .Union(_files) .Select(t => new NewTorrent { Cookies = !string.IsNullOrWhiteSpace(Cookies) ? Cookies : null, DownloadDirectory = !string.IsNullOrWhiteSpace(DownloadDirectory) ? DownloadDirectory : null, Filename = t, MetaInfo = null, Paused = Paused, PeerLimit = PeerLimit, BandwidthPriority = BandwidthPriority, FilesWanted = (FilesWanted ?? new List <int>()).Any() ? FilesWanted.ToArray() : null, FilesUnwanted = (FilesUnwanted ?? new List <int>()).Any() ? FilesUnwanted.ToArray() : null, PriorityHigh = (PriorityHigh ?? new List <int>()).Any() ? PriorityHigh.ToArray() : null, PriorityLow = (PriorityLow ?? new List <int>()).Any() ? PriorityLow.ToArray() : null, PriorityNormal = (PriorityNormal ?? new List <int>()).Any() ? PriorityNormal.ToArray() : null }) .ToList(); newTorrents.AddRange(_metas.Select(m => new NewTorrent { Cookies = !string.IsNullOrWhiteSpace(Cookies) ? Cookies : null, DownloadDirectory = !string.IsNullOrWhiteSpace(DownloadDirectory) ? DownloadDirectory : null, Filename = null, MetaInfo = m, Paused = Paused, PeerLimit = PeerLimit, BandwidthPriority = BandwidthPriority, FilesWanted = (FilesWanted ?? new List <int>()).Any() ? FilesWanted.ToArray() : null, FilesUnwanted = (FilesUnwanted ?? new List <int>()).Any() ? FilesUnwanted.ToArray() : null, PriorityHigh = (PriorityHigh ?? new List <int>()).Any() ? PriorityHigh.ToArray() : null, PriorityLow = (PriorityLow ?? new List <int>()).Any() ? PriorityLow.ToArray() : null, PriorityNormal = (PriorityNormal ?? new List <int>()).Any() ? PriorityNormal.ToArray() : null }) .ToList()); AddTorrentsResponse response = Task.Run(async() => await torrentSvc.AddTorrents(newTorrents)).Result; if (Json) { WriteObject(JsonConvert.SerializeObject(response)); } else { WriteObject(response); } } catch (Exception e) { ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to add torrent(s) with error: {e.Message}", e), null, ErrorCategory.OperationStopped, null)); } }
public TorrentUploaderWidgetController() { this._torrentService = new TorrentService(); }