コード例 #1
0
ファイル: rtorrent.py プロジェクト: EqUaTe/SickRage
    def _get_auth(self):

        if self.auth is not None:
            return self.auth

        if not self.host:
            return

        self.host = self.host.rstrip('/')

        tp_kwargs = {}
        if settings.TORRENT_AUTH_TYPE and settings.TORRENT_AUTH_TYPE.lower(
        ) != 'none':
            tp_kwargs['authtype'] = settings.TORRENT_AUTH_TYPE

        if not settings.TORRENT_VERIFY_CERT:
            tp_kwargs['check_ssl_cert'] = False

        if self.username and self.password:
            self.auth = RTorrent(self.host,
                                 self.username,
                                 self.password,
                                 True,
                                 tp_kwargs=tp_kwargs or None)
        else:
            self.auth = RTorrent(self.host,
                                 None,
                                 None,
                                 True,
                                 tp_kwargs=tp_kwargs or None)

        return self.auth
コード例 #2
0
    def _get_auth(self):
        self.auth = None

        if self.auth is not None:
            return self.auth

        if not self.host:
            return

        sp_kwargs = {}
        if sickrage.TORRENT_AUTH_TYPE != 'None':
            sp_kwargs[b'authtype'] = sickrage.TORRENT_AUTH_TYPE

        if not sickrage.TORRENT_VERIFY_CERT:
            sp_kwargs[b'check_ssl_cert'] = False

        if self.username and self.password:
            url_parts = self.host.split('//')
            self.auth = RTorrent(
                url_parts[0] +
                "{0}:{1}@".format(self.username, self.password) + url_parts[1])
        else:
            self.auth = RTorrent(self.host)

        return self.auth
コード例 #3
0
ファイル: rtorrent_client.py プロジェクト: 6328484/sickr425
    def _get_auth(self):
        self.auth = None

        if self.auth is not None:
            return self.auth

        if not self.host:
            return

        tp_kwargs = {}
        if sickbeard.TORRENT_AUTH_TYPE is not 'none':
            tp_kwargs[b'authtype'] = sickbeard.TORRENT_AUTH_TYPE

        if not sickbeard.TORRENT_VERIFY_CERT:
            tp_kwargs[b'check_ssl_cert'] = False

        if self.username and self.password:
            self.auth = RTorrent(self.host,
                                 self.username,
                                 self.password,
                                 True,
                                 tp_kwargs=tp_kwargs)
        else:
            self.auth = RTorrent(self.host, None, None, True)

        return self.auth
コード例 #4
0
ファイル: main.py プロジェクト: willko23/CouchPotatoServer
    def connect(self, reconnect=False):
        # Already connected?
        if not reconnect and self.rt is not None:
            return self.rt

        url = cleanHost(self.conf('host'), protocol=True, ssl=self.conf('ssl'))
        parsed = urlparse(url)

        # rpc_url is only used on http/https scgi pass-through
        if parsed.scheme in ['http', 'https']:
            url += self.conf('rpc_url')

        if self.conf('username') and self.conf('password'):
            self.rt = RTorrent(url, self.conf('username'),
                               self.conf('password'))
        else:
            self.rt = RTorrent(url)

        self.error_msg = ''
        try:
            self.rt._verify_conn()
        except AssertionError as e:
            self.error_msg = e.message
            self.rt = None

        return self.rt
コード例 #5
0
    def _get_auth(self):
        if self.auth is not None:
            return self.auth

        if not self.host:
            return

        tp_kwargs = {}
        if app.TORRENT_AUTH_TYPE != 'none':
            tp_kwargs['authtype'] = app.TORRENT_AUTH_TYPE

        if not app.TORRENT_VERIFY_CERT:
            tp_kwargs['check_ssl_cert'] = False
        else:
            if app.SSL_CA_BUNDLE:
                tp_kwargs['check_ssl_cert'] = app.SSL_CA_BUNDLE

        try:
            if self.username and self.password:
                self.auth = RTorrent(self.host,
                                     self.username,
                                     self.password,
                                     True,
                                     tp_kwargs=tp_kwargs)
            else:
                self.auth = RTorrent(self.host, None, None, True)
        except Exception as error:  # No request/connection specific exception thrown.
            raise DownloadClientConnectionException(
                f'Unable to authenticate with rtorrent client: {error}')

        return self.auth
