Exemplo n.º 1
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)
Exemplo n.º 2
0
  playlist = ts.load(sys.argv[1])
else:
  sys.stderr.write("Usage: plc <playlist file> <optional output file>. "
                   "If no output file is given, print to stdout.\n")
  sys.exit()

start_time = time.time()

songs = match_transport(playlist, rb.get_songs(RB_DB))

for i, song in enumerate(songs):
  if song == None:
    sys.stderr.write("E: couldn't find %d: %s by %s.\n" % 
                     ((i+1), playlist["playlist"][i]["title"], 
                      playlist["playlist"][i]["artist"]))

m3u_list = m3u.M3UList(songs, name=playlist['description'], 
                       comments=[playlist['comment']])

target = sys.stdout

if len(sys.argv) > 2:
  target = sys.argv[2]

m3u.write(m3u_list, target)

sys.stderr.write("N: Finished matching in %f seconds.\n" %
                 (time.time() - start_time))