Beispiel #1
0
    def getAllDownloadStatus(self):

        raw_statuses = self.call("nzb")

        release_downloads = ReleaseDownloadList(self)
        for nzb in raw_statuses.get("nzbs", []):

            # Check status
            status = "busy"
            if nzb["state"] == 20:
                status = "completed"
            elif nzb["state"] in [21, 22, 24]:
                status = "failed"

            release_downloads.append(
                {
                    "id": nzb["id"],
                    "name": nzb["uiTitle"],
                    "status": status,
                    "original_status": nzb["state"],
                    "timeleft": -1,
                    "folder": ss(nzb["destinationPath"]),
                }
            )

        return release_downloads
Beispiel #2
0
    def getAllDownloadStatus(self, ids):

        raw_statuses = self.call('nzb')

        release_downloads = ReleaseDownloadList(self)
        for nzb in raw_statuses.get('nzbs', []):
            if nzb['id'] in ids:

                # Check status
                status = 'busy'
                if nzb['state'] == 20:
                    status = 'completed'
                elif nzb['state'] in [21, 22, 24]:
                    status = 'failed'
    
                release_downloads.append({
                    'id': nzb['id'],
                    'name': nzb['uiTitle'],
                    'status': status,
                    'original_status': nzb['state'],
                    'timeleft':-1,
                    'folder': sp(nzb['destinationPath']),
                })

        return release_downloads
Beispiel #3
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking uTorrent download status.')

        if not self.connect():
            return []

        release_downloads = ReleaseDownloadList(self)

        data = self.utorrent_api.get_status()
        if not data:
            log.error('Error getting data from uTorrent')
            return []

        queue = json.loads(data)
        if queue.get('error'):
            log.error('Error getting data from uTorrent: %s', queue.get('error'))
            return []

        if not queue.get('torrents'):
            log.debug('Nothing in queue')
            return []

        # Get torrents
        for torrent in queue['torrents']:
            if torrent[0] in ids:

                #Get files of the torrent
                torrent_files = []
                try:
                    torrent_files = json.loads(self.utorrent_api.get_files(torrent[0]))
                    torrent_files = [sp(os.path.join(torrent[26], torrent_file[0])) for torrent_file in torrent_files['files'][1]]
                except:
                    log.debug('Failed getting files from torrent: %s', torrent[2])
    
                status = 'busy'
                if (torrent[1] & self.status_flags['STARTED'] or torrent[1] & self.status_flags['QUEUED']) and torrent[4] == 1000:
                    status = 'seeding'
                elif (torrent[1] & self.status_flags['ERROR']):
                    status = 'failed'
                elif torrent[4] == 1000:
                    status = 'completed'
    
                if not status == 'busy':
                    self.removeReadOnly(torrent_files)
    
                release_downloads.append({
                    'id': torrent[0],
                    'name': torrent[2],
                    'status': status,
                    'seed_ratio': float(torrent[7]) / 1000,
                    'original_status': torrent[1],
                    'timeleft': str(timedelta(seconds = torrent[10])),
                    'folder': sp(torrent[26]),
                    'files': '|'.join(torrent_files)
                })

        return release_downloads
