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_m3u_parse():
  from playlist.m3u import parse, M3UList
  TEST_PLAYLIST = os.path.join(TESTDIR, "test.m3u")
  try:
    playlist = parse(TEST_PLAYLIST)
    assert type(playlist) == M3UList
    assert playlist.comments[0] == "This is a comment"
    assert playlist[0] == "/music/opeth/white cluster.mp3"
    assert playlist[3] == "/video/mononoke.avi"
    assert len(playlist) == 4
  finally:
    pass
Example #3
0
def test_m3u_write():
  from playlist.m3u import write, M3UList, parse
  from os import remove

  TEMP_FILE = os.path.join(TESTDIR, "m3u_write_test.m3u")

  playlist = M3UList(["/music/file_1.mp3", "/music/file_2.mp3"], comments=["This is a comment", "This is another comment"])
  
  try:
    write(playlist, TEMP_FILE)
    new_playlist = parse(TEMP_FILE)
    assert playlist == new_playlist
    assert len(playlist.comments) == len(new_playlist.comments)
    assert playlist.comments[0] == new_playlist.comments[0]
    
    for comment in playlist.comments:
      assert comment in new_playlist.comments

  finally:
    remove(TEMP_FILE)
Example #4
0
def test_match():
    from playlist import match
    from playlist import transport as ts
    from db import rhythmbox as rb
    from playlist.m3u import parse

    REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json")
    REFERENCE_PLAYLIST_COMPILED_M3U = os.path.join(TESTDIR, "reference.m3u")
    TEST_DB = os.path.join(TESTDIR, "rhythmdb.xml")

    playlist = ts.load(REFERENCE_PLAYLIST)
    songs = rb.get_songs(TEST_DB)

    # This is som preliminary testing that the playlist is actually sane
    # (i.e. contains no missed matches and is the right size.
    matched = match.match_transport(playlist, songs)
    assert len(matched) == len(playlist["playlist"])
    assert not None in matched

    # Here we compare the matched playlist to a hand-compiled m3u list.
    compiled_playlist = parse(REFERENCE_PLAYLIST_COMPILED_M3U)
    for i in xrange(len(matched)):
        assert matched[i] == compiled_playlist[i]