diff options
| author | jvoisin | 2011-08-03 18:39:53 +0200 |
|---|---|---|
| committer | jvoisin | 2011-08-03 18:39:53 +0200 |
| commit | bc2fb9a3944a013e05c2f84c1e324c35c26a1827 (patch) | |
| tree | 4affa3fe9c077ee121ee8eea218760dac49e54d8 /lib | |
| parent | 73e80a3859da461ca363cde6c4ab050e53159362 (diff) | |
Add (in xml) the supported fileformat list, and a parser
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mat.py | 42 |
1 files changed, 40 insertions, 2 deletions
| @@ -7,6 +7,7 @@ | |||
| 7 | import os | 7 | import os |
| 8 | import subprocess | 8 | import subprocess |
| 9 | import logging | 9 | import logging |
| 10 | import xml.sax | ||
| 10 | 11 | ||
| 11 | import hachoir_core.cmd_line | 12 | import hachoir_core.cmd_line |
| 12 | import hachoir_parser | 13 | import hachoir_parser |
| @@ -45,13 +46,50 @@ except ImportError: | |||
| 45 | try: | 46 | try: |
| 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 |
| 51 | except ImportError: | 50 | except 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 | ||
| 54 | class 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 | |||
| 55 | def secure_remove(filename): | 93 | def secure_remove(filename): |
| 56 | ''' | 94 | ''' |
| 57 | securely remove the file | 95 | securely remove the file |