コード例 #6
0
ファイル: rtorrent_client.py プロジェクト: zapru/Medusa
    def _get_auth(self):
        if self.auth is not None:
            return self.auth

        if not self.host:
            return

        tp_kwargs = {}
        if app.TORRENT_AUTH_TYPE != 'none':
            tp_kwargs['authtype'] = app.TORRENT_AUTH_TYPE

        if not app.TORRENT_VERIFY_CERT:
            tp_kwargs['check_ssl_cert'] = False
        else:
            if app.SSL_CA_BUNDLE:
                tp_kwargs['check_ssl_cert'] = app.SSL_CA_BUNDLE

        if self.username and self.password:
            self.auth = RTorrent(self.host,
                                 self.username,
                                 self.password,
                                 True,
                                 tp_kwargs=tp_kwargs)
        else:
            self.auth = RTorrent(self.host, None, None, True)

        return self.auth
コード例 #7
0
    def connect(self):
        # Already connected?
        if self.rt is not None:
            return self.rt

        url = cleanHost(self.conf('host'), protocol=True,
                        ssl=self.conf('ssl')) + self.conf('rpc_url')

        if self.conf('username') and self.conf('password'):
            self.rt = RTorrent(url, self.conf('username'),
                               self.conf('password'))
        else:
            self.rt = RTorrent(url)

        return self.rt
コード例 #8
0
    def connect(self, reconnect=False):
        # Already connected?
        if not reconnect and self.rt is not None:
            return self.rt

        url = cleanHost(self.conf('host'), protocol=True, ssl=self.conf('ssl'))

        # Automatically add '+https' to 'httprpc' protocol if SSL is enabled
        if self.conf('ssl') and url.startswith('httprpc://'):
            url = url.replace('httprpc://', 'httprpc+https://')

        parsed = urlparse(url)

        # rpc_url is only used on http/https scgi pass-through
        if parsed.scheme in ['http', 'https']:
            url += self.conf('rpc_url')

        # Construct client
        self.rt = RTorrent(url, self.getAuth(), verify_ssl=self.getVerifySsl())

        self.error_msg = ''
        try:
            self.rt.connection.verify()
        except AssertionError as e:
            self.error_msg = e.message
            self.rt = None

        return self.rt
コード例 #9
0
ファイル: test_rtorrent.py プロジェクト: singron/yhack-bt
    def setUp(self):
        self.rt = RTorrent()
        self.test_file = "tests/tester.torrent"
        self.test_magnet = "magnet:?xt=urn:btih:f2ed240912dc324d6a30de6811a8747f80b9722d&dn=The+Wolverine+2013+DVDRip+x264+AC3-EVO&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337"

        files = self.rt.get_active_infohashes()
        for f in files:
            self.rt.erase(f)
コード例 #10
0
ファイル: main.py プロジェクト: gthicks/CouchPotatoServer
    def connect(self):
        # Already connected?
        if self.rt is not None:
            return self.rt

        # Ensure url is set
        if not self.conf('url'):
            log.error(
                'Config properties are not filled in correctly, url is missing.'
            )
            return False

        if self.conf('username') and self.conf('password'):
            self.rt = RTorrent(self.conf('url'), self.conf('username'),
                               self.conf('password'))
        else:
            self.rt = RTorrent(self.conf('url'))

        return self.rt
コード例 #11
0
def test_RTorrent(socketpath):
    rtorrent = RTorrent(socketpath)
    assert rtorrent.test_connection() is True
    listViews = rtorrent.get_views()
    print(listViews)
    t0 = time()
    listTorrents = rtorrent.get_torrents()
    t1 = time()
    print(listTorrents, t1 - t0)
    listTorrents = rtorrent.get_torrents()
    t2 = time()
    print(listTorrents, t2 - t1)
コード例 #12
0
    def _authenticate(self):
        """
        Setup connection to rTorrent XMLRPC server
        :return:
        """

        try:
            self.rtorrent = RTorrent(self.url)
        except ConnectionRefusedError as e:
            self.send_log('Failed to connect to rTorrent.  Aborting',
                          'critical')
            sys.exit(1)

        self.send_log('Successfully connected to rTorrent', 'info')
