コード例 #1
0
 def saveTorrent(self, torrentUrl):
     #if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
     if re.match("^magnet\:.+$", torrentUrl):
         self.magnetLink = torrentUrl
         self.magnetToTorrent(torrentUrl)
         self.magnetLink = None
         return self.torrentFile
     else:
         if not xbmcvfs.exists(self.torrentFilesPath):
             xbmcvfs.mkdirs(self.torrentFilesPath)
         torrentFile = localize_path(
             os.path.join(self.torrentFilesPath,
                          self.md5(torrentUrl) + '.torrent'))
         try:
             if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl):
                 log('xbmcvfs.File for %s' % torrentUrl)
                 content = xbmcvfs.File(torrentUrl, "rb").read()
             else:
                 log('request for %s' % torrentUrl)
                 content = self.makeRequest(torrentUrl)
             localFile = xbmcvfs.File(torrentFile, "w+b")
             localFile.write(content)
             localFile.close()
         except Exception, e:
             log('Unable to rename torrent file from %s to %s in InposLoader::saveTorrent. Exception: %s'
                 % (torrentUrl, torrentFile, str(e)))
             return
コード例 #2
0
    def setup_engine(self):
        encryption = Encryption.ENABLED if self.__settings__.getSetting('encryption') == 'true' else Encryption.DISABLED

        if self.__settings__.getSetting("connections_limit") not in ["",0,"0"]:
            connections_limit = int(self.__settings__.getSetting("connections_limit"))
        else:
            connections_limit = None

        use_random_port = True if self.__settings__.getSetting('use_random_port') == 'true' else False

        listen_port=int(self.__settings__.getSetting("listen_port")) if self.__settings__.getSetting(
            "listen_port") != "" else 6881

        if '1' != self.__settings__.getSetting("keep_files") and 'Saved Files' not in self.storageDirectory:
            keep_complete = False
            keep_incomplete = False
        else:
            keep_complete = True
            keep_incomplete = True

        dht_routers = ["router.bittorrent.com:6881", "router.utorrent.com:6881"]
        user_agent = ''
        self.engine = Engine(uri=file_url(localize_path(self.torrentFile)), download_path=self.storageDirectory,
                             connections_limit=connections_limit,
                             encryption=encryption, keep_complete=keep_complete, keep_incomplete=keep_incomplete,
                             dht_routers=dht_routers, use_random_port=use_random_port, listen_port=listen_port,
                             user_agent=user_agent)
コード例 #3
0
 def getContentList(self):
     filelist = []
     for contentId, contentFile in enumerate(self.torrentFileInfo.files()):
         stringdata = {"title": localize_path(contentFile.path), "size": contentFile.size, "ind": int(contentId),
                       'offset': contentFile.offset}
         filelist.append(stringdata)
     return filelist
コード例 #4
0
ファイル: SkorbaLoader.py プロジェクト: gacj22/WizardGacj22
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            self.magnetLink = torrentUrl
            self.magnetToTorrent(torrentUrl)
            self.magnetLink = None
            return self.torrentFile
        else:
            if not xbmcvfs.exists(self.torrentFilesPath):
                xbmcvfs.mkdirs(self.torrentFilesPath)
            torrentFile = localize_path(os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent'))
            try:
                if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl):
                    log('xbmcvfs.File for %s' % torrentUrl)
                    content = xbmcvfs.File(torrentUrl, "rb").read()
                else:
                    log('request for %s' % torrentUrl)
                    content = self.makeRequest(torrentUrl)

                localFile = xbmcvfs.File(torrentFile, "w+b")
                localFile.write(content)
                localFile.close()
            except Exception, e:
                log('Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(e))
                return
            if xbmcvfs.exists(torrentFile):
                try:
                    e=self.lt.bdecode(xbmcvfs.File(torrentFile,'rb').read())
                    self.torrentFileInfo = self.lt.torrent_info(e)
                except Exception, e:
                    log('Exception: ' + str(e))
                    xbmcvfs.delete(torrentFile)
                    return
                if not xbmcvfs.exists(self.torrentFilesPath):
                    xbmcvfs.mkdirs(self.torrentFilesPath)
                newFile = localize_path(self.torrentFilesPath + self.md5(torrentUrl) + '.torrent')
                if newFile != torrentFile:
                    if xbmcvfs.exists(newFile):
                        xbmcvfs.delete(newFile)
                    if not xbmcvfs.exists(newFile):
                        try:
                            xbmcvfs.rename(torrentFile, newFile)
                        except Exception, e:
                            log('Unable to rename torrent file from %s to %s in Torrent::renameTorrent. Exception: %s' %
                                (torrentFile, newFile, str(e)))
                            return
コード例 #5
0
 def saveTorrent(self, torrentUrl):
     #if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
     if re.match("^magnet\:.+$", torrentUrl):
         self.magnetLink = torrentUrl
         self.magnetToTorrent(torrentUrl)
         self.magnetLink = None
         return self.torrentFile
     else:
         if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
         torrentFile = localize_path(os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent'))
         try:
             if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl):
                 log('xbmcvfs.File for %s' % torrentUrl)
                 content = xbmcvfs.File(torrentUrl, "rb").read()
             else:
                 log('request for %s' % torrentUrl)
                 content = self.makeRequest(torrentUrl)
             localFile = xbmcvfs.File(torrentFile, "w+b")
             localFile.write(content)
             localFile.close()
         except Exception, e:
             log('Unable to rename torrent file from %s to %s in InposLoader::saveTorrent. Exception: %s' %
                     (torrentUrl, torrentFile, str(e)))
             return