Example #1
0
def track_to_string(track):
    string = []

    for field in SEARCH_FIELDS:
        if field in track:
            value = track[field].encode('utf-8')
            string.append(field.capitalize() + ' = ' + value)

    string.append('Filename = ' + track['filename'])
    string.append('Length = ' + format_length(track['length']))

    return u' | '.join(string)
Example #2
0
def list_tracks(tracks):
    length = 0.0
    summary = {}

    for field in SEARCH_FIELDS:
        summary[field] = []

    print '[lister] listing tracks'

    for track in tracks:
        length += track['length']
        string = []

        for field in SEARCH_FIELDS:
            if field in track:
                value = track[field].encode('utf-8')

                if value not in summary[field]:
                    summary[field].append(value)

                string.append(field.capitalize() + ' = ' + value)

        string.append('Length = ' + format_length(track['length']))
        string.append('Filename = ' + track['filename'].encode('utf-8'))
        string = ' | '.join(string)

        print(string)

    print '[lister] listing summary'
    print 'Number of tracks: %d' % len(tracks)
    print 'Length: ' + format_length(length)

    for field in SEARCH_FIELDS:
        if summary[field]:
            count = len(summary[field])
            values = ' | '.join(sorted(summary[field]))

            print '%ss (%d): %s' % (field.capitalize(), count, values)
Example #3
0
def limit(tracks, total_length):
    """
    Return (tracklist, length) tuple, where tracklist length is less than
    or equal to total_length and length is the formatted tracklist length
    """
    tracklist = []
    length = 0.0

    print '[rolabesti] creating tracklist'

    for track in tracks:
        if track['length'] <= total_length - length:
            length += track['length']
            tracklist.append(track)
        else:
            break

    return tracklist, format_length(length)