Changeset 112a87
- Timestamp:
- 03/17/2017 10:26:17 AM (8 years ago)
- Branches:
- 2.0.x, develop, master
- Children:
- 9e303b
- Parents:
- 642433
- git-author:
- Calum Lind <calumlind+deluge@gmail.com> (11/08/2016 03:44:30 PM)
- git-committer:
- Calum Lind <calumlind+deluge@gmail.com> (03/17/2017 10:26:17 AM)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/common.py
r642433 r112a87 622 622 xt_param = 'xt=urn:btih:' 623 623 dn_param = 'dn=' 624 tr_param = 'tr=' 625 tr0_param = re.compile('^tr.(\d+)=(\S+)') 624 626 if uri.startswith(magnet_scheme): 625 627 name = None 626 628 info_hash = None 629 trackers = {} 630 tier = 0 627 631 for param in uri[len(magnet_scheme):].split('&'): 628 632 if param.startswith(xt_param): … … 640 644 elif param.startswith(dn_param): 641 645 name = unquote_plus(param[len(dn_param):]) 646 elif param.startswith(tr_param): 647 tracker = unquote_plus(param[len(tr_param):]) 648 trackers[tracker] = tier 649 tier += 1 650 elif param.startswith('tr.'): 651 try: 652 tier, tracker = re.match(tr0_param, param).groups() 653 trackers[tracker] = tier 654 except AttributeError: 655 pass 642 656 643 657 if info_hash: 644 658 if not name: 645 659 name = info_hash 646 return {'name': name, 'info_hash': info_hash, 'files_tree': '' }660 return {'name': name, 'info_hash': info_hash, 'files_tree': '', 'trackers': trackers} 647 661 return False 648 662 649 663 650 664 def create_magnet_uri(infohash, name=None, trackers=None): 651 """ 652 Creates a magnet uri 653 654 :param infohash: the info-hash of the torrent 655 :type infohash: string 656 :param name: the name of the torrent (optional) 657 :type name: string 658 :param trackers: the trackers to announce to (optional) 659 :type trackers: list of strings 660 661 :returns: a magnet uri string 662 :rtype: string 663 664 """ 665 from base64 import b32encode 666 uri = 'magnet:?xt=urn:btih:' + b32encode(infohash.decode('hex')) 665 """Creates a magnet uri 666 667 Args: 668 infohash (str): The info-hash of the torrent. 669 name (str, optional): The name of the torrent. 670 trackers (dict, optional): The trackers to announce to. 671 672 Returns: 673 str: A magnet uri string. 674 675 """ 676 677 uri = 'magnet:?xt=urn:btih:' + base64.b32encode(infohash.decode('hex')) 667 678 if name: 668 679 uri = uri + '&dn=' + name 669 680 if trackers: 670 for t in trackers: 671 uri = uri + '&tr=' + t 681 try: 682 for tracker in sorted(trackers, key=trackers.__getitem__): 683 uri = ''.join([uri, '&tr.%d=' % trackers[tracker], tracker]) 684 except TypeError: 685 for tracker in trackers: 686 uri = ''.join([uri, '&tr=', tracker]) 672 687 673 688 return uri
Note:
See TracChangeset
for help on using the changeset viewer.