Example #1
0
    def _search(self, mdb, query, filename, year=None, auto=False):
        """ Search the movie using all available datasources and let the user
            select a result. Return the choosen datasource and produced movie dict.

        If auto is enabled, directly returns the first movie found.
        """
        choices = []
        for datasource, movie in mdb.search(query, year=year):
            if auto:
                return datasource, movie
            if movie.get('directors'):
                directors = ' by '
                if len(movie['directors']) > 1:
                    directors += '%s and %s' % (', '.join(movie['directors'][0:-1]),
                                                          movie['directors'][-1])
                else:
                    directors += movie['directors'][0]
            else:
                directors = ''
            fmt = u'{title} ({year}){directors} [{datasource}]'
            choices.append(((datasource, movie), fmt.format(title=bold(movie['title']),
                                                            year=movie.get('year', 'Unknown'),
                                                            directors=directors,
                                                            datasource=datasource.name)))

        if not choices:
            printer.p('No results to display for the file: {fn}', fn=filename)
            return None, None

        choices.append((('manual', None), 'Enter manually informations'))
        choices.append((('abort', None), 'None of these'))
        printer.p('Please choose the relevant movie for the file: {fn}', fn=filename, end='\n\n')
        return printer.choice(choices)
Example #2
0
    def run(self, args, config):
        mdb = self.get_metadata_db(args.tree)
        mds = MovieDatasource(config.subsections('datasource'), args.tree, self.profile.object_class)
        total_runtime = 0
        total_size = 0
        count_by_genre = defaultdict(lambda: 0)
        count_by_director = defaultdict(lambda: 0)
        count_by_quality = defaultdict(lambda: 0)
        count_by_container = defaultdict(lambda: 0)
        for movie_hash, movie in mdb.itermovies():
            movie_fullpath = os.path.join(args.tree, '.kolekto', 'movies', movie_hash)
            movie = mds.attach(movie_hash, movie)
            total_runtime += movie.get('runtime', 0)
            total_size += os.path.getsize(movie_fullpath)
            for genre in movie.get('genres', []):
                count_by_genre[genre] += 1
            for director in movie.get('directors', []):
                count_by_director[director] += 1
            count_by_quality[movie.get('quality', 'n/a')] += 1
            count_by_container[movie.get('container', 'n/a')] += 1

        printer.p(bold('Number of movies:'), mdb.count())
        printer.p(bold('Total runtime:'), timedelta(seconds=total_runtime * 60))
        printer.p(bold('Total size:'), humanize_filesize(total_size))
        printer.p(bold('Genres top3:'), format_top(count_by_genre))
        printer.p(bold('Director top3:'), format_top(count_by_director))
        printer.p(bold('Quality:'), format_top(count_by_quality, None))
        printer.p(bold('Container:'), format_top(count_by_container, None))
Example #3
0
    def run(self, args, config):
        mdb = self.get_metadata_db(args.tree)
        hash_by_title = defaultdict(lambda: [])
        for movie_hash, movie in mdb.itermovies():
            hash_by_title[movie.get('title', None), movie.get('year', None)].append(movie_hash)

        for (title, year), hashs in hash_by_title.iteritems():
            if len(hashs) > 1:
                printer.p('{title} ({year}): {hashs}', title=bold(title),
                          year=year, hashs=' '.join(hashs))
Example #4
0
def show(movie):
    """ Show the movie metadata.
    """
    for key, value in sorted(movie.iteritems(), cmp=metadata_sorter, key=lambda x: x[0]):
        if isinstance(value, list):
            if not value:
                continue
            other = value[1:]
            value = value[0]
        else:
            other = []
        printer.p('{key}: {value}', key=bold(key), value=value)
        for value in other:
            printer.p('{pad}{value}', value=value, pad=' ' * (len(key) + 2))