Example #1
0
        public void Handle(AddUrlMessage message)
        {
            using (var addParams = new AddTorrentParams())
            {
                addParams.Name     = message.Name;
                addParams.SavePath = message.SavePath ?? _keyValueStore.Get <string>("bt.save_path");
                addParams.Url      = message.Url;

                if (message.Trackers != null)
                {
                    foreach (var tracker in message.Trackers)
                    {
                        addParams.Trackers.Add(tracker);
                    }
                }

                // Parse info hash
                var infoHash = Regex.Match(message.Url, "urn:btih:([\\w]{32,40})").Groups[1].Value;

                if (infoHash.Length == 32)
                {
                    infoHash = BitConverter.ToString(Base32Encoder.ToBytes(infoHash)).Replace("-", "").ToLowerInvariant();
                }

                // Set label
                _metadataRepository.SetLabel(infoHash, message.Label);

                // Add torrent
                _session.AsyncAddTorrent(addParams);
            }
        }