Example #1
0
    def readTrackers(self, torrent):
        torrent = self.readTorrent(torrent)

        if not self.hasTrackers(torrent):
            #try using magnet torrentcollecting url
            sources = self.torrentdb.getTorrentCollecting(
                torrent['torrent_id'])
            for source, in sources:
                if source.startswith('magnet'):
                    dn, xt, trs = MagnetLink.parse_url(source)

                    if len(trs) > 0:
                        if 'info' not in torrent:
                            torrent["info"] = {}

                        torrent["info"]["announce"] = trs[0]
                        torrent["info"]["announce-list"] = [trs]
                    break

        if not self.hasTrackers(torrent):
            #see if we have a TorrentTracker entry
            trackers = self.torrentdb.getTracker(torrent['infohash'])

            if trackers and len(trackers) > 0:
                if 'info' not in torrent:
                    torrent["info"] = {}
                    torrent["info"]["announce"] = ''

                for tracker, tier in trackers:
                    if tier == 0:
                        torrent["info"]["announce"] = tracker
                    else:
                        #tier 1 is actually first in announce-list

                        tier = max(tier - 1, 0)
                        if "announce-list" not in torrent['info']:
                            torrent['info']["announce-list"] = []

                        while len(torrent["info"]["announce-list"]) <= tier:
                            torrent['info']["announce-list"].append([])

                        torrent['info']["announce-list"][tier].append(tracker)

        return torrent
Example #2
0
    def dbreadTrackers(self, torrent):
        announce = announce_list = None
        
        #try using magnet torrentcollecting url
        sources = self.torrentdb.getTorrentCollecting(torrent['torrent_id'])
        for source, in sources:
            if source.startswith('magnet'):
                dn, xt, trs = MagnetLink.parse_url(source)
                
                if len(trs) > 0:
                    if 'info' not in torrent:
                        torrent["info"] = {}
                    
                    announce = trs[0]
                    announce_list = [trs]
                break
        
        if not (announce or announce_list):
            #see if we have a TorrentTracker entry
            trackers = self.torrentdb.getTracker(torrent['infohash'])
        
            if trackers and len(trackers) > 0:
                announce_list = []
                
                for tracker, tier in trackers:
                    if tier == 0:
                        announce = tracker
                    else:
                        #tier 1 is actually first in announce-list
                        tier = max(tier-1, 0)
                        while len(announce_list) <= tier:
                            announce_list.append([])
                        
                        announce_list[tier].append(tracker)
            
        if announce and announce_list:   
            if 'info' not in torrent:
                torrent["info"] = {}

            torrent["info"]["announce"] = announce
            torrent['info']["announce-list"] = announce_list
            
        return torrent
 def readTrackers(self, torrent):
     torrent = self.readTorrent(torrent)
     
     if not self.hasTrackers(torrent):
         #try using magnet torrentcollecting url
         sources = self.torrentdb.getTorrentCollecting(torrent['torrent_id'])
         for source, in sources:
             if source.startswith('magnet'):
                 dn, xt, trs = MagnetLink.parse_url(source)
                 
                 if len(trs) > 0:
                     if 'info' not in torrent:
                         torrent["info"] = {}
                     
                     torrent["info"]["announce"] = trs[0]
                     torrent["info"]["announce-list"] = [trs]
                 break
             
     if not self.hasTrackers(torrent):
         #see if we have a TorrentTracker entry
         trackers = self.torrentdb.getTracker(torrent['infohash'])
         
         if trackers and len(trackers) > 0:
             if 'info' not in torrent:
                 torrent["info"] = {}
                 torrent["info"]["announce"] = ''
         
             for tracker, tier in trackers:
                 if tier == 0:
                     torrent["info"]["announce"] = tracker
                 else:
                     #tier 1 is actually first in announce-list
                     
                     tier = max(tier-1, 0)
                     if "announce-list" not in torrent['info']:
                         torrent['info']["announce-list"] = []
                     
                     while len(torrent["info"]["announce-list"]) <= tier:
                         torrent['info']["announce-list"].append([])
                     
                     torrent['info']["announce-list"][tier].append(tracker)
     
     return torrent