コード例 #1
0
        public void AddTorrent_Test()
        {
            if (!File.Exists(FILE_PATH))
                throw new Exception("Torrent file not found");

            var fstream = File.OpenRead(FILE_PATH);
            byte[] filebytes = new byte[fstream.Length];
            fstream.Read(filebytes, 0, Convert.ToInt32(fstream.Length));
            
			string encodedData = Convert.ToBase64String(filebytes);

			//The path relative to the server (priority than the metadata)
			//string filename = "/DataVolume/shares/Public/Transmission/torrents/ubuntu-10.04.4-server-amd64.iso.torrent";

            var torrent = new NewTorrent
            {
				//Filename = filename,
                Metainfo = encodedData,
                Paused = false
            };

            var newTorrentInfo = client.AddTorrent(torrent);

			Assert.IsNotNull(newTorrentInfo);
			Assert.IsTrue(newTorrentInfo.ID != 0);
        }
コード例 #2
0
        public override Task<string> Download(string path, ITorrentSearchResult searchResult) {
            return Task.Run(() => {
                var client = CreateClient();

                var torrent = new NewTorrent { Filename = searchResult.MagnetUri, DownloadDirectory = Path.Combine(path, searchResult.Name) };
                var result = client.AddTorrent(torrent);
                if (!string.IsNullOrEmpty(result.ErrorString)) throw new NovaromaException(result.ErrorString + " ("+ result.Error +")");

                return result.HashString;
            });
        }
コード例 #3
0
        /// <summary>
        /// Add torrent (API: torrent-add)
        /// </summary>
        /// <returns>Torrent info (ID, Name and HashString)</returns>
        public async Task<NewTorrentInfo> TorrentAddAsync(NewTorrent torrent)
        {
            if (String.IsNullOrWhiteSpace(torrent.Metainfo) && String.IsNullOrWhiteSpace(torrent.Filename))
                throw new Exception("Either \"filename\" or \"metainfo\" must be included.");

            var request = new TransmissionRequest("torrent-add", torrent.ToDictionary());
            var response = await SendRequestAsync(request);
            var jObject = response.Deserialize<JObject>();

            if (jObject == null || jObject.First == null)
                return null;

            NewTorrentInfo result = null;
            JToken value = null;

            if (jObject.TryGetValue("torrent-duplicate", out value))
                result = JsonConvert.DeserializeObject<NewTorrentInfo>(value.ToString());
            else if (jObject.TryGetValue("torrent-added", out value))
                result = JsonConvert.DeserializeObject<NewTorrentInfo>(value.ToString());

            return result;
        }