#!/usr/bin/env python
# encoding=utf-8

"""ardj metadata source for ezstream.

To let ezstream retrieve track metadata, install this script as follows:

    <metadata_progname>/this/script</metadata_progname>
    <metadata_format>@t@</metadata_format>
"""

import sys


try:
    from ardj.tracks import get_last_track

    if len(sys.argv) != 2:
        print "ardj is playing"
        exit(0)

    track = get_last_track()
    if track is None:
        print "unknown track"
        exit(0)

    if sys.argv[1] == "artist":
        print track["artist"].encode("utf-8")
    elif sys.argv[1] == "title":
        print track["title"].encode("utf-8")
    else:
        print "unknown"

except Exception, e:
    print >> sys.stderr, "ardj-next: %s: %s" % (e.__class__.__name__, e)

    print "error"
