コード例 #1
0
    def _test(self, host, port, username, password):
        url = self._url(host, port)
        try:
            client = self._client(username, password, host, port, timeout=10)
            response = client.session.get()

        except shifter.urllib2.socket.timeout:
            return (False, {},
                    'Connetion failure: Timeout. Check host and port.')

        except shifter.urllib2.URLError as e:
            msg = 'Connetion failure: %s. Check host and port.'
            return (False, {}, msg % e.reason)

        except shifter.TransmissionRPCError:
            msg = 'Connetion failure: %s. Check username and password.'
            return (False, {}, msg % e.message)

        plugins.log('Transmission test url %s' % url,
                    censor={self.c.password: '******'})

        if response:
            return (True, {}, 'Connetion Established!')

        return (False, {}, 'Unknown response from Transmisstion')
コード例 #2
0
    def _url(self, host=None, port=0):
        if not host:
            host = self.c.host

            if not host.startswith('http'):
                plugins.log('Fixing url. Adding http://')
                self.c.host = 'http://%s' % host

            host = self.c.host

        else:
            if not host.startswith('http'):
                host = 'http://%s' % host

        if not port:
            port = self.c.port

        return '%s:%s/transmission/rpc' % (host, port)
コード例 #3
0
    def addDownload(self, download):
        client = self._client()
        cat = self._getCategory(download.element)

        kwargs = {}
        if self.c.download_path:
            path = self.c.download_path

            if self.c.category_folders and cat is not None:
                path = '%s/%s' % (path, cat)

            kwargs['download-dir'] = path

        try:
            r = client.torrent.add(filename=download.url, **kwargs)
        except:
            msg = ('Unable to connect to Transmission. Most likely a timout.'
                   'Is Transmission running?')
            plugins.log.error(msg)
            return False

        if not r:
            msg = ('Unable to add torrent to Transmission. Is it a dupe?')
            plugins.log.error(msg)
            return False

        plugins.log('Transmission ID: %s' % r['id'])
        plugins.log('Transmission Name: %s' % r['name'])
        plugins.log('Transmission Hash: %s' % r['hash_string'])
        plugins.log.info('Torrent added to Transmission')

        download.external_id = r['id']
        return True
コード例 #4
0
ファイル: PublicHD.py プロジェクト: carze/XDM-Plugins
    def searchForElement(self, element):
        downloads = []
        category = str(self._getCategory(element))
        if category != 'Movies':
            log("Can only search for movies on PublicHD!")
            return []
        terms = element.getSearchTerms()
        log.debug('terms: %s' % terms)
        for term in terms:
            payload = {
                'page':'torrents',
                'search': term,
                'active': 1,
            }
            response = requests.get(self._seachUrl, params=payload, verify=self.c.verify_ssl_certificate)
            log("PublicHD final search for term %s url %s" % (term, response.url))

            soup = BeautifulSoup(response.text)

            entries = soup.find('table', attrs = {'id': 'torrbg'}).find_all('tr')

            for result in entries:
                info_url = result.find(href = re.compile('torrent-details'))
                magnet = result.find(href = re.compile('magnet:'))
                download = result.find(href = re.compile(r'\.torrent$'))

                if info_url and download and magnet:
                    log("%s found on PublicHD: %s" % (element.type, info_url.string))
                    dl_url = download['href']
                    if self.c.use_torrentcache:
                        dl_url = self._decodeMagnet(magnet['href'])
                        log.debug('PublicHD: magnet link \'%s\' translated to url \'%s\'' % (magnet['href'], dl_url))

                    size = result.find_all('td')[7].find('b').string
                    info = parse_qs(info_url['href'])

                    d = Download()
                    d.url = dl_url
                    d.name = info_url.string
                    d.element = element
                    d.size = self._decodeSize(size)
                    d.external_id = info['id'][0]
                    d.type = 'de.lad1337.torrent'
                    downloads.append(d)
        return downloads