Beispiel #4
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking Deluge download status.')

        if not self.connect():
            return []

        release_downloads = ReleaseDownloadList(self)

        queue = self.drpc.get_alltorrents(ids)

        if not queue:
            log.debug('Nothing in queue or error')
            return []

        for torrent_id in queue:
            torrent = queue[torrent_id]

            if not 'hash' in torrent:
                # When given a list of ids, deluge will return an empty item for a non-existant torrent.
                continue

            log.debug('name=%s / id=%s / save_path=%s / move_on_completed=%s / move_completed_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / stop_ratio=%s / is_seed=%s / is_finished=%s / paused=%s', (torrent['name'], torrent['hash'], torrent['save_path'], torrent['move_on_completed'], torrent['move_completed_path'], torrent['hash'], torrent['progress'], torrent['state'], torrent['eta'], torrent['ratio'], torrent['stop_ratio'], torrent['is_seed'], torrent['is_finished'], torrent['paused']))

            # Deluge has no easy way to work out if a torrent is stalled or failing.
            #status = 'failed'
            status = 'busy'
            if torrent['is_seed'] and tryFloat(torrent['ratio']) < tryFloat(torrent['stop_ratio']):
                # We have torrent['seeding_time'] to work out what the seeding time is, but we do not
                # have access to the downloader seed_time, as with deluge we have no way to pass it
                # when the torrent is added. So Deluge will only look at the ratio.
                # See above comment in download().
                status = 'seeding'
            elif torrent['is_seed'] and torrent['is_finished'] and torrent['paused'] and torrent['state'] == 'Paused':
                status = 'completed'

            download_dir = sp(torrent['save_path'])
            if torrent['move_on_completed']:
                download_dir = torrent['move_completed_path']

            torrent_files = []
            for file_item in torrent['files']:
                torrent_files.append(sp(os.path.join(download_dir, file_item['path'])))

            release_downloads.append({
                'id': torrent['hash'],
                'name': torrent['name'],
                'status': status,
                'original_status': torrent['state'],
                'seed_ratio': torrent['ratio'],
                'timeleft': str(timedelta(seconds = torrent['eta'])),
                'folder': sp(download_dir if len(torrent_files) == 1 else os.path.join(download_dir, torrent['name'])),
                'files': '|'.join(torrent_files),
            })

        return release_downloads
Beispiel #5
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking Transmission download status.')

        if not self.connect():
            return []

        release_downloads = ReleaseDownloadList(self)

        return_params = {
            'fields': ['id', 'name', 'hashString', 'percentDone', 'status', 'eta', 'isStalled', 'isFinished', 'downloadDir', 'uploadRatio', 'secondsSeeding', 'seedIdleLimit', 'files']
        }

        session = self.trpc.get_session()
        queue = self.trpc.get_alltorrents(return_params)
        if not (queue and queue.get('torrents')):
            log.debug('Nothing in queue or error')
            return []

        for torrent in queue['torrents']:
            if torrent['hashString'] in ids:
                log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / isStalled=%s / eta=%s / uploadRatio=%s / isFinished=%s / incomplete-dir-enabled=%s / incomplete-dir=%s',
                          (torrent['name'], torrent['id'], torrent['downloadDir'], torrent['hashString'], torrent['percentDone'], torrent['status'], torrent.get('isStalled', 'N/A'), torrent['eta'], torrent['uploadRatio'], torrent['isFinished'], session['incomplete-dir-enabled'], session['incomplete-dir']))

                status = 'busy'
                if torrent.get('isStalled') and not torrent['percentDone'] == 1 and self.conf('stalled_as_failed'):
                    status = 'failed'
                elif torrent['status'] == 0 and torrent['percentDone'] == 1:
                    status = 'completed'
                elif torrent['status'] in [5, 6]:
                    status = 'seeding'

                if session['incomplete-dir-enabled'] and status == 'busy':
                    torrent_folder = session['incomplete-dir']
                else:
                    torrent_folder = torrent['downloadDir']

                torrent_files = []
                for file_item in torrent['files']:
                    torrent_files.append(sp(os.path.join(torrent_folder, file_item['name'])))

                release_downloads.append({
                    'id': torrent['hashString'],
                    'name': torrent['name'],
                    'status': status,
                    'original_status': torrent['status'],
                    'seed_ratio': torrent['uploadRatio'],
                    'timeleft': str(timedelta(seconds = torrent['eta'])),
                    'folder': sp(torrent_folder if len(torrent_files) == 1 else os.path.join(torrent_folder, torrent['name'])),
                    'files': '|'.join(torrent_files)
                })

        return release_downloads
Beispiel #6
0
    def getAllDownloadStatus(self):
        log.debug('Checking rTorrent download status.')

        if not self.connect():
            return False

        try:
            torrents = self.rt.get_torrents()

            release_downloads = ReleaseDownloadList(self)

            for torrent in torrents:
                torrent_files = []
                for file_item in torrent.get_files():
                    torrent_files.append(
                        sp(os.path.join(torrent.directory, file_item.path)))

                status = 'busy'
                if torrent.complete:
                    if torrent.active:
                        status = 'seeding'
                    else:
                        status = 'completed'

                release_downloads.append({
                    'id':
                    torrent.info_hash,
                    'name':
                    torrent.name,
                    'status':
                    status,
                    'seed_ratio':
                    torrent.ratio,
                    'original_status':
                    torrent.state,
                    'timeleft':
                    str(
                        timedelta(
                            seconds=float(torrent.left_bytes) /
                            torrent.down_rate))
                    if torrent.down_rate > 0 else -1,
                    'folder':
                    sp(torrent.directory),
                    'files':
                    '|'.join(torrent_files)
                })

            return release_downloads

        except Exception, err:
            log.error('Failed to get status from rTorrent: %s', err)
            return False
