Example #1
0
def isSameTorrent(torrent1src, torrent2src):
    """
    Compare two torrents to see if they are the same
    """
    
    # Same location
    if torrent1src == torrent2src:
        return True

    metainfo1 = get_metainfo(torrent1src)
    if metainfo1 is None:
        return False
    
    metainfo2 = get_metainfo(torrent2src)
    if metainfo2 is None:
        return False
    
    metainfo_hash1 = sha1(bencode(metainfo1)).hexdigest()
    metainfo_hash2 = sha1(bencode(metainfo2)).hexdigest()
    
    # Hash values for both torrents are the same
    if metainfo_hash1 == metainfo_hash2:
        return True
        
    return False
Example #2
0
    def AddTorrentURL(self, url, dest = None, caller="", cookies = None, label = None):
        # Strip any leading/trailing spaces from the URL
        url = url.strip()
        
        url = url.encode("unicode_escape")
        
        # Copy file from web and call addnewproc
        #########################################
        btmetainfo = get_metainfo(url, style="url", cookies = cookies)
        if btmetainfo is None:
            errormsg = _("Can't get torrent from this URL") + ":\n" + url
            if caller not in ["web", "command"]:
                #display error can't connect to server
                dialog = wx.MessageDialog(None,
                                          errormsg,
                                          _('Error'), 
                                          wx.ICON_ERROR)
                dialog.ShowModal()
                dialog.Destroy()
            return False, errormsg, None

        # Backup metainfo from URL to local directory
        url_splitted = urlsplit(url)
        filename = os.path.split(''.join([unquote(url_splitted[2]), url_splitted[3]]))[1]
        
        return self.AddTorrentFromMetainfo(btmetainfo, filename = filename, dest = dest, caller = caller, label = label)
Example #3
0
 def _announceCopy(self, event = None):
     dl = wx.FileDialog(self.dialog, 
                        _('Choose .torrent file to use'), 
                        '', 
                        '', 
                         _('Torrent Files') + ' (*.torrent)|*.torrent', 
                        wx.OPEN)
     if dl.ShowModal() == wx.ID_OK:
         try:
             metainfo = get_metainfo(dl.GetPath())
             if (metainfo is None):
                 return
             self.annCtl.SetValue(metainfo['announce'])
             if 'announce-list' in metainfo:
                 list = []
                 for tier in metainfo['announce-list']:
                     for tracker in tier:
                         list += [tracker, ', ']
                     del list[-1]
                     list += ['\n']
                 liststring = ''
                 for i in list:
                     liststring += i
                 self.annListCtl.SetValue(liststring+'\n\n')
             else:
                 self.annListCtl.SetValue('')
         except:
             return                
Example #4
0
    def getResponse(self, force = False):
        """
        Get metainfo for the torrent
        """
        if not force and self.status.isActive():
            #active process
            metainfo = self.connection.engine.dow.getResponse()
        else:
            #not active process
            metainfo = get_metainfo(self.src)

        return metainfo
Example #5
0
 def AddTorrentFromBencodeData(self, data, dest = None, caller="", label = None):
     btmetainfo = get_metainfo(data, style="rawdata")
     if btmetainfo is None:
         errormsg = _('Failed : Invalid torrent file')
         
         if caller not in ["web", "command"]:
             #display error can't connect to server
             dialog = wx.MessageDialog(None, 
                                       errormsg, 
                                       _('Error'), 
                                       wx.ICON_ERROR)
             dialog.ShowModal()
             dialog.Destroy()
         return False, errormsg, None
     
     return self.AddTorrentFromMetainfo(btmetainfo, dest = dest, caller = caller, label = label)