Exemplo n.º 1
0
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            torrentFile = self.magnetToTorrent(torrentUrl)
            content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
        else:
            torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5(
                torrentUrl) + '.torrent'
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(file_decode(torrentUrl), "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        f = gzip.GzipFile(fileobj=buf)
                        content = f.read()
                    else:
                        content = result.read()

                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
Exemplo n.º 2
0
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            torrentFile = self.magnetToTorrent(torrentUrl)
            content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
        else:
            torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + self.md5(
                torrentUrl) + '.torrent'
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(file_decode(torrentUrl),
                                           "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        f = gzip.GzipFile(fileobj=buf)
                        content = f.read()
                    else:
                        content = result.read()

                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
Exemplo n.º 3
0
    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 = self.torrentFilesPath + self.md5(
                torrentUrl) + '.torrent'
            try:
                if not re.match("^http\:.+$", torrentUrl):
                    content = xbmcvfs.File(file_decode(torrentUrl), "rb").read()
                else:
                    request = urllib2.Request(torrentUrl)
                    request.add_header('Referer', torrentUrl)
                    request.add_header('Accept-encoding', 'gzip')
                    result = urllib2.urlopen(request)
                    if result.info().get('Content-Encoding') == 'gzip':
                        buf = StringIO(result.read())
                        f = gzip.GzipFile(fileobj=buf)
                        content = f.read()
                    else:
                        content = result.read()

                localFile = xbmcvfs.File(torrentFile, "w+b")
                localFile.write(content)
                localFile.close()
            except Exception, e:
                print 'Unable to save torrent file from "' + torrentUrl + '" to "' + torrentFile + '" in Torrent::saveTorrent' + '. Exception: ' + str(
                    e)
                return
            if xbmcvfs.exists(torrentFile):
                try:
                    self.torrentFileInfo = self.lt.torrent_info(file_decode(torrentFile))
                except Exception, e:
                    print 'Exception: ' + str(e)
                    xbmcvfs.delete(torrentFile)
                    return
                baseName = file_encode(os.path.basename(self.getFilePath()))
                if not xbmcvfs.exists(self.torrentFilesPath):
                    xbmcvfs.mkdirs(self.torrentFilesPath)
                newFile = self.torrentFilesPath + self.md5(baseName) + '.' + self.md5(
                    torrentUrl) + '.torrent'  # + '.'+ baseName
                if not xbmcvfs.exists(newFile):
                    xbmcvfs.delete(newFile)
                if not xbmcvfs.exists(newFile):
                    try:
                        xbmcvfs.rename(torrentFile, newFile)
                    except Exception, e:
                        print 'Unable to rename torrent file from "' + torrentFile + '" to "' + newFile + '" in Torrent::renameTorrent' + '. Exception: ' + str(
                            e)
                        return
Exemplo n.º 4
0
 def magnetToTorrent(self, magnet):
     self.magnetLink = magnet
     self.initSession()
     torrentInfo = self.getMagnetInfo()
     try:
         torrentFile = self.lt.create_torrent(torrentInfo)
         baseName = os.path.basename(self.storageDirectory + os.sep + torrentInfo.files()[0].path)
         if not xbmcvfs.exists(self.torrentFilesPath):
             xbmcvfs.mkdirs(self.torrentFilesPath)
         self.torrentFile = self.torrentFilesPath + self.md5(baseName) + '.torrent'
         torentFileHandler = xbmcvfs.File(self.torrentFile, "w+b")
         torentFileHandler.write(self.lt.bencode(torrentFile.generate()))
         torentFileHandler.close()
         self.torrentFileInfo = self.lt.torrent_info(file_decode(self.torrentFile))
     except:
         xbmc.executebuiltin("Notification(%s, %s, 7500)" % (Localization.localize('Error'), Localization.localize(
             'Can\'t download torrent, probably no seeds available.')))
         self.torrentFileInfo = torrentInfo
Exemplo n.º 5
0
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            torrentFile = self.magnetToTorrent(torrentUrl)
            content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
        else:
            torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + 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
Exemplo n.º 6
0
    def saveTorrent(self, torrentUrl):
        if re.match("^magnet\:.+$", torrentUrl):
            torrentFile = self.magnetToTorrent(torrentUrl)
            content = xbmcvfs.File(file_decode(torrentFile), "rb").read()
        else:
            torrentFile = self.storageDirectory + os.sep + self.torrentFilesDirectory + os.sep + 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
Exemplo n.º 7
0
                pass

        try:
            self.lt = libtorrent
            del libtorrent
        except:
            xbmcgui.Dialog().ok(Localization.localize('Python-Libtorrent Not Found'),
                                Localization.localize(self.platform["message"][0]),
                                Localization.localize(self.platform["message"][1]))
            return

        self.storageDirectory = storageDirectory
        self.torrentFilesPath = os.path.join(self.storageDirectory, torrentFilesDirectory) + os.sep
        if xbmcvfs.exists(torrentFile):
            self.torrentFile = torrentFile
            self.torrentFileInfo = self.lt.torrent_info(file_decode(self.torrentFile))
        elif re.match("^magnet\:.+$", torrentFile):
            self.magnetLink = torrentFile

    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 = self.torrentFilesPath + self.md5(
                torrentUrl) + '.torrent'
            try: