#!/usr/bin/python

# usage: cppls -h hostname -f filename.pls destination_dir

import sys, getopt, re

def main(argv):
  playlist = "playlist.pls"
  host = "127.0.0.1"

  try:
    opts, args = getopt.getopt(argv, "h:f:", ["host", "file"])
  except getopt.GetoptError:
    sys.exit(2)

  for opt, arg in opts:
    if opt in ("-h", "--host"):
      host = arg
    elif opt in ("-f", "--file"):
      playlist = arg
 
  destdir = "".join(args)

  f = open(playlist)

  re_file = re.compile('^File\d+=');
  re_split = re.compile('=');
  for line in f:
    if re_file.match(line):
      junk, filename = re_split.split(line) 
      filename = filename.rstrip('\n')
      c = "scp %s:\"%s\" %s" % (host, filename, destdir) 
      print c

if __name__ == "__main__":
  main(sys.argv[1:])
