Skip to content

Instantly share code, notes, and snippets.

@rodrigorgs
Created November 5, 2022 01:23
Show Gist options
  • Save rodrigorgs/e12a58066de4087e18dcd9f24f662a36 to your computer and use it in GitHub Desktop.
Save rodrigorgs/e12a58066de4087e18dcd9f24f662a36 to your computer and use it in GitHub Desktop.
# Converte um backup do DataCifra (arquivo .dtcxlist) em texto simples,
# em um formato que pode ser importado pelo Cifra+
#
import plistlib
import base64
import NSKeyedUnArchiver
import sys
import os
import unicodedata
import re
from pathlib import Path
def strip_accents(s):
return ''.join(c for c in unicodedata.normalize('NFD', s)
if unicodedata.category(c) != 'Mn')
def normaliza(s):
x = strip_accents(s)
x = re.sub(r'[^\w\s]', '_', x)
return x[:250]
def main():
try:
FILENAME = sys.argv[1]
except IndexError:
print("Você deve informar o nome do arquivo .dtcxlist a ser convertido.")
sys.exit(1)
OUTPUT_DIR = 'cifra-plus'
with open(FILENAME, 'rb') as f:
pl = plistlib.load(f)
Path('cifra-plus').mkdir(exist_ok=True)
for song in pl:
d = NSKeyedUnArchiver.unserializeNSKeyedArchiver(song)
artista = d['referencia']
titulo = d['titulo']
letra = d['letra']
filename = f'{normaliza(artista)} - {normaliza(titulo)}.txt'
print(filename)
with open(os.path.join(OUTPUT_DIR, filename), 'w') as f:
f.write(titulo + '\n')
f.write(artista + '\n')
f.write('\n')
f.write(letra)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment