#!/usr/local/bin/python2.7

import mpdaddsimilar
import optparse

def main():
    parser = optparse.OptionParser(
                usage = "%prog [OPTIONS]",
                description = "Adds similar tracks to your MPD playlist",
                version = "0.1\nWritten by: Amr Hassan <amr.hassan@gmail.com>"
                )
                
    parser.add_option("-q", "--quantity", type="int", help="how many tracks to add per existing track [default=%default]", default=5)
    parser.add_option("-l", "--position-last", help="put the new tracks at the end of the playlist", action="store_false", dest="relative_position")
    parser.add_option("", "--position-relative", help="put the new tracks after their respective similars [default]", action="store_true", dest="relative_position", default=True)
    parser.add_option("-r", "--range", help="the range of tracks to work on from the current playlist as either a single position \
                                            or a START:STOP range value [default=%default]." +
                                            "Possible values for START include an empty string for the first track, and" +
                                            "possibe value for STOP include an empty track for the last position. Also, " +
                                            "The \"c\" character can be specified in either to indicate the current position."+
                                            "\nExamples (without the brackets):\
                                            %prog -r: for all the tracks\
                                            %prog -r:-3 for all but the last three tracks\
                                            %prog -rc: for all the tracks from the currently playing and onwards".replace("%prog", "mpd-add-similar")
                                            ,type="str", default=":")
    
    (options, args) = parser.parse_args()
    
    print "Computing (it might take a few moments)..."
    mpdaddsimilar.mpd_connect()
    q = mpdaddsimilar.add_similar_tracks(options.range, options.quantity, options.relative_position)
    print "All done. Added %d tracks." %q

main()
