def command_auth(args):
    import getpass
    from settings import auth

    _username = getpass.getuser()
    username = raw_input('Enter username (%s): ' % _username)
    if not username:
        username = _username

    password = getpass.getpass('Enter password: ')

    auth(username, password)
    print 'Saved access_token.'


def command_upload(args):
    from upload import upload
    from utils import copy_to_clipboard, open_browser

    if args.compress and args.filename.endswith('.wav'):
        from lame import compress

        compress(args.filename, bitrate=args.bitrate,
                                title=args.title,
                                artist=args.artist,
                                album=args.album,
                                year=args.year)

        args.filename = args.filename.replace('.wav', '.mp3')

    if args.public:
        sharing = 'public'
    else:
        sharing = 'private'

    if args.tags:
        tag_list = [x.strip() for x in args.tags.split(',')]
    else:
        tag_list = []

    res = upload(args.filename, sharing=sharing,
                                      downloadable=args.downloadable,
                                      title=args.title,
                                      description=args.description,
                                      genre=args.genre,
                                      tag_list=tag_list,
                                      artwork=args.artwork)

    url = res['permalink_url']

    print url
    open_browser(url)
    copy_to_clipboard(url)


def main():
    import argparse
    import sys

    from __init__ import __version__

    parser = argparse.ArgumentParser()
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)

    subparsers = parser.add_subparsers()

    auth_parser = subparsers.add_parser('auth', help='authenticate and save access token')
    auth_parser.set_defaults(command=command_auth)

    upload_parser = subparsers.add_parser('upload', help='upload track to soundcloud')
    upload_parser.add_argument('filename', action='store', help='filename to upload')
    upload_parser.add_argument('--public', action='store_true', help='make track public')
    upload_parser.add_argument('--compress', action='store_true', help='compress file')
    upload_parser.add_argument('--no-compress', action='store_false', help='do not compress file')
    upload_parser.set_defaults(compress=True)
    upload_parser.add_argument('--downloadable', action='store_true', help='allow downloads')
    upload_parser.add_argument('--no-downloadable', action='store_false', help='disallow downloads')
    upload_parser.set_defaults(downloadable=True)
    upload_parser.add_argument('--bitrate', default=320, help='bitrate for compression')
    upload_parser.add_argument('--artist', help='id3 title')
    upload_parser.add_argument('--title', help='id3 title')
    upload_parser.add_argument('--album', help='id3 album')
    upload_parser.add_argument('--year', help='id3 year')
    upload_parser.add_argument('--description', help='description of track')
    upload_parser.add_argument('--genre', help='genre of track')
    upload_parser.add_argument('--tags', help='comma separated list of tags')
    upload_parser.add_argument('--artwork', help='artwork to use for song')
    upload_parser.set_defaults(command=command_upload)

    # default to upload command
    if sys.argv[1:]:
        choices = subparsers.choices.keys()
        choices += ['-h', '--help', '-v', '--version']

        # unless recognized command is passed, treat first argument as file to upload
        if sys.argv[1] not in choices:
            sys.argv = [sys.argv[0], 'upload'] + sys.argv[1:]

    args = parser.parse_args()
    args.command(args)

@@ -1,20 +1,43 @@
+import os%0Aimport sys%0A%0A%0A
 def command_auth(arg
@@ -808,16 +808,155 @@
 gs.year)
+%0A        # clear line%0A        rows, columns = os.popen('stty size', 'r').read().split()%0A        sys.stdout.write('%5Cr' + ' ' * int(columns))
 %0A%0A      
@@ -1291,22 +1291,16 @@
         
-      
 download
@@ -1347,38 +1347,32 @@
                 
-      
 title=args.title
@@ -1365,38 +1365,32 @@
 tle=args.title,%0A
-      
                 
@@ -1467,22 +1467,16 @@
         
-      
 genre=ar
@@ -1485,22 +1485,16 @@
 .genre,%0A
-      
         
@@ -1532,30 +1532,24 @@
 t=tag_list,%0A
-      
             
@@ -1700,16 +1700,16 @@
 main():%0A
+
     impo
@@ -1723,23 +1723,8 @@
 arse
-%0A    import sys
 %0A%0A  

Clear line when finished compressing.