Beispiel #1
0
def exportm3u(tags, tofile, format = None, reldir = False, winsep=False):
    header = ['#EXTM3U']

    if reldir:
        reldir = os.path.dirname(os.path.abspath(tofile))
        filenames = [relpath(f.filepath, reldir) for f in tags]
    else:
        filenames = [f.filepath for f in tags]

    if winsep:
        filenames = [f.replace('/', '\\') for f in filenames]

    if format is None:
        text = '\n'.join(header + filenames)
    else:
        text = header
        extinfo = ('#EXTINF: %s, %s' % (str(lnglength(f.length)),
            encode_fn(tagtofilename(format, f, False))) for f in tags)
        [text.extend([z,y]) for z,y in zip(extinfo, filenames)]
        text = '\n'.join(text)

    playlist = open(tofile, 'w')
    playlist.write(text)
    playlist.close()
Beispiel #2
0
time_fields = [
    '__added',
    '__lastplayed',
    '__laststarted',
]
timefunc = lambda key: lambda value: {'~#%s' % key[2:]: lngtime(value)}
revmapping = dict([(key, timefunc(key)) for key in time_fields])
revmapping.update({
    'track': lambda value: {
        'tracknumber': value
    },
    '__bitrate': lambda value: {
        '~#bitrate': lngfrequency(value)
    },
    '__length': lambda value: {
        '~#length': lnglength(value)
    },
    'playcount': lambda value: {
        '~#playcount': int(value)
    },
    'rating': lambda value: {
        '~#rating': float(value)
    },
    '__skipcount': lambda value: {
        '~#skipcount': int(value)
    },
    '__mountpoint': lambda value: {
        '~mountpoint': value
    },
    '__modified': lambda value: {
        '~#mtime': lngtime(value)
    '~#length': lambda value: {'__length': strlength(value)},
    '~#playcount': lambda value: {'playcount': [unicode(value)]},
    '~#rating': lambda value: {'rating': [unicode(value)]},
    '~#skipcount': lambda value: {'__skipcount': [unicode(value)]},
    '~mountpoint': lambda value: {'__mountpoint': value},
    '~#mtime': lambda value : {'__modified': strtime(value)},
    '~picture': lambda value: {'__picture': value},
    })

time_fields = ['__added', '__lastplayed', '__laststarted',]
timefunc = lambda key: lambda value : {'~#%s' % key[2:]: lngtime(value)}
revmapping = dict([(key, timefunc(key)) for key in time_fields])
revmapping.update({
    'track': lambda value: {'tracknumber': value},
    '__bitrate' : lambda value: {'~#bitrate': lngfrequency(value)},
    '__length': lambda value: {'~#length': lnglength(value)},
    'playcount': lambda value: {'~#playcount': int(value)},
    'rating': lambda value: {'~#rating': float(value)},
    '__skipcount': lambda value: {'~#skipcount': int(value)},
    '__mountpoint': lambda value: {'~mountpoint': value},
    '__modified': lambda value : {'~#mtime': lngtime(value)},
    '__picture': lambda value: {'~picture': to_string(value)},
    })

class Tag(MockTag):
    """Use as base for all tag classes."""
    mapping = audioinfo.mapping.get('puddletag', {})
    revmapping = audioinfo.revmapping.get('puddletag', {})
    IMAGETAGS = ()

    def __init__(self, libclass, libtags):