Exemplo n.º 1
0
    def update_history_processed(self, process_results):
        """Update the history table when we have a processed path + resource."""
        from medusa.schedulers.download_handler import ClientStatus
        status = ClientStatus()

        # Postpone the process, and setting the client_status.
        if not process_results.postpone_any:
            # Resource postprocessed
            status.add_status_string('Postprocessed')

            # If succeeded store Postprocessed + Completed. (384)
            # If failed store Postprocessed + Failed. (272)
            if process_results.result and not process_results.failed:
                status.add_status_string('Completed')
                self.success = True
            else:
                status.add_status_string('Failed')
                self.success = False
            self.update_resource(status)
        else:
            log.info(
                'Postponed PP for: {path} and resource: {resource} keeping existing status',
                {
                    'path': self.path,
                    'resource': self.resource_name
                })
Exemplo n.º 2
0
    def get_status(self, info_hash):
        """
        Return torrent status.

        Status codes:
        ```
            0: "Stopped"
            1: "Check waiting"
            2: "Checking"
            3: "Download waiting"
            4: "Downloading"
            5: "Seed waiting"
            6: "Seeding"
        ```
        """
        torrent = self._torrent_properties(info_hash)
        if not torrent:
            return

        client_status = ClientStatus()
        if torrent['status'] == 4:
            client_status.set_status_string('Downloading')

        if torrent['status'] == 0:
            client_status.set_status_string('Paused')

        # if torrent['status'] == ?:
        #     client_status.set_status_string('Failed')

        if torrent['status'] == 6:
            client_status.set_status_string('Completed')

        if torrent['status'] == 0 and torrent['isFinished']:
            client_status.set_status_string('Seeded')

        # Store ratio
        client_status.ratio = torrent['uploadRatio'] * 1.0

        # Store progress
        client_status.progress = int(torrent['percentDone'] * 100)

        # Store destination
        client_status.destination = torrent['downloadDir']

        # Store resource
        client_status.resource = torrent['name']

        return client_status
Exemplo n.º 3
0
def create_history_item(history_row, compact=False):
    """
    Create a history object, using the data from a history db row item.

    Calculate additional data, where needed.
    :param history_row: a main.db history row.
    :param compact: A boolean indicating if this is used for a compact layout.
    :returns: A dict with history information.
    """
    from medusa.providers import get_provider_class
    from medusa.providers.generic_provider import GenericProvider
    from medusa.tv.series import Series, SeriesIdentifier

    provider = {}
    release_group = None
    release_name = None
    file_name = None
    subtitle_language = None
    show_slug = None
    client_status = None
    show_slug = None
    show_title = 'Missing Show'

    if history_row['action'] in (SNATCHED, FAILED):
        provider_id = GenericProvider.make_id(history_row['provider'])
        provider_class = get_provider_class(provider_id)

        if provider_class:
            provider.update({
                'id': provider_class.get_id(),
                'name': provider_class.name,
                'imageName': provider_class.image_name()
            })
        else:
            provider.update({
                'id': provider_id,
                'name': history_row['provider'],
                'imageName': f'{provider_id}.png'
            })
        release_name = history_row['resource']

    if history_row['action'] == DOWNLOADED:
        release_group = history_row['provider']
        file_name = history_row['resource']

    if history_row['action'] == SUBTITLED:
        subtitle_language = history_row['resource']
        provider['name'] = history_row['provider']

    if history_row['client_status'] is not None:
        status = ClientStatus(status=history_row['client_status'])
        client_status = {
            'status': [s.value for s in status],
            'string': status.status_to_array_string()
        }

    if history_row['indexer_id'] and history_row['showid']:
        identifier = SeriesIdentifier.from_id(history_row['indexer_id'],
                                              history_row['showid'])
        show_slug = identifier.slug
        show = Series.find_by_identifier(identifier)
        if show:
            show_title = show.title

    history_row['episodeTitle'] = '{0} - s{1:02d}e{2:02d}'.format(
        show_title, history_row['season'], history_row['episode'])

    return {
        'series': show_slug,
        'status': history_row['action'],
        'statusName': statusStrings.get(history_row['action']),
        'actionDate': history_row['date'],
        'quality': history_row['quality'],
        'resource': basename(history_row['resource']),
        'size': history_row['size'],
        'properTags': history_row['proper_tags'],
        'season': history_row['season'],
        'episode': history_row['episode'],
        'episodeTitle': history_row['episodeTitle'],
        'manuallySearched': bool(history_row['manually_searched']),
        'infoHash': history_row['info_hash'],
        'provider': provider,
        'releaseName': release_name,
        'releaseGroup': release_group,
        'fileName': file_name,
        'subtitleLanguage': subtitle_language,
        'showSlug': show_slug,
        'showTitle': show_title,
        'providerType': history_row['provider_type'],
        'clientStatus': client_status,
        'partOfBatch': bool(history_row['part_of_batch'])
    }