コード例 #13
0
def test_Torrent(socketpath):
    rtorrent = RTorrent(socketpath)
    t = Torrent(rtorrent, info_hash="42B7EFAB0D48757C6D7906272733BD22B57BB182")
コード例 #14
0
def xhr_rtorrentdl():

    # url qualification
    def url_qualify(url_proto, url_host, url_port):

        url_host_part = str(url_host).partition('/')

        # validate host (kinda... just make sure it's not empty)
        if url_host_part[0]:

            # validate port
            if not url_port:

                # for http and https we can assume default service ports
                if url_proto == 'http':
                    url_port = 80
                elif url_proto == 'https':
                    url_port = 443
                else:
                    raise Exception('port must be defined for protocol %s' %
                                    (url_proto))

            else:
                try:
                    url_port = int(url_port)
                except ValueError:
                    raise Exception('port must be a numeric value')

            url_qualified = '%s://%s:%i%s%s' % (url_proto, url_host_part[0],
                                                url_port, url_host_part[1],
                                                url_host_part[2])

            return url_qualified

        else:
            raise Exception('invalid host: %s' % (url_host[0]))

    # initialize empty list, which will be later populated with listing
    # of active torrents
    torrentlist = list()

    # connection flag
    connected = False

    # global rates
    down_rate = 0.0
    up_rate = 0.0

    rtorrent_url = None
    rtorrent_user = None
    rtorrent_password = None

    try:
        if get_setting_value('rtorrent_host') is not None:
            rtorrent_url = url_qualify(get_setting_value('rtorrent_proto'),
                                       get_setting_value('rtorrent_host'),
                                       get_setting_value('rtorrent_port'))
    except Exception as ex:
        log_error(ex)

    try:
        if rtorrent_url:
            # user/password login is not implemented for scgi
            if get_setting_value('rtorrent_proto') != 'scgi':
                rtorrent_user = get_setting_value('rtorrent_user')
                rtorrent_password = get_setting_value('rtorrent_password')

            client = RTorrent(rtorrent_url, rtorrent_user, rtorrent_password,
                              True)

            if client is not None:
                connected = True
                down_rate = client.get_down_rate()
                up_rate = client.get_up_rate()

            # loop through each job and add all torrents to torrentlist()
            for torrent in client.get_torrents():
                # friendly status and time left
                time_left = -1
                if torrent.complete:
                    if torrent.active:
                        status = 'seeding'
                    else:
                        status = 'done'
                else:
                    if torrent.active:
                        if torrent.down_rate > 0:
                            time_left = str(
                                timedelta(seconds=round(
                                    float(torrent.left_bytes) /
                                    torrent.down_rate)))
                            status = 'leeching'
                        else:
                            status = 'waiting'
                    else:
                        status = 'inactive'

                # get torrent file list
                # FIXME takes too much time and is not used anyway for now
                #torrent_filelist = []
                #for file_current in torrent.get_files():
                #	torrent_filelist.append(os.path.join(torrent.directory,file_current.path))

                # what's left?
                progress = float(100.0 / torrent.size_bytes *
                                 (torrent.size_bytes - torrent.left_bytes))

                # append to list
                torrentlist.append({
                    'name': torrent.name,
                    'info_hash': torrent.info_hash,
                    'status': status,
                    'state': torrent.state,
                    'progress': progress,
                    'time_left': time_left,
                    'down_rate': torrent.down_rate,
                    'up_rate': torrent.up_rate,
                    'ratio': torrent.ratio
                    #	'folder': torrent.directory,
                    #	'files': '|'.join(torrent_filelist)
                })

            # no torrents -> empty list
            if not torrentlist.__len__():
                torrentlist = None

    except Exception as ex:
        log_error(ex)
        torrentlist = None

    return render_template(
        'rtorrentdl.html',
        connected=connected,
        torrentlist_scroll=get_setting_value('rtorrent_list_scroll'),
        torrentlist=torrentlist,
        down_rate=down_rate,
        up_rate=up_rate)