#!/usr/bin/env python
#
# $Source: /home/blais/repos/cvsroot/arubomu/bin/arubomu-xmms-durations,v $
# $Id: arubomu-xmms-durations,v 1.6 2004/02/16 01:02:57 blais Exp $
#

"""arubomu-xmms-durations

Extract the durations from the currently running xmms playlist.

"""

__version__ = "$Revision: 1.6 $"
__author__ = "Martin Blais <blais@furius.ca>"


import xmms


def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip(), version=__version__)
    parser.add_option('-s', '--short', action='store_true',
                      help="Print only the durations, not the empty songs "
                      "and titles.")
    opts, args = parser.parse_args()

    if not opts.short:
        print '   <songs>'
    sess = 0
    n = xmms.get_playlist_length(sess)
    for i in range(n):
        title = xmms.get_playlist_title(i, sess)
        time = xmms.get_playlist_time(i, sess)
        ms = time % 1000
        secs = time / 1000
        min = secs / 60
        secs = secs % 60
        ptime = '%d:%02d' % (min, secs)
        if not opts.short:
            print '      <song no="%d">' % (i+1)
            print '         <title>%s</title>' % title

        print '         <duration>%s</duration>' % ptime

        if not opts.short:
            print '      </song>'
    if not opts.short:
        print '   </songs>'

if __name__ == '__main__':
    main()
