Last active
November 10, 2023 17:37
-
-
Save be1/241bea4a9f56e6fccaf25db206a074bf to your computer and use it in GitHub Desktop.
Quick script to generate a LaTeX 'cd-cover' sheet from a Brasero project file, for music compilations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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[a4paper,landscape]{cd-cover} | |
\\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}""") |
BUG: LaTeX special characters should be escaped :-)
Hello and thank you for these useful scripts!
I would just like to mention that:
- Line 16 should be \documentclass[a4paper,landscape]{cd-cover}, otherwise it defaults to letter size instead of A4
- Line 29 should be \newpage (just a typo)
Best regards,
George
Hello and thank you for these useful scripts!
I would just like to mention that:
1. Line 16 should be \documentclass[a4paper,landscape]{cd-cover}, otherwise it defaults to letter size instead of A4 2. Line 29 should be \newpage (just a typo)
Best regards, George
Hello. Fixed. Please note that a more updated script is available on https://git.noise.rocks/ben/brasero2tex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
brasero2TeX.py project.brasero > project.tex && pdflatex project.tex && lpr project.pdf