diff --git a/srt2fcp.py b/srt2fcp.py index eb2375b..8396b67 100755 --- a/srt2fcp.py +++ b/srt2fcp.py @@ -265,9 +265,9 @@ sequence_template = ''' def wrap_text(start, end, text, fontsize=30): margin = 40 width = 640 - #font = os.path.join(base, 'DejaVuSansCondensedBold.ttf') - font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf' - + font = os.path.join(base, 'DejaVuSansCondensedBold.ttf') + if not os.path.exists(font): + font = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf' n = 10 alltxt = [] text = ox.strip_tags(ox.decode_html(text)) @@ -295,8 +295,11 @@ class Fcp: font = 'Courier New' #font = 'Lucida Grande' - def __init__(self): - pass + def __init__(self, size=None, font=None): + if size is not None: + self.fontsize = size + if font is not None: + self.font = font def add_srt(self, srt, wrap=True): data = ox.srt.load(srt) @@ -343,19 +346,22 @@ class Fcp: f.write(s) f.write(fcp_footer) + if __name__ == '__main__': usage = "usage: %prog srtfile" parser = OptionParser(usage=usage) parser.add_option('-w', '--wrap', dest='wrap', help='rewrap text', action="store_true") + parser.add_option('-s', '--size', dest='size', help='font size, default=18', type=int, default=18) + parser.add_option('-f', '--font', dest='font', help='font name, default="Courier New"', type=str, default='Courier New') (opts, args) = parser.parse_args() - + if not args: parser.print_help() sys.exit() - + srt = args[0] output = srt.replace('.srt', '') + '.xml' - fcp = Fcp() + fcp = Fcp(font=opts.font, size=int(opts.size)) fcp.add_srt(srt, opts.wrap) fcp.save(output)