Beispiel #7
0
    def getAllDownloadStatus(self):

        log.debug('Checking Deluge download status.')

        if not self.connect():
            return False

        release_downloads = ReleaseDownloadList(self)

        queue = self.drpc.get_alltorrents()

        if not queue:
            log.debug('Nothing in queue or error')
            return False

        for torrent_id in queue:
            torrent = queue[torrent_id]
            log.debug('name=%s / id=%s / save_path=%s / move_completed_path=%s / hash=%s / progress=%s / state=%s / eta=%s / ratio=%s / stop_ratio=%s / is_seed=%s / is_finished=%s / paused=%s', (torrent['name'], torrent['hash'], torrent['save_path'], torrent['move_completed_path'], torrent['hash'], torrent['progress'], torrent['state'], torrent['eta'], torrent['ratio'], torrent['stop_ratio'], torrent['is_seed'], torrent['is_finished'], torrent['paused']))

            # Deluge has no easy way to work out if a torrent is stalled or failing.
            #status = 'failed'
            status = 'busy'
            if torrent['is_seed'] and tryFloat(torrent['ratio']) < tryFloat(torrent['stop_ratio']):
                # We have torrent['seeding_time'] to work out what the seeding time is, but we do not
                # have access to the downloader seed_time, as with deluge we have no way to pass it
                # when the torrent is added. So Deluge will only look at the ratio.
                # See above comment in download().
                status = 'seeding'
            elif torrent['is_seed'] and torrent['is_finished'] and torrent['paused'] and torrent['state'] == 'Paused':
                status = 'completed'

            download_dir = sp(torrent['save_path'])
            if torrent['move_on_completed']:
                download_dir = torrent['move_completed_path']

            torrent_files = []
            for file_item in torrent['files']:
                torrent_files.append(sp(os.path.join(download_dir, file_item['path'])))

            release_downloads.append({
                'id': torrent['hash'],
                'name': torrent['name'],
                'status': status,
                'original_status': torrent['state'],
                'seed_ratio': torrent['ratio'],
                'timeleft': str(timedelta(seconds = torrent['eta'])),
                'folder': sp(download_dir if len(torrent_files) == 1 else os.path.join(download_dir, torrent['name'])),
                'files': '|'.join(torrent_files),
            })

        return release_downloads
Beispiel #8
0
    def getAllDownloadStatus(self):
        log.debug('Checking rTorrent download status.')

        if not self.connect():
            return False

        try:
            torrents = self.rt.get_torrents()

            release_downloads = ReleaseDownloadList(self)

            for torrent in torrents:
                torrent_files = []
                for file_item in torrent.get_files():
                    torrent_files.append(
                        os.path.join(torrent.directory, file_item.path))

                status = 'busy'
                if torrent.complete:
                    if torrent.active:
                        status = 'seeding'
                    else:
                        status = 'completed'

                release_downloads.append({
                    'id':
                    torrent.info_hash,
                    'name':
                    torrent.name,
                    'status':
                    status,
                    'seed_ratio':
                    torrent.ratio,
                    'original_status':
                    torrent.state,
                    'timeleft':
                    str(
                        timedelta(seconds=float(torrent.left_bytes) /
                                  torrent.down_rate))
                    if torrent.down_rate > 0 else -1,
                    'folder':
                    ss(torrent.directory),
                    'files':
                    ss('|'.join(torrent_files))
                })

            return release_downloads

        except Exception, err:
            log.error('Failed to get status from rTorrent: %s', err)
            return False
