From: pin Date: Fri, 30 Jul 2010 14:00:44 +0000 (+0000) Subject: Affichage du titre de la chanson. X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/commitdiff_plain/fa75b1df8242dff846bd0fd6c2a274170892b73a?ds=inline Affichage du titre de la chanson. git-svn-id: https://svn.cri.ensmp.fr/svn/minwii/trunk@308 fe552daf-6dbe-4428-90eb-1537e0879342 --- diff --git a/src/minwii/loganalyse.py b/src/minwii/loganalyse.py index ec1b025..ab8c819 100755 --- a/src/minwii/loganalyse.py +++ b/src/minwii/loganalyse.py @@ -12,6 +12,8 @@ from minwii.musicxml import musicXml2Song from minwii.globals import PLAYING_MODES from statlib import stats from datetime import timedelta +from xml.etree import ElementTree +import os.path PLAYING_MODES = dict(PLAYING_MODES) @@ -73,6 +75,10 @@ class LogFileAnalyser(LogFileReader) : try : self.mode = mode = self.getMode() results.append(('Mode de jeu', PLAYING_MODES.get(mode, mode))) + + self.songTitle = LogFileAnalyser.getSongTitle(self.getSongFile()) + results.append(('Chanson', self.songTitle)) + for name in self.POSSIBLE_ANALYSES[mode] : meth = getattr(self, name) results.append((meth.__doc__, meth())) @@ -81,6 +87,23 @@ class LogFileAnalyser(LogFileReader) : return results + @staticmethod + def getSongTitle(file) : + if os.path.exists(file) : + it = ElementTree.iterparse(file, ['start', 'end']) + creditFound = False + + for evt, el in it : + if el.tag == 'credit' : + creditFound = True + if el.tag == 'credit-words' and creditFound: + return el.text + if el.tag == 'part-list' : + # plus de chance de trouver un titre + return os.path.basename(file) + else : + return os.path.basename(file) + def _toTimeDelta(self, milliseconds) : duration = milliseconds / 1000. duration = int(round(duration, 0)) diff --git a/src/minwii/logfilereader.py b/src/minwii/logfilereader.py index 50da29c..a5a2d35 100755 --- a/src/minwii/logfilereader.py +++ b/src/minwii/logfilereader.py @@ -177,7 +177,10 @@ class LogFileReader(object) : f = self.logfile f.seek(0) before = f.readline() - after = f.read() + line = f.readline() + while line.startswith('METADATA ') : + line = f.readline() + after = line + f.read() lines = [] for name, value in metadata :