m4ainfo.py :  » Media-Sound-Audio » Media-Metadata-for-Python » mmpython-0.4.10 » audio » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Media Sound Audio » Media Metadata for Python 
Media Metadata for Python » mmpython 0.4.10 » audio » m4ainfo.py
#!/usr/bin/env python
# Based on a sample implementation posted to daap-dev mailing list by
# Bob Ippolito <bob@redivi.com>
#
# Modifed by Aubin Paul <aubin@outlyer.org> for mmpython/Freevo
#

import struct
from mmpython import mediainfo
import mmpython

#_print = mediainfo._debug

class Mpeg4(mediainfo.MusicInfo):
    def __init__(self, file):
        self.containerTags = ('moov', 'udta', 'trak', 'mdia', 'minf', 'dinf', 'stbl',
                              'meta', 'ilst', '----')
        self.skipTags = {'meta':4 }

        mediainfo.MusicInfo.__init__(self)
        self.valid = 0
        returnval = 0
        while returnval == 0:
            try:
                self.readNextTag(file)
            except ValueError:
                returnval = 1
        if mediainfo.DEBUG and self.valid:
            print self.title
            print self.artist
            print self.album
            print self.year
            print self.encoder

    def readNextTag(self, file):
        length, name = self.readInt(file), self.read(4, file)
        length -= 8
        if length < 0 or length > 1000:
            raise ValueError, "Oops?"
        #print "%r" % str(name) # (%r bytes, starting at %r)" % \
        #  (name, length, file.tell() + 8)
        if name in self.containerTags:
            self.read(self.skipTags.get(name, 0), file)
            data = '[container tag]'
        else:
            data = self.read(length, file)
        if name == '\xa9nam':
            self.title = data[8:]
            self.valid = 1
        if name == '\xa9ART':
            self.artist = data[8:]
            self.valid = 1
        if name == '\xa9alb':
            self.album = data[8:]
            self.valid = 1
        if name == 'trkn':
            # Fix this
            self.trackno = data
            self.valid = 1
        if name == '\xa9day':
            self.year = data[8:]
            self.valid = 1
        if name == '\xa9too':
            self.encoder = data[8:]
            self.valid = 1
        return 0
        
    def read(self, b, file):
        data = file.read(b)
        if len(data) < b:
            raise ValueError, "EOF"
        return data

    def readInt(self, file):
        return struct.unpack('>I', self.read(4, file))[0]
        
mmpython.registertype( 'application/m4a', ('m4a',), mediainfo.TYPE_MUSIC, Mpeg4 )

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.