Version imprimable du sujet

Cliquez ici pour voir ce sujet dans son format original

Forums MacBidouille _ La Programmation En Général _ [PYTHON] Générer les metadata des pistes pour Audacity

Écrit par : Jaypee 4 Mar 2017, 22:04

Si comme moi vous pratiquez le repiquage de disques vinyle en Flac ou MP3 avec Audacity, une corvée est de préparer les fichiers XML tels celui-ci, un par titre de l' album

Code
<tags>
    <tag name="GENRE" value="Rock"/>
    <tag name="TITLE" value="Come Together"/>
    <tag name="TRACKNUMBER" value="1"/>
    <tag name="ALBUM" value="Abbey Road"/>
    <tag name="YEAR" value="1969"/>
    <tag name="ARTIST" value="The Beatles"/>
</tags>


Le site de référence des collectionneurs de disques noirs est discogs.com, qui propose une API aux développeurs, et chaque album est identifié par un identifiant de "release". La recherche directe de l'album fournit une liste de releases, on ouvre celle de son choix et l'URL se termine par release/<id>. On peut ensuite utiliser ce script Python et passer cet identifiant.
CODE
import urllib2, json, sys

release_id = int(sys.argv[1])
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', 'AudacityTaggerApp/3.0')]
release = json.load(opener.open('https://api.discogs.com/releases/{}'.format(release_id)))

for artist in release['artists']:
aname = artist['name']

album = release['title']
year= release['year']
for genre in release['genres']:
gname = genre

asize = 0
for track in release['tracklist']:
ttitle = track['title']
chars = list(track['position'])
if len(chars) == 2:
[face, pos] = chars
else:
[face, pos10, pos ] = chars
pos = 10 * int(pos10) + int(pos)

if face == 'A':
tposition = pos
asize += 1
else:
tposition = asize + int(pos)

file_name = '{}-{}-{}.xml'.format(aname,album,tposition)
file_io = open(file_name, 'w')
file_io.write( '<tags>\n' )
file_io.write( '\t<tag name="GENRE" value="{}"/>\n'.format(gname) )
file_io.write( '\t<tag name="TITLE" value="{}"/>\n'.format(ttitle))
file_io.write( '\t<tag name="TRACKNUMBER" value="{}"/>\n'.format(tposition) )
file_io.write( '\t<tag name="ALBUM" value="{}"/>\n'.format(album) )
file_io.write( '\t<tag name="YEAR" value="{}"/>\n'.format(year) )
file_io.write( '\t<tag name="ARTIST" value="{}"/>\n'.format(aname) )
file_io.write( '</tags>\n' )
file_io.close()


Exemple d'utilisation
Code
[jaypee:.../Tags & Labels for Audacity]$ python discogs.py 7076251
[jaypee:.../Tags & Labels for Audacity]$ ls -lt The*
-rw-r--r--  1 jaypee  staff  236  4 mar 21:42 The Beatles-Abbey Road-1.xml
-rw-r--r--  1 jaypee  staff  232  4 mar 21:42 The Beatles-Abbey Road-10.xml
-rw-r--r--  1 jaypee  staff  240  4 mar 21:42 The Beatles-Abbey Road-11.xml
-rw-r--r--  1 jaypee  staff  237  4 mar 21:42 The Beatles-Abbey Road-12.xml
-rw-r--r--  1 jaypee  staff  263  4 mar 21:42 The Beatles-Abbey Road-13.xml
-rw-r--r--  1 jaypee  staff  239  4 mar 21:42 The Beatles-Abbey Road-14.xml
-rw-r--r--  1 jaypee  staff  241  4 mar 21:42 The Beatles-Abbey Road-15.xml
-rw-r--r--  1 jaypee  staff  231  4 mar 21:42 The Beatles-Abbey Road-16.xml
-rw-r--r--  1 jaypee  staff  235  4 mar 21:42 The Beatles-Abbey Road-17.xml
-rw-r--r--  1 jaypee  staff  232  4 mar 21:42 The Beatles-Abbey Road-2.xml
-rw-r--r--  1 jaypee  staff  246  4 mar 21:42 The Beatles-Abbey Road-3.xml
-rw-r--r--  1 jaypee  staff  234  4 mar 21:42 The Beatles-Abbey Road-4.xml
-rw-r--r--  1 jaypee  staff  239  4 mar 21:42 The Beatles-Abbey Road-5.xml
-rw-r--r--  1 jaypee  staff  250  4 mar 21:42 The Beatles-Abbey Road-6.xml
-rw-r--r--  1 jaypee  staff  241  4 mar 21:42 The Beatles-Abbey Road-7.xml
-rw-r--r--  1 jaypee  staff  230  4 mar 21:42 The Beatles-Abbey Road-8.xml
-rw-r--r--  1 jaypee  staff  251  4 mar 21:42 The Beatles-Abbey Road-9.xml

Et si on affiche le contenu l'un d'eux:
Code
<tags>
    <tag name="GENRE" value="Rock"/>
    <tag name="TITLE" value="Golden Slumbers"/>
    <tag name="TRACKNUMBER" value="14"/>
    <tag name="ALBUM" value="Abbey Road"/>
    <tag name="YEAR" value="1969"/>
    <tag name="ARTIST" value="The Beatles"/>
</tags>


Fini la dactylographie barbante smile.gif

J-P
PS: La dernière version est sur GitHub: https://github.com/jaypeeds/audacity-meta-tagger

Propulsé par Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)