summaryrefslogtreecommitdiff
path: root/lib/mat.py
diff options
context:
space:
mode:
authorjvoisin2011-08-03 18:39:53 +0200
committerjvoisin2011-08-03 18:39:53 +0200
commitbc2fb9a3944a013e05c2f84c1e324c35c26a1827 (patch)
tree4affa3fe9c077ee121ee8eea218760dac49e54d8 /lib/mat.py
parent73e80a3859da461ca363cde6c4ab050e53159362 (diff)
Add (in xml) the supported fileformat list, and a parser
Diffstat (limited to 'lib/mat.py')
-rw-r--r--lib/mat.py42
1 files changed, 40 insertions, 2 deletions
diff --git a/lib/mat.py b/lib/mat.py
index 8226c7e..8fe6fb4 100644
--- a/lib/mat.py
+++ b/lib/mat.py
@@ -7,6 +7,7 @@
7import os 7import os
8import subprocess 8import subprocess
9import logging 9import logging
10import xml.sax
10 11
11import hachoir_core.cmd_line 12import hachoir_core.cmd_line
12import hachoir_parser 13import hachoir_parser
@@ -45,13 +46,50 @@ except ImportError:
45try: 46try:
46 import mutagen 47 import mutagen
47 STRIPPERS['audio/x-flac'] = audio.FlacStripper 48 STRIPPERS['audio/x-flac'] = audio.FlacStripper
48 STRIPPERS['audio/x-ape'] = audio.Apev2Stripper
49 STRIPPERS['audio/x-wavpack'] = audio.Apev2Stripper
50 STRIPPERS['audio/vorbis'] = audio.OggStripper 49 STRIPPERS['audio/vorbis'] = audio.OggStripper
51except ImportError: 50except ImportError:
52 print('unable to import python-mutagen : limited audio format support') 51 print('unable to import python-mutagen : limited audio format support')
53 52
54 53
54class XMLParser(xml.sax.handler.ContentHandler):
55 '''
56 Parse the supported format xml, and return a corresponding
57 list of dict
58 '''
59 def __init__(self):
60 self.dict = {}
61 self.list = []
62 self.content, self.key = '', ''
63 self.between= False
64
65 def startElement(self, name, attrs):
66 '''
67 Called when entering into xml balise
68 '''
69 self.between = True
70 self.key = name
71 self.content = ''
72
73 def endElement(self, name):
74 '''
75 Called when exiting a xml balise
76 '''
77 if name == 'format': # exiting a fileformat section
78 self.list.append(self.dict.copy())
79 self.dict.clear()
80 else:
81 content = self.content.replace('\n', ' ')
82 self.dict[self.key] = content
83 self.between = False
84
85 def characters(self, characters):
86 '''
87 Concatenate the content between opening and closing balises
88 '''
89 if self.between is True:
90 self.content += characters
91
92
55def secure_remove(filename): 93def secure_remove(filename):
56 ''' 94 '''
57 securely remove the file 95 securely remove the file