Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to instantiate mutagen.flac.Picture #209

Closed
lazka opened this issue Jan 6, 2015 · 6 comments
Closed

Unable to instantiate mutagen.flac.Picture #209

lazka opened this issue Jan 6, 2015 · 6 comments
Labels
bug

Comments

@lazka
Copy link
Member

@lazka lazka commented Jan 6, 2015

Originally reported by: Naftuli Tzvi Kay (Bitbucket: rfkrocktk, GitHub: rfkrocktk)


I'm trying to replace the picture in my FLAC files with one from disk.

There seems to be a bug in Picture.load() where it tries specifying a length (as read from the image) which is invalid.

#!python

/usr/local/lib/python2.7/dist-packages/mutagen/flac.pyc in load(self, data)
    537     def load(self, data):
    538         self.type, length = struct.unpack('>2I', data.read(8))
--> 539         self.mime = data.read(length).decode('UTF-8', 'replace')
    540         length, = struct.unpack('>I', data.read(4))
    541         self.desc = data.read(length).decode('UTF-8', 'replace')

/usr/local/lib/python2.7/dist-packages/mutagen/flac.pyc in read(self, size)
     65         if size >= 0 and len(data) != size:
     66             raise error("file said %d bytes, read %d bytes" % (
---> 67                         size, len(data)))
     68         return data
     69 

error: file said 934244 bytes, read 506296 bytes

Here's what I'm trying to do:

#!python

f = FLAC("track.flac")

with open("Folder.jpg", "wb") as pf:
    f.add_picture(Picture(pf))

The logic inside of Picture.load() doesn't seem to work right and prevents me from adding pictures to my FLAC files :(


@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 7, 2015

Original comment by Naftuli Tzvi Kay (Bitbucket: rfkrocktk, GitHub: rfkrocktk):


Do I need to format the actual picture file in a certain way in order to get it to work with these constructs?

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 7, 2015

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


The constructor is used for parsing the flac data structure.

See https://code.google.com/p/quodlibet/source/browse/quodlibet/quodlibet/formats/xiph.py#454 for an exmaple

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 7, 2015

Original comment by Naftuli Tzvi Kay (Bitbucket: rfkrocktk, GitHub: rfkrocktk):


Great, thanks, makes sense. Can you patch the docstrings to include this information? Something like

#!python

def __init__(self, data=None):
    """
    Creates a new Picture object from an optional FLAC metadata structure. To create a picture from file (in order to add to a FLAC file), 
    instantiate this object without passing anything to the constructor and then set the properties manually:

        p = Picture()

        with open("Folder.jpg", "rb") as f:
            pic.data = f.read()

        pic.type = APICType.COVER_FRONT
        pic.mime = "image/jpeg"
        pic.width = 500
        pic.height = 500
        pic.depth = 16 # color depth

    """
@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 7, 2015

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


Sure, thanks for writing it up.

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 7, 2015

Original comment by Naftuli Tzvi Kay (Bitbucket: rfkrocktk, GitHub: rfkrocktk):


No problem, I love Mutagen and am happy to make the docs better and easier
to use.

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jan 9, 2015

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


docs: add example for how to create a new flac.Picture (Fixes issue #209)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.