Beispiel #9
0
    def getAllDownloadStatus(self):

        log.debug('Checking Transmission download status.')

        if not self.connect():
            return False

        release_downloads = ReleaseDownloadList(self)

        return_params = {
            'fields': ['id', 'name', 'hashString', 'percentDone', 'status', 'eta', 'isStalled', 'isFinished', 'downloadDir', 'uploadRatio', 'secondsSeeding', 'seedIdleLimit', 'files']
        }

        queue = self.trpc.get_alltorrents(return_params)
        if not (queue and queue.get('torrents')):
            log.debug('Nothing in queue or error')
            return False

        for torrent in queue['torrents']:
            log.debug('name=%s / id=%s / downloadDir=%s / hashString=%s / percentDone=%s / status=%s / eta=%s / uploadRatio=%s / isFinished=%s',
                (torrent['name'], torrent['id'], torrent['downloadDir'], torrent['hashString'], torrent['percentDone'], torrent['status'], torrent['eta'], torrent['uploadRatio'], torrent['isFinished']))

            torrent_files = []
            for file_item in torrent['files']:
                torrent_files.append(os.path.normpath(os.path.join(ss(torrent['downloadDir']), ss(file_item['name']))))

            status = 'busy'
            if torrent['isStalled'] and self.conf('stalled_as_failed'):
                status = 'failed'
            elif torrent['status'] == 0 and torrent['percentDone'] == 1:
                status = 'completed'
            elif torrent['status'] in [5, 6]:
                status = 'seeding'

            release_downloads.append({
                'id': torrent['hashString'],
                'name': torrent['name'],
                'status': status,
                'original_status': torrent['status'],
                'seed_ratio': torrent['uploadRatio'],
                'timeleft': str(timedelta(seconds = torrent['eta'])),
                'folder': os.path.normpath(ss(torrent['downloadDir'])) if len(torrent_files) == 1 else os.path.normpath(os.path.join(ss(torrent['downloadDir']), ss(torrent['name']))),
                'files': ss('|'.join(torrent_files))
            })

        return release_downloads
Beispiel #10
0
    def getAllDownloadStatus(self, ids):
        log.debug('Checking rTorrent download status.')

        if not self.connect():
            return []

        try:
            torrents = self.rt.get_torrents()

            release_downloads = ReleaseDownloadList(self)

            for torrent in torrents:
                if torrent.info_hash in ids:
                    torrent_directory = os.path.normpath(torrent.directory)
                    torrent_files = []

                    for file in torrent.get_files():
                        if not os.path.normpath(file.path).startswith(torrent_directory):
                            file_path = os.path.join(torrent_directory, file.path.lstrip('/'))
                        else:
                            file_path = file.path

                        torrent_files.append(sp(file_path))

                    release_downloads.append({
                        'id': torrent.info_hash,
                        'name': torrent.name,
                        'status': self.getTorrentStatus(torrent),
                        'seed_ratio': torrent.ratio,
                        'original_status': torrent.state,
                        'timeleft': str(timedelta(seconds = float(torrent.left_bytes) / torrent.down_rate)) if torrent.down_rate > 0 else -1,
                        'folder': sp(torrent.directory),
                        'files': '|'.join(torrent_files)
                    })

            return release_downloads

        except Exception as err:
            log.error('Failed to get status from rTorrent: %s', err)
            return []
Beispiel #11
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking SABnzbd download status.')

        # Go through Queue
        try:
            queue = self.call({
                'mode': 'queue',
            })
        except:
            log.error('Failed getting queue: %s', traceback.format_exc(1))
            return []

        # Go through history items
        try:
            history = self.call({
                'mode': 'history',
                'limit': 15,
            })
        except:
            log.error('Failed getting history json: %s', traceback.format_exc(1))
            return []

        release_downloads = ReleaseDownloadList(self)

        # Get busy releases
        for nzb in queue.get('slots', []):
            if nzb['nzo_id'] in ids:
                status = 'busy'
                if 'ENCRYPTED / ' in nzb['filename']:
                    status = 'failed'

                release_downloads.append({
                    'id': nzb['nzo_id'],
                    'name': nzb['filename'],
                    'status': status,
                    'original_status': nzb['status'],
                    'timeleft': nzb['timeleft'] if not queue['paused'] else -1,
                })

        # Get old releases
        for nzb in history.get('slots', []):
            if nzb['nzo_id'] in ids:
                status = 'busy'
                if nzb['status'] == 'Failed' or (nzb['status'] == 'Completed' and nzb['fail_message'].strip()):
                    status = 'failed'
                elif nzb['status'] == 'Completed':
                    status = 'completed'

                release_downloads.append({
                    'id': nzb['nzo_id'],
                    'name': nzb['name'],
                    'status': status,
                    'original_status': nzb['status'],
                    'timeleft': str(timedelta(seconds = 0)),
                    'folder': sp(os.path.dirname(nzb['storage']) if os.path.isfile(nzb['storage']) else nzb['storage']),
                })

        return release_downloads