Exemplo n.º 4
0
    def get_status(self, info_hash):
        """
        Return torrent status.

        Status codes:
        ```
            complete: 'Completed download'
            is_finished: 'Finished seeding (ratio reeched)'

        ```
        """
        torrent = self._torrent_properties(info_hash)
        if not torrent:
            return

        client_status = ClientStatus()
        if torrent.started:
            client_status.set_status_string('Downloading')

        if torrent.paused:
            client_status.set_status_string('Paused')

        # # if torrent['status'] == ?:
        # #     client_status.set_status_string('Failed')

        if torrent.complete:
            client_status.set_status_string('Completed')

        # Store ratio
        client_status.ratio = torrent.ratio

        # Store progress
        if torrent.bytes_done:
            client_status.progress = int(torrent.completed_bytes / torrent.bytes_done * 100)

        # Store destination
        client_status.destination = torrent.directory

        # Store resource
        client_status.resource = torrent.base_filename

        return client_status
Exemplo n.º 5
0
    def get_status(self, info_hash):
        """
        Return torrent status.

        Example result:
        ```
            'hash': '35b814f1438054158b0bd07d305dc0edeb20b704'
            'is_finished': False
            'ratio': 0.0
            'paused': False
            'name': '[FFA] Haikyuu!!: To the Top 2nd Season - 11 [1080p][HEVC][Multiple Subtitle].mkv'
            'stop_ratio': 2.0
            'state': 'Downloading'
            'progress': 23.362499237060547
            'files': ({'index': 0, 'offset': 0, 'path': '[FFA] Haikyuu!!: To ...title].mkv', 'size': 362955692},)
            'is_seed': False
        ```
        """
        if not self.connect():
            raise DownloadClientConnectionException(f'Error while fetching torrent info_hash {info_hash}')

        torrent = self.drpc._torrent_properties(info_hash)
        if not torrent:
            return False

        client_status = ClientStatus()
        if torrent['state'] == 'Downloading':
            client_status.add_status_string('Downloading')

        if torrent['paused']:
            client_status.add_status_string('Paused')

        # TODO: Find out which state the torrent get's when it fails.
        # if torrent[1] & 16:
        #     client_status.add_status_string('Failed')

        if torrent['is_finished']:
            client_status.add_status_string('Completed')

        if torrent['ratio'] >= torrent['stop_ratio']:
            client_status.add_status_string('Seeded')

        # Store ratio
        client_status.ratio = torrent['ratio']

        # Store progress
        client_status.progress = int(torrent['progress'])

        # Store destination
        client_status.destination = torrent['download_location']

        # Store resource
        client_status.resource = torrent['name']

        return client_status
Exemplo n.º 6
0
    def get_status(self, info_hash):
        """
        Return torrent status.

        Status field returns a bitwize value.
        1 = Started
        2 = Checking
        4 = Start after check
        8 = Checked
        16 = Error
        32 = Paused
        64 = Queued
        128 = Loaded
        """
        torrent = self._torrent_properties(info_hash)
        if not torrent:
            return

        client_status = ClientStatus()
        if torrent[1] & 1:
            client_status.set_status_string('Downloading')

        if torrent[1] & 32:
            client_status.set_status_string('Paused')

        if torrent[1] & 16:
            client_status.set_status_string('Failed')

        if torrent[1] & 1 and torrent[4] == 1000:
            client_status.set_status_string('Completed')

        if torrent[1] == 152:  # Checked + Error + Loaded
            # Probably torrent removed.
            client_status.set_status_string('Aborted')

        # Store ratio
        client_status.ratio = torrent[7] / 1000

        # Store progress
        client_status.progress = int(torrent[4] / 10)

        # Store destination
        client_status.destination = torrent[26]

        # Store resource
        client_status.resource = torrent[2]

        return client_status
Exemplo n.º 7
0
def get_status(nzo_id):
    """
    Return nzb status (Paused, Downloading, Downloaded, Failed, Completed).

    :return: ClientStatus object.
    """
    from medusa.schedulers.download_handler import ClientStatus

    nzb = get_nzb_by_id(nzo_id)
    if not nzb:
        return False

    client_status = ClientStatus()

    if nzb['status'] in ('Paused', 'Downloading', 'Downloaded', 'Failed',
                         'Extracting', 'Completed'):
        client_status.set_status_string(nzb['status'])
    else:
        client_status.set_status_string('Downloading')

    # Get Progress
    if nzb['status'] == 'Completed':
        client_status.progress = 100
    elif nzb.get('percentage'):
        client_status.progress = int(nzb['percentage'])

    # Store destination
    storage = nzb.get('storage', '')
    if storage:
        if basename(storage) == nzb.get('name'):
            client_status.destination = storage
            client_status.resource = nzb.get('nzb_name')
        else:
            client_status.destination = dirname(storage)
            client_status.resource = basename(storage)

    return client_status
