Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def test_parse_reference_playlist():
  from playlist import transport as ts
  from datetime import date
  REFERENCE_PLAYLIST = os.path.join(TESTDIR, "reference.json")

  playlist = ts.load(REFERENCE_PLAYLIST)
  assert ts.allowed_match("levenshtein", playlist)
  assert playlist['tags'][0] == "ebm"
  assert type(ts.updated(playlist)) == date
  assert ts.valid_playlist(playlist)
Ejemplo n.º 3
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]
Ejemplo n.º 4
0
# -*- mode: Python; encoding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*-
# This is a reference playlist compiler.
import time
import os
import sys
from playlist import transport as ts
from playlist import m3u
from playlist.match import match_transport
from db import rhythmbox as rb
from db import dirtree

RB_DB = os.path.expanduser('~/.local/share/rhythmbox/rhythmdb.xml')
CURRENT_DIR = os.path.dirname(__file__)

if len(sys.argv) > 1 and not len(sys.argv) > 2:
  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"]))