Example #1
0
def main(args):
    if len(args) != 2:
        sys.stderr.write("Usage: pldc <playlist file>.\n")
        sys.exit()
    
    playlist = m3u.parse(args[1])
    
    def mangle_song(s):
        ("Read the metadata from the song in path s, "
         "and mangle it to a valid line for the songs "
         "part of a transport playlist.")

        md = dt.read_metadata_from_file(s)
        return ts.make_song(artist=md['artist'][0],
                            length=md.info.length,
                            title=md['title'][0],
                            album=md.get("album", None)[0])
        

    songs = map(mangle_song, playlist)

    # fixme: these and other options should be provided at command line:
    transport = ts.make_playlist(songs, 
                                 "http://test.example.com/pls",
                                 "description")
    ts.write(transport, sys.stdout)
Example #2
0
def test_transport_write():
    from playlist import transport as ts
    from os import remove

    TEMP_FILE = os.path.join(TESTDIR, "transport_write_test.json")
    REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json")

    playlist = ts.load(REFERENCE_PLAYLIST)
    try:
        ts.write(playlist, TEMP_FILE)
        new_playlist = ts.load(TEMP_FILE)
        assert ts.valid_playlist(new_playlist)
        assert playlist == new_playlist
    finally:
        remove(TEMP_FILE)