コード例 #1
0
ファイル: test.py プロジェクト: krl/music-tools
def test_playlist_creators():
  from playlist import transport as ts

  REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json")
  
  valid_song = ts.make_song("Test artist", 200, "Test song")
  invalid_song = {"fisk" : "sylt"}
  invalid_song2 = {"artist" : "Test_artist"}

  assert ts.valid_song(valid_song)
  assert not ts.valid_song(invalid_song)
  assert not ts.valid_song(invalid_song2)

  valid_playlist = ts.make_playlist([valid_song], 
                                 "http://test.com/test.json",
                                 "Test playlist",
                                 ["Albin Stjerna"])

  invalid_playlist = ts.make_playlist([invalid_song, invalid_song2], 
                                 "http://test.com/test.json",
                                 "Test playlist",
                                 ["Albin Stjerna"])

  assert ts.valid_playlist(valid_playlist)
  assert not ts.valid_playlist(invalid_playlist)
コード例 #2
0
ファイル: pldc.py プロジェクト: albins/music-tools
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)