Beispiel #12
0
    def getAllDownloadStatus(self):

        raw_statuses = self.call('nzb')

        release_downloads = ReleaseDownloadList(self)
        for nzb in raw_statuses.get('nzbs', []):

            # Check status
            status = 'busy'
            if nzb['state'] == 20:
                status = 'completed'
            elif nzb['state'] in [21, 22, 24]:
                status = 'failed'

            release_downloads.append({
                'id': nzb['id'],
                'name': nzb['uiTitle'],
                'status': status,
                'original_status': nzb['state'],
                'timeleft':-1,
                'folder': ss(nzb['destinationPath']),
            })

        return release_downloads
Beispiel #13
0
                log.error('Password is incorrect.')
            else:
                log.error('Protocol Error: %s', e)
            return []

        # Get NZBGet data
        try:
            status = rpc.status()
            groups = rpc.listgroups()
            queue = rpc.postqueue(0)
            history = rpc.history()
        except:
            log.error('Failed getting data: %s', traceback.format_exc(1))
            return []

        release_downloads = ReleaseDownloadList(self)

        for nzb in groups:
            try:
                nzb_id = [
                    param['Value'] for param in nzb['Parameters']
                    if param['Name'] == 'couchpotato'
                ][0]
            except:
                nzb_id = nzb['NZBID']

            if nzb_id in ids:
                log.debug('Found %s in NZBGet download queue',
                          nzb['NZBFilename'])
                timeleft = -1
                try:
Beispiel #14
0
                log.error("Password is incorrect.")
            else:
                log.error("Protocol Error: %s", e)
            return False

        # Get NZBGet data
        try:
            status = rpc.status()
            groups = rpc.listgroups()
            queue = rpc.postqueue(0)
            history = rpc.history()
        except:
            log.error("Failed getting data: %s", traceback.format_exc(1))
            return False

        release_downloads = ReleaseDownloadList(self)

        for nzb in groups:
            log.debug("Found %s in NZBGet download queue", nzb["NZBFilename"])
            try:
                nzb_id = [param["Value"] for param in nzb["Parameters"] if param["Name"] == "couchpotato"][0]
            except:
                nzb_id = nzb["NZBID"]

            timeleft = -1
            try:
                if (
                    nzb["ActiveDownloads"] > 0
                    and nzb["DownloadRate"] > 0
                    and not (status["DownloadPaused"] or status["Download2Paused"])
                ):
Beispiel #15
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking NZBGet download status.')

        rpc = self.getRPC()

        try:
            if rpc.writelog('INFO', 'CouchPotato connected to check status'):
                log.debug('Successfully connected to NZBGet')
            else:
                log.info('Successfully connected to NZBGet, but unable to send a message')
        except socket.error:
            log.error('NZBGet is not responding. Please ensure that NZBGet is running and host setting is correct.')
            return []
        except xmlrpclib.ProtocolError as e:
            if e.errcode == 401:
                log.error('Password is incorrect.')
            else:
                log.error('Protocol Error: %s', e)
            return []

        # Get NZBGet data
        try:
            status = rpc.status()
            groups = rpc.listgroups()
            queue = rpc.postqueue(0)
            history = rpc.history()
        except:
            log.error('Failed getting data: %s', traceback.format_exc(1))
            return []

        release_downloads = ReleaseDownloadList(self)

        for nzb in groups:
            try:
                nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0]
            except:
                nzb_id = nzb['NZBID']

            if nzb_id in ids:
                log.debug('Found %s in NZBGet download queue', nzb['NZBFilename'])
                timeleft = -1
                try:
                    if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']):
                        timeleft = str(timedelta(seconds = nzb['RemainingSizeMB'] / status['DownloadRate'] * 2 ^ 20))
                except:
                    pass

                release_downloads.append({
                    'id': nzb_id,
                    'name': nzb['NZBFilename'],
                    'original_status': 'DOWNLOADING' if nzb['ActiveDownloads'] > 0 else 'QUEUED',
                    # Seems to have no native API function for time left. This will return the time left after NZBGet started downloading this item
                    'timeleft': timeleft,
                })

        for nzb in queue: # 'Parameters' is not passed in rpc.postqueue
            if nzb['NZBID'] in ids:
                log.debug('Found %s in NZBGet postprocessing queue', nzb['NZBFilename'])
                release_downloads.append({
                    'id': nzb['NZBID'],
                    'name': nzb['NZBFilename'],
                    'original_status': nzb['Stage'],
                    'timeleft': str(timedelta(seconds = 0)) if not status['PostPaused'] else -1,
                })

        for nzb in history:
            try:
                nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0]
            except:
                nzb_id = nzb['NZBID']

            if nzb_id in ids:
                log.debug('Found %s in NZBGet history. ParStatus: %s, ScriptStatus: %s, Log: %s', (nzb['NZBFilename'] , nzb['ParStatus'], nzb['ScriptStatus'] , nzb['Log']))
                release_downloads.append({
                    'id': nzb_id,
                    'name': nzb['NZBFilename'],
                    'status': 'completed' if nzb['ParStatus'] in ['SUCCESS', 'NONE'] and nzb['ScriptStatus'] in ['SUCCESS', 'NONE'] else 'failed',
                    'original_status': nzb['ParStatus'] + ', ' + nzb['ScriptStatus'],
                    'timeleft': str(timedelta(seconds = 0)),
                    'folder': sp(nzb['DestDir'])
                })

        return release_downloads
