Example #1
0
def crawl(path, collection):
    for file_ in walkfiles(path):
        metadata = mutagen.File(file_, easy=True)
        if not metadata:
            # not a media file or file not supported. skip.
            continue

        artist, album, title, year, genre, tracknumber = \
            map(lambda key: get_first_item_or_none(metadata.get(key)),
                ('artist', 'album', 'title', 'date', 'genre', 'tracknumber'))
        if tracknumber is not None:
            # 5/12 -> 5
            tracknumber = tracknumber.split('/')[0]
        duration = metadata.info.length
        rating = 0

        track = {
            'artist': artist,
            'album': album,
            'title': title,
            'year': year,
            'genre': genre,
            'tracknumber': tracknumber,
            'duration': duration,
            'rating': rating,
            'path': file_
        }
        collection.save(track)
Example #2
0
def crawl(collection, path):
    for file_ in walkfiles(path):
        if collection.find_one({'path': file_}):
            continue
        metadata = mutagen.File(file_, easy=True)
        if not metadata:
            continue
        data = dict()
        for key in KEYS:
            try:
                data[key] = metadata[key][0]
            except KeyError:
                    data[key] = 'Unknown'

        track = Track(data['title'],
                    data['artist'],
                    data['album'],
                    data['genre'],
                    data['year'],
                    metadata.info.length,
                    relpath(file_, path),
                    0 
        )
        collection.insert(track.to_dict())