Skip to content

Instantly share code, notes, and snippets.

@be1
Last active November 10, 2023 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save be1/241bea4a9f56e6fccaf25db206a074bf to your computer and use it in GitHub Desktop.
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.
#!/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}""")
@be1
Copy link
Author

be1 commented Oct 14, 2020

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

@be1
Copy link
Author

be1 commented Nov 29, 2020

BUG: LaTeX special characters should be escaped :-)

@gfrangias
Copy link

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

@be1
Copy link
Author

be1 commented Nov 10, 2023

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