Beispiel #16
0
    def getAllDownloadStatus(self):

        log.debug('Checking uTorrent download status.')

        if not self.connect():
            return False

        release_downloads = ReleaseDownloadList(self)

        data = self.utorrent_api.get_status()
        if not data:
            log.error('Error getting data from uTorrent')
            return False

        queue = json.loads(data)
        if queue.get('error'):
            log.error('Error getting data from uTorrent: %s',
                      queue.get('error'))
            return False

        if not queue.get('torrents'):
            log.debug('Nothing in queue')
            return False

        # Get torrents
        for torrent in queue['torrents']:

            #Get files of the torrent
            torrent_files = []
            try:
                torrent_files = json.loads(
                    self.utorrent_api.get_files(torrent[0]))
                torrent_files = [
                    os.path.join(torrent[26], torrent_file[0])
                    for torrent_file in torrent_files['files'][1]
                ]
            except:
                log.debug('Failed getting files from torrent: %s', torrent[2])

            status_flags = {
                "STARTED": 1,
                "CHECKING": 2,
                "CHECK-START": 4,
                "CHECKED": 8,
                "ERROR": 16,
                "PAUSED": 32,
                "QUEUED": 64,
                "LOADED": 128
            }

            status = 'busy'
            if (torrent[1] & status_flags["STARTED"] or torrent[1]
                    & status_flags["QUEUED"]) and torrent[4] == 1000:
                status = 'seeding'
            elif (torrent[1] & status_flags["ERROR"]):
                status = 'failed'
            elif torrent[4] == 1000:
                status = 'completed'

            if not status == 'busy':
                self.removeReadOnly(torrent_files)

            release_downloads.append({
                'id':
                torrent[0],
                'name':
                torrent[2],
                'status':
                status,
                'seed_ratio':
                float(torrent[7]) / 1000,
                'original_status':
                torrent[1],
                'timeleft':
                str(timedelta(seconds=torrent[10])),
                'folder':
                ss(torrent[26]),
                'files':
                ss('|'.join(torrent_files))
            })

        return release_downloads
Beispiel #17
0
                log.error('Password is incorrect.')
            else:
                log.error('Protocol Error: %s', e)
            return []

        # Get NZBGet data
        try:
            status = rpc.status()
            groups = rpc.listgroups()
            queue = rpc.postqueue(0)
            history = rpc.history()
        except:
            log.error('Failed getting data: %s', traceback.format_exc(1))
            return []

        release_downloads = ReleaseDownloadList(self)

        for nzb in groups:
            try:
                nzb_id = [param['Value'] for param in nzb['Parameters'] if param['Name'] == 'couchpotato'][0]
            except:
                nzb_id = nzb['NZBID']

            if nzb_id in ids:
                log.debug('Found %s in NZBGet download queue', nzb['NZBFilename'])
                timeleft = -1
                try:
                    if nzb['ActiveDownloads'] > 0 and nzb['DownloadRate'] > 0 and not (status['DownloadPaused'] or status['Download2Paused']):
                        timeleft = str(timedelta(seconds = nzb['RemainingSizeMB'] / status['DownloadRate'] * 2 ^ 20))
                except:
                    pass
