#!/usr/bin/env python

import sys, os.path, json, taglib

def read(path):
	return taglib.File(path).tags

def write(path, tags):
	file = taglib.File(path)
	file.tags = tags
	file.save();

def stringify(data):
	return json.dumps(data, indent=2);

def parse(string):
	return json.loads(string)

if __name__ == "__main__":
	if sys.argv[1] == "--write":
		path = sys.argv[2]
		tags = parse(sys.stdin.read())
		write(path, tags)
	else:
		path = sys.argv[1]
		data = read(path)
		sys.stdout.write(stringify(data))
