rails / marcel

Find the mime type of files, examining file, filename and declared type
Apache License 2.0
386 stars 67 forks source link

Audio/flac? #42

Closed jrochkind closed 3 years ago

jrochkind commented 3 years ago

Previous marcel analyzed a FLAC file and returned mime-type: audio/flac.

New 1.0 with it's own data decides audio/x-flac instead. Perhaps because of this line: https://github.com/rails/marcel/blob/949e9d6890d0ed52b75962280634670d102aa8dd/lib/marcel/tables.rb#L333

It is not clear to me which is "right", the situation with "official" mime/content-types has gotten a bit out of hand.

But a differnet part of marcel uses audio/flac: https://github.com/rails/marcel/blob/949e9d6890d0ed52b75962280634670d102aa8dd/script/generate_tables.rb#L150

Not sure if these data tables are generated from some upstream source, so this is an issue (if it is one?) for some such source? If the marcel/tables.rb is generated from an upstream source, a comment at top of file saying so might be helpful.

Is there any way for me to configure marcel to tell it I'd rather it return audio/flac?

gmcgibbon commented 3 years ago

https://github.com/rails/marcel/pull/46 and https://github.com/rails/marcel/pull/45 this is indeed also a regression. I'll take a look at it.

In the meantime, you should be able to extend marcel like these manual overrides: https://github.com/rails/marcel/blob/a525d5b38f287ca0511c8eb26e657a1d46686e5f/lib/marcel/mime_type/definitions.rb

jrochkind commented 3 years ago

Thanks! As I tried to look into it more.... it's unclear that audio/flac actually is "legal", it's not in the IANA registry... but many tools use it anyway... while others use audio/x-flac. it's unclear to me what the "right" thing to do would be if you were starting from scratch... which might not be the same as the "right" thing in marcel which has a history of doing it one way.

gmcgibbon commented 3 years ago

I'm also not sure which one is more correct, but the fact that marcel < 1.0.0 used audio/flac makes me think it should be audio/flac. The difference is a side effect of switching to a different types DB that's appropriately licensed. Open to opinions on the PR though! 😄

jrochkind commented 3 years ago

Yeah, I actually can't decide what I think is best.

If marcel had already been 1.0, I think it would be legit to say it should stay the same in the interest of backwards compat. But marcel wasn't, so made zero promises as to backwards compat. But this itself was probably a mistake, marcel not being 1.0 long ago, as it was so widely used in production and a dependency of Rails... so we maybe should treat it as if it were 1.0, meaning backwards compat, yeah.

On the other hand, audio/flac may be literally officially illegal. On the other other hand, plenty of tools seem to use it anyway in the wild.

So who knows! Whatever is least disruptive to existing users of the tool is best I guess! And I'm not even sure what that is at this point!