leosongwei / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
0 stars 0 forks source link

MP4 'stik' field is not read/written #90

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
mutagen doesn't the 'stik' iTunes tag (TV Show/Movie/Music Video/etc).  I added 
this code, which definitely reads it correctly; I haven't tested writing.

to the cdata class I added:

    byte = staticmethod(lambda data: struct.unpack('b', data)[0])
    ubyte = staticmethod(lambda data: struct.unpack('B', data)[0])

    to_byte = staticmethod(lambda data: struct.pack('<b', data))
    to_ubyte = staticmethod(lambda data: struct.pack('<B', data))

then in mp4.py

    def __parse_int8(self, atom, data):
        self[atom.name] = [cdata.ubyte(value[1]) for
                           value in self.__parse_data(atom, data)]

    def __render_int8(self, key, value):
        try:
            if len(value) == 0:
                return self.__render_data(key, 0x15, "")

            if min(value) < 0 or max(value) >= 2**8:
                raise MP4MetadataValueError(
                    "invalid 8 bit integers: %r" % value)
        except TypeError:
            raise MP4MetadataValueError(
                "must be a list of 8 bit integers")

        values = map(cdata.to_ubyte, value)
        return self.__render_data(key, 0x15, values)

then register the field in __atoms:
        "stik": (__parse_int8, __render_int8),

Original issue reported on code.google.com by arolson...@gmail.com on 16 May 2011 at 3:03

GoogleCodeExporter commented 9 years ago

Original comment by joe.wreschnig@gmail.com on 16 May 2011 at 9:51

GoogleCodeExporter commented 9 years ago
I've been using a slightly extended version of the OP's suggested changes.  
Attached is a patch (with tests) adding support to mutagen.mp4 for several 
iTunes video-related atoms: tvsn, tves, hdvd, stik, rtng.  I didn't patch 
mutagen.m4a since it's deprecated.  Plus, these additional atoms are generally 
only useful for video files with iTunes.  Support for these atoms can be added  
via subclassing, but it would be handy to have them incorporated in a future 
Mutagen.

Original comment by dinkypumpkin on 28 Sep 2011 at 2:16

Attachments:

GoogleCodeExporter commented 9 years ago
mutagen has moved to Bitbucket: https://bitbucket.org/lazka/mutagen/issue/90

Original comment by reiter.christoph@gmail.com on 4 Jul 2014 at 3:40