#!/usr/bin/env python
#
# $Source: /home/blais/repos/cvsroot/arubomu/old/bin/fix-cdindex,v $
# $Id: fix-cdindex,v 1.1 2004/02/15 21:59:21 blais Exp $
#

"""fix-discs [<options>] <file>

Attempt to remove discs field from album.

"""

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


import sys
from pprint import pprint

from elementtree.ElementTree import Element, ElementTree
from elementtree_pretty import write_pretty

from arubomu import cdindex




def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip(), version=__version__)
    opts, args = parser.parse_args()
    
    if len(args) != 1:
        raise parser.error("Please specify a single input file.")
    fn = args[0]

    albumlist = cdindex.parseFile(fn)

    # clean up reviews
    for a in albumlist:
        if a.reviews:
            a.reviews[0] = '\n  %s\n' % a.reviews[0].strip()

    pel = Element('album-list')
    for a in albumlist:
        pel.append(a.toxml(loose=True))

        

    tree = ElementTree(pel)
    write_pretty(tree, sys.stdout, encoding='ISO-8859-1', indent='   ')
    print
    

    
##     rv = 0
##     discs = tree.find('//album/discs')
##     if discs != None:
##         discs = map(int, discs.text.split(','))
##         discdecl = tree.findall('//album/disc')
##         if len(discdecl) != len(discs):
##             print fn
##             ##print '%s: %s' % (fn, discs)
##             rv = 1

##     return rv
##     tree.write(sys.stdout, encoding='iso-8859-1')
##     print

if __name__ == '__main__':
    main()
