예제 #1
0
        protected override Data.Torrent FindAddedTorrent(AddUrlResponse result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (InputUrl != null && string.Equals(InputUrl.Scheme, "magnet", StringComparison.OrdinalIgnoreCase))
            {
                Regex reg   = new Regex("BTIH:([A-F0-9]{40})");
                Match match = reg.Match(InputUrl.ToString().ToUpperInvariant());
                if (match.Success)
                {
                    string hash    = match.Groups[1].Value;
                    var    torrent = result.Result.Torrents.OrderByDescending(t => t.AddedDate).AsParallel().FirstOrDefault(item => string.Equals(item.Hash, hash, StringComparison.OrdinalIgnoreCase));
                    return(torrent);
                }
            }

            return(null);
        }
예제 #2
0
        protected override Data.Torrent FindAddedTorrent(AddUrlResponse result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (InputUrl != null && string.Equals(InputUrl.Scheme, "magnet", StringComparison.OrdinalIgnoreCase))
            {
                //BTIH
                Regex reg   = new Regex("BTIH:([A-F0-9]{40})");
                var   url   = InputUrl.ToString().ToUpperInvariant();
                Match match = reg.Match(url);
                if (match.Success)
                {
                    string hash    = match.Groups[1].Value;
                    var    torrent = result.Result.Torrents.OrderByDescending(t => t.AddedDate).FirstOrDefault(item => string.Equals(item.Hash, hash, StringComparison.OrdinalIgnoreCase));
                    return(torrent);
                }
                else
                {
                    // Base 32 not raw hash
                    reg   = new Regex("BTIH:([A-Z0-9]{32})");
                    url   = InputUrl.ToString().ToUpperInvariant();
                    match = reg.Match(url);

                    if (!match.Success)
                    {
                        return(null);
                    }

                    var    data    = Base32Helper.ToBytes(match.Groups[1].Value);
                    string hash    = BitConverter.ToString(data).Replace("-", string.Empty);
                    var    torrent = result.Result.Torrents.OrderByDescending(t => t.AddedDate).FirstOrDefault(item => string.Equals(item.Hash, hash, StringComparison.OrdinalIgnoreCase));
                    return(torrent);
                }
            }

            return(null);
        }