Beispiel #18
0
    def getAllDownloadStatus(self, ids):

        log.debug('Checking uTorrent download status.')

        if not self.connect():
            return []

        release_downloads = ReleaseDownloadList(self)

        data = self.utorrent_api.get_status()
        if not data:
            log.error('Error getting data from uTorrent')
            return []

        queue = json.loads(data)
        if queue.get('error'):
            log.error('Error getting data from uTorrent: %s',
                      queue.get('error'))
            return []

        if not queue.get('torrents'):
            log.debug('Nothing in queue')
            return []

        # Get torrents
        for torrent in queue['torrents']:
            if torrent[0] in ids:

                #Get files of the torrent
                torrent_files = []
                try:
                    torrent_files = json.loads(
                        self.utorrent_api.get_files(torrent[0]))
                    torrent_files = [
                        sp(os.path.join(torrent[26], torrent_file[0]))
                        for torrent_file in torrent_files['files'][1]
                    ]
                except:
                    log.debug('Failed getting files from torrent: %s',
                              torrent[2])

                status = 'busy'
                if (torrent[1] & self.status_flags['STARTED'] or torrent[1]
                        & self.status_flags['QUEUED']) and torrent[4] == 1000:
                    status = 'seeding'
                elif (torrent[1] & self.status_flags['ERROR']):
                    status = 'failed'
                elif torrent[4] == 1000:
                    status = 'completed'

                if not status == 'busy':
                    self.removeReadOnly(torrent_files)

                release_downloads.append({
                    'id':
                    torrent[0],
                    'name':
                    torrent[2],
                    'status':
                    status,
                    'seed_ratio':
                    float(torrent[7]) / 1000,
                    'original_status':
                    torrent[1],
                    'timeleft':
                    str(timedelta(seconds=torrent[10])),
                    'folder':
                    sp(torrent[26]),
                    'files':
                    '|'.join(torrent_files)
                })

        return release_downloads
Beispiel #19
0
    def getAllDownloadStatus(self):

        log.debug('Checking uTorrent download status.')

        if not self.connect():
            return False

        release_downloads = ReleaseDownloadList(self)

        data = self.utorrent_api.get_status()
        if not data:
            log.error('Error getting data from uTorrent')
            return False

        queue = json.loads(data)
        if queue.get('error'):
            log.error('Error getting data from uTorrent: %s', queue.get('error'))
            return False

        if not queue.get('torrents'):
            log.debug('Nothing in queue')
            return False

        # Get torrents
        for torrent in queue['torrents']:

            #Get files of the torrent
            torrent_files = []
            try:
                torrent_files = json.loads(self.utorrent_api.get_files(torrent[0]))
                torrent_files = [os.path.join(torrent[26], torrent_file[0]) for torrent_file in torrent_files['files'][1]]
            except:
                log.debug('Failed getting files from torrent: %s', torrent[2])

            status_flags = {
                "STARTED"     : 1,
                "CHECKING"    : 2,
                "CHECK-START" : 4,
                "CHECKED"     : 8,
                "ERROR"       : 16,
                "PAUSED"      : 32,
                "QUEUED"      : 64,
                "LOADED"      : 128
            }

            status = 'busy'
            if (torrent[1] & status_flags["STARTED"] or torrent[1] & status_flags["QUEUED"]) and torrent[4] == 1000:
                status = 'seeding'
            elif (torrent[1] & status_flags["ERROR"]):
                status = 'failed'
            elif torrent[4] == 1000:
                status = 'completed'

            if not status == 'busy':
                self.removeReadOnly(torrent_files)

            release_downloads.append({
                'id': torrent[0],
                'name': torrent[2],
                'status': status,
                'seed_ratio': float(torrent[7]) / 1000,
                'original_status': torrent[1],
                'timeleft': str(timedelta(seconds = torrent[10])),
                'folder': ss(torrent[26]),
                'files': ss('|'.join(torrent_files))
            })

        return release_downloads