Skip to content

Instantly share code, notes, and snippets.

@be1
Last active Dec 1, 2020
Embed
What would you like to do?
Quick script to generate a LaTeX 'cd-cover' sheet from a Brasero project file, for music compilations.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, re, datetime, urllib.parse, xml.etree.ElementTree as ET
if len(sys.argv) < 2:
sys.exit('Usage: %s brasero.project.file' % sys.argv[0])
tree = ET.ElementTree(file=sys.argv[1])
root = tree.getroot()
label = next(root.iter("label")).text.replace('&', '\\&')
sub = "Compil Benoît"
today = datetime.date.today()
print("""
\\documentclass{cd-cover}[a4paper,landscape]
\\usepackage[french]{babel}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{sans}
\\newcommand{\\TITLE}{""" + label + """}
\\newcommand{\\SUBTITLE}{""" + sub + """}
\\newcommand{\\DATE}{""" + str(today) + """}
\\begin{document}
\\parindent=0pt\\parskip=0pt
\\begin{bookletsheets}
.
\newpage
\\begin{center}
\\begin{framebox}
{\\LARGE \\textbf{\\TITLE}}
\\end{framebox}
\\end{center}
\\vfill
{\\large{\\textbf\\SUBTITLE}}\\hfill{\\large\\DATE}
\\end{bookletsheets}
\\begin{backsheet}{\\hfil\\TITLE\\hfil\\SUBTITLE\\hfil\\DATE}
\\begin{center}
\\textbf{\\TITLE}
\\end{center}
\\begin{enumerate}""")
for e in root.iter("audio"):
title = urllib.parse.unquote(next(e.iter("title")).text).replace('&', '\\&')
artist = urllib.parse.unquote(next(e.iter("artist")).text).replace('&', '\\&')
duration = int (next(e.iter("end")).text) - int (next(e.iter("start")).text)
duration /= 1000000
sec = duration / 1000
m = str(int(sec / 60))
s = int(sec) % 60
if s < 10:
s = "0" + str(s)
else:
s = str(s)
print ("\\item {} ({}) \\dotfill {}:{}".format(title, artist, m, s))
print("""
\\end{enumerate}
\\end{backsheet}
\\end{document}""")
@be1
Copy link
Author

be1 commented Oct 14, 2020

brasero2TeX.py project.brasero > project.tex && pdflatex project.tex && lpr project.pdf

Loading

@be1
Copy link
Author

be1 commented Nov 29, 2020

BUG: LaTeX special characters should be escaped :-)

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment