Beispiel #1
0
    def get_local_files(self, config, task):
        cwd = os.getcwd()  # save the current working directory
        entries = aggregate_inputs(task, config['what'])
        result = []
        for entry in entries:
            location = entry.get('location')
            if not location or not os.path.exists(location):
                log.warning('%s is not a local file. Skipping.', entry['title'])
                entry.reject('not a local file')
                continue

            result.append(entry)
            entry['files'] = []

            if os.path.isfile(location):
                entry['files'].append(TorrentMatchFile(location, os.path.getsize(location)))
            else:
                # change working dir to make things simpler
                os.chdir(location)
                # traverse the file tree
                for root, _, files in os.walk('.'):
                    # we only need to iterate over files
                    for f in files:
                        file_path = os.path.join(root, f)
                        # We need normpath to strip out the dot
                        abs_file_path = os.path.normpath(os.path.join(location, file_path))
                        entry['files'].append(
                            TorrentMatchFile(abs_file_path, os.path.getsize(file_path))
                        )

        # restore the working directory
        os.chdir(cwd)

        return result
Beispiel #2
0
    def get_local_files(self, config, task):
        cwd = os.getcwd()  # save the current working directory
        entries = aggregate_inputs(task, config['what'])
        for entry in entries:
            location = entry.get('location')
            if not location or not os.path.exists(location):
                log.warning('%s is not a local file. Skipping.',
                            entry['title'])
                entry.reject('not a local file')
                continue

            entry['files'] = []

            if os.path.isfile(location):
                entry['files'].append(
                    TorrentMatchFile(location, os.path.getsize(location)))
            else:
                # change working dir to make things simpler
                os.chdir(location)
                # traverse the file tree
                for root, _, files in os.walk('.'):
                    # we only need to iterate over files
                    for f in files:
                        file_path = os.path.join(root, f)
                        # We need normpath to strip out the dot
                        abs_file_path = os.path.normpath(
                            os.path.join(location, file_path))
                        entry['files'].append(
                            TorrentMatchFile(abs_file_path,
                                             os.path.getsize(file_path)))

        # restore the working directory
        os.chdir(cwd)

        return entries
Beispiel #3
0
    def on_task_filter(self, task, config):

        fields = config['fields']
        action = config['action']
        all_fields = config['all_fields']

        match_entries = aggregate_inputs(task, config['from'])

        # perform action on intersecting entries
        for entry in task.entries:
            for generated_entry in match_entries:
                log.trace('checking if %s matches %s', entry['title'], generated_entry['title'])
                common = self.entry_intersects(entry, generated_entry, fields, config.get('exact'))
                if common and (not all_fields or len(common) == len(fields)):
                    msg = 'intersects with %s on field(s) %s' % (
                        generated_entry['title'],
                        ', '.join(common),
                    )
                    for key in generated_entry:
                        if key not in entry:
                            entry[key] = generated_entry[key]
                    if action == 'reject':
                        entry.reject(msg)
                    if action == 'accept':
                        entry.accept(msg)
Beispiel #4
0
    def on_task_filter(self, task, config):

        fields = config['fields']
        action = config['action']
        all_fields = config['all_fields']

        match_entries = aggregate_inputs(task, config['from'])

        # perform action on intersecting entries
        for entry in task.entries:
            for generated_entry in match_entries:
                log.trace('checking if %s matches %s', entry['title'], generated_entry['title'])
                common = self.entry_intersects(entry, generated_entry, fields, config.get('exact'), config.get('case_sensitive'))
                if common and (not all_fields or len(common) == len(fields)):
                    msg = 'intersects with %s on field(s) %s' % (
                        generated_entry['title'],
                        ', '.join(common),
                    )
                    for key in generated_entry:
                        if key not in entry:
                            entry[key] = generated_entry[key]
                    if action == 'reject':
                        entry.reject(msg)
                    if action == 'accept':
                        entry.accept(msg)
Beispiel #5
0
    def on_task_input(self, task, config):
        config.setdefault('release_estimations', {})
        if not isinstance(config['release_estimations'], dict):
            config['release_estimations'] = {'mode': config['release_estimations']}

        config['release_estimations'].setdefault('mode', 'strict')
        config['release_estimations'].setdefault('optimistic', '0 days')

        task.no_entries_ok = True
        entries = aggregate_inputs(task, config['what'])
        log.verbose('Discovering %i titles ...', len(entries))
        if len(entries) > 500:
            log.critical('Looks like your inputs in discover configuration produced '
                         'over 500 entries, please reduce the amount!')
        # TODO: the entries that are estimated should be given priority over expiration
        entries = self.interval_expired(config, task, entries)
        estimation_mode = config['release_estimations']
        if estimation_mode['mode'] != 'ignore':
            entries = self.estimated(entries, estimation_mode)
        return self.execute_searches(config, entries, task)
Beispiel #6
0
    def on_task_filter(self, task, config):

        fields = config['fields']
        action = config['action']
        all_fields = config['all_fields']

        if not task.entries:
            logger.trace(
                'Stopping crossmatch filter because of no entries to check')
            return

        match_entries = aggregate_inputs(task, config['from'])

        # perform action on intersecting entries
        for entry in task.entries:
            for generated_entry in match_entries:
                logger.trace('checking if {} matches {}', entry['title'],
                             generated_entry['title'])
                common = self.entry_intersects(
                    entry,
                    generated_entry,
                    fields,
                    config.get('exact'),
                    config.get('case_sensitive'),
                )
                if common and (not all_fields or len(common) == len(fields)):
                    msg = 'intersects with %s on field(s) %s' % (
                        generated_entry['title'],
                        ', '.join(common),
                    )
                    for key in generated_entry:
                        if key not in entry:
                            entry[key] = generated_entry[key]
                    if action == 'reject':
                        entry.reject(msg)
                    if action == 'accept':
                        entry.accept(msg)