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

Embedart: fails on some jpegs because imghdr doesn't recognize the mimetype #1545

Merged
merged 10 commits into from Jul 27, 2015

Conversation

Projects
None yet
2 participants
@nathdwek
Member

nathdwek commented Jul 21, 2015

This errors pops up

embedart: Embedding album art into Queen - Live at Wembley ’86

embedart: not embedding image of unsupported type: image/x-None

with this cover (found by beets-fetchart).

This is due to this issue. Fortunately, imghdr provides the list imghdr.tests to add extra mimetype tests. I added a test which identifies jpeg files based on their magic bytes, which is the method used by file.

This is my first time contributing to beets, so I think some code style guidance is probably needed (mainly regarding the modification of imghdr.tests, which should only happen once). I also absolutely need some help with adding the right tests. There is some testing code in this PR, which is very naively based on the rest of test_mediafile.py, but the test doesn't fail without the patch, and I think it actually never runs. I should probably also find/build a smaller cover which can only be recognized based on the magic bytes.

nathdwek added some commits Jun 26, 2015

implement fix-jpeg-detection:
detect jpeg files using their magic bytes following the unix file implementation
by adding a test function to the imghdr.tests list, as intended
@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

I added a commit to fix the code style issues.

@sampsyo

This comment has been minimized.

Member

sampsyo commented Jul 21, 2015

Awesome! Thanks for sorting this out. Looks great so far.

  • I think the test belongs in a standalone test function, probably in the simpler test_mediafile_edge.py. The test can just call _image_mime_type() directly rather than using the automated test-battery machinery. Does that make sense?
  • I would love to avoid modifying imghdr.tests is possible. Could we just run your new magic-number check ourselves if imghdr gives us None? (Avoiding changes to global state help make things more predictable down the road.)
  • And finally, just to check: do you have reason to believe this check is fairly precise, i.e., there aren't a bunch of other formats that happen to use the same magic number? A link to the file policy would totally suffice.
@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

  • I'll have a look at test_mediafile_edge.py and see if I can get really started with tests without any external indication.
  • I also felt kinda uncomfortable modifying imghdr.tests like that but it had the advantage of really being a "pluggable" solution. I'll look into alternatives.
  • https://github.com/file/file/blob/master/magic/Magdir/jpeg#L12
@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

I added a commit re:testing. The test now passes and fails adequately.

@sampsyo

This comment has been minimized.

Member

sampsyo commented Jul 21, 2015

Nice! The test looks great.

Would you mind adding a comment to the code with that link? Could help us stay less confused later on. 😃

@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

I added two commits with a more elegant implementation which doesn't require to modify imghdr.tests and also comments for the test.

Should I try to build a smaller image which fits the edge case or is the 1000x1000 image acceptable in the test ressources?

@sampsyo

This comment has been minimized.

Member

sampsyo commented Jul 21, 2015

This is looking great. Thanks for the extra comments.

A smaller image would be wonderful if it's not too difficult -- it seems a little suboptimal to add a 0.5 MB file to the beets distribution for just one test. (And avoiding copyrighted images is also a plus.)

@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

Yeah I don't know I never tried but I guess it shouldn't be too difficult :)

@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 21, 2015

I added a commit with a smaller test image.

Anything else to be done?

@nathdwek nathdwek changed the title from [WIP] Embedart: fails on some jpegs because imghdr doesn't recognize the mimetype to Embedart: fails on some jpegs because imghdr doesn't recognize the mimetype Jul 21, 2015

@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 27, 2015

Do I need to do anything else before this can be merged?

@sampsyo

This comment has been minimized.

Member

sampsyo commented Jul 27, 2015

Nope, I was just being slow. Thanks for your patience.

@sampsyo sampsyo merged commit 68ec829 into beetbox:master Jul 27, 2015

2 checks passed

continuous-integration/appveyor AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

sampsyo added a commit that referenced this pull request Jul 27, 2015

Merge pull request #1545 from nathdwek/fix-jpeg-detection
Embedart: fails on some jpegs because imghdr doesn't recognize the mimetype

sampsyo added a commit that referenced this pull request Jul 27, 2015

@sampsyo

This comment has been minimized.

Member

sampsyo commented Jul 27, 2015

All merged up! Thank you again!

@nathdwek

This comment has been minimized.

Member

nathdwek commented Jul 27, 2015

Thank you very much for your responsiveness 😃

@nathdwek nathdwek deleted the nathdwek:fix-jpeg-detection branch Aug 2, 2015

nathdwek added a commit that referenced this pull request Nov 7, 2016

images: Make sure all jpegs work everywhere
Apply #1545 to a public function used everywhere

nathdwek added a commit that referenced this pull request Nov 8, 2016

images: Make sure all jpegs work everywhere
Apply #1545 to a public function used everywhere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment