示例#1
0
 public string MakeUrl(Magnet magnet)
 {
     return string.Format("http://{0}/torrent/{1}.torrent", this.ServiceDomain, magnet.Hash.ToUpper());
 }
示例#2
0
        public static Magnet Parse(string magnetUri)
        {
            Magnet magnet = new Magnet();
            string[] magnetParts, magItem;

            magnet.RawMagnetLink = magnetUri;

            magnetUri = Uri.UnescapeDataString(magnetUri);

            if (!magnetUri.StartsWith("magnet:?"))
                throw new Exception("Geçersiz magnet linki");

            //split magnet parts using ampersand
            magnetParts = BreakString(magnetUri.Replace("magnet:?", ""), '&');

            magnet.Trackers = new List<string>();

            foreach (string part in magnetParts)
            {
                magItem = BreakString(part, '=');

                switch (magItem[0])
                {
                        //client and hash info
                    case "xt":
                        {
                            int hashLoc=2;

                            string[] xtParts = BreakString(magItem[1], ':');

                            if (xtParts[0] == "urn")
                            {
                                //grab magnet client type
                                switch (xtParts[1])
                                {
                                    case "tree":
                                        {
                                            hashLoc++;
                                            magnet.HashType = HashType.TigerTree;
                                        }
                                        break;
                                    case "btih":
                                        magnet.HashType = HashType.BitTorrent;
                                        break;
                                    case "sha1":
                                        magnet.HashType = HashType.Sha1;
                                        break;
                                    case "bitprint":
                                        magnet.HashType = HashType.BitPrint;
                                        break;
                                    case "ed2k":
                                        magnet.HashType = HashType.Ed2k;
                                        break;
                                    case "aich":
                                        magnet.HashType = HashType.Aich;
                                        break;
                                    case "kzhash":
                                        magnet.HashType = HashType.Kazaa;
                                        break;
                                    case "md5":
                                        magnet.HashType = HashType.Md5;
                                        break;
                                }
                            }

                            magnet.Hash = xtParts[hashLoc];

                        }
                        break;
                    case "dn": //display name
                        magnet.Name = magItem[1];
                        break;
                    case "tr": //trackers
                        magnet.Trackers.Add(magItem[1]);
                        break;
                    case "xl":
                    case "as":
                    case "xs":
                    case "kt":
                    case "mt":
                        //Not implemented
                        break;
                }

            }

            if (string.IsNullOrEmpty(magnet.Hash))
                throw new Exception("Geçersiz magnet linki (Hash bilgisi yok)");

            return magnet;
        }