Exemplo n.º 8
0
    def get_status(self, info_hash):
        """Return torrent status."""
        torrent = self._torrent_properties(info_hash)
        if not torrent:
            return

        client_status = ClientStatus()
        if torrent['state'] in ('downloading', 'checkingDL', 'forcedDL',
                                'metaDL', 'queuedDL'):
            client_status.set_status_string('Downloading')

        # Might want to separate these into a PausedDl and PausedUl in future.
        if torrent['state'] in ('pausedDL', 'stalledDL'):
            client_status.set_status_string('Paused')

        if torrent['state'] == 'error':
            client_status.set_status_string('Failed')

        if torrent['state'] in ('uploading', 'queuedUP', 'checkingUP',
                                'forcedUP', 'stalledUP', 'pausedUP'):
            client_status.set_status_string('Completed')

        # if torrent['ratio'] >= torrent['max_ratio']:
        #     client_status.set_status_string('Seeded')

        # Store ratio
        client_status.ratio = torrent['ratio'] * 1.0

        # Store progress
        client_status.progress = int(torrent['downloaded'] / torrent['size'] *
                                     100) if torrent['size'] else 0

        # Store destination
        client_status.destination = torrent['save_path']

        # Store resource
        client_status.resource = torrent['name']

        log.info('Qbittorrent torrent: [{name}] using state: [{state}]', {
            'name': torrent['name'],
            'state': torrent['state']
        })

        return client_status
Exemplo n.º 9
0
        def data_generator():
            """Read and paginate history records."""
            start = arg_limit * (arg_page - 1)

            for item in results[start:start + arg_limit]:
                provider = {}
                release_group = None
                release_name = None
                file_name = None
                subtitle_language = None
                show_slug = None
                client_status = None
                show_slug = None
                show_title = 'Missing Show'

                if item['action'] in (SNATCHED, FAILED):
                    provider_id = GenericProvider.make_id(item['provider'])
                    provider_class = get_provider_class(provider_id)

                    if provider_class:
                        provider.update({
                            'id':
                            provider_class.get_id(),
                            'name':
                            provider_class.name,
                            'imageName':
                            provider_class.image_name()
                        })
                    else:
                        provider.update({
                            'id': provider_id,
                            'name': item['provider'],
                            'imageName': f'{provider_id}.png'
                        })
                    release_name = item['resource']

                if item['action'] == DOWNLOADED:
                    release_group = item['provider']
                    file_name = item['resource']

                if item['action'] == SUBTITLED:
                    subtitle_language = item['resource']
                    provider['name'] = item['provider']

                if item['client_status'] is not None:
                    status = ClientStatus(status=item['client_status'])
                    client_status = {
                        'status': [s.value for s in status],
                        'string': status.status_to_array_string()
                    }

                if item['indexer_id'] and item['showid']:
                    identifier = SeriesIdentifier.from_id(
                        item['indexer_id'], item['showid'])
                    show_slug = identifier.slug
                    show = Series.find_by_identifier(identifier)
                    if show:
                        show_title = show.title

                item['episodeTitle'] = '{0} - s{1:02d}e{2:02d}'.format(
                    show_title, item['season'], item['episode'])

                yield {
                    'id': item['rowid'],
                    'series': show_slug,
                    'status': item['action'],
                    'statusName': statusStrings.get(item['action']),
                    'actionDate': item['date'],
                    'quality': item['quality'],
                    'resource': basename(item['resource']),
                    'size': item['size'],
                    'properTags': item['proper_tags'],
                    'season': item['season'],
                    'episode': item['episode'],
                    'episodeTitle': item['episodeTitle'],
                    'manuallySearched': bool(item['manually_searched']),
                    'infoHash': item['info_hash'],
                    'provider': provider,
                    'releaseName': release_name,
                    'releaseGroup': release_group,
                    'fileName': file_name,
                    'subtitleLanguage': subtitle_language,
                    'showSlug': show_slug,
                    'showTitle': show_title,
                    'providerType': item['provider_type'],
                    'clientStatus': client_status,
                    'partOfBatch': bool(item['part_of_batch'])
                }
Exemplo n.º 10
0
def get_status(nzo_id):
    """
    Return nzb status (Paused, Downloading, Downloaded, Failed, Extracting).

    :return: ClientStatus object.
    """
    from medusa.schedulers.download_handler import ClientStatus

    nzb = get_nzb_by_id(nzo_id)
    status = None
    if not nzb:
        return False

    client_status = ClientStatus()
    # Map status to a standard ClientStatus.
    if '/' in nzb['Status']:
        status, _ = nzb['Status'].split('/')
    else:
        status = nzb['Status']

    # Queue status checks (Queued is not recorded as status)
    if status == 'DOWNLOADING':
        client_status.set_status_string('Downloading')

    if status == 'PAUSED':
        client_status.set_status_string('Paused')

    if status == 'UNPACKING':
        client_status.set_status_string('Extracting')

    # History status checks.
    if status == 'DELETED':  # Mostly because of duplicate checks.
        client_status.set_status_string('Aborted')

    if status == 'SUCCESS':
        client_status.set_status_string('Completed')

    if status == 'FAILURE':
        client_status.set_status_string('Failed')

    # Get Progress
    if status == 'SUCCESS':
        client_status.progress = 100
    elif nzb.get('percentage'):
        client_status.progress = int(nzb['percentage'])

    client_status.destination = nzb.get('DestDir', '')

    client_status.resource = nzb.get('NZBFilename')

    return client_status