Katharine / ponytone

Online Pony Karaoke
MIT License
13 stars 7 forks source link

Cannot import ogg #20

Open barbeque-squared opened 4 years ago

barbeque-squared commented 4 years ago

Newer songs have started to use the ogg format in favour of mp3. Example: A Final Twilight

I have created a fix for this problem in a branch, by just using the general mutagen importer instead of the mp3-specific one: https://github.com/barbeque-squared/ponytone/tree/import-ogg However, I literally cannot tests if this actually works in browsers, otherwise I'd have created a pull request instead.

For reference, without the fix you get this error when importing ogg:

$ docker exec ponytone_web_1 python importmlk.py https://www.mylittlekaraoke.com/store/beta/dotmlk/Community/4EverfreeBrony%20-%20A%20Final%20Twilight%20%28Cover%29.tar.mlk  postgres://postgres:postgres@db:5432/postgres
Traceback (most recent call last):
  File "importmlk.py", line 155, in <module>
    info = song_info(tar, filename)
  File "importmlk.py", line 82, in song_info
    duration = mutagen.mp3.MP3(tar.extractfile(mp3_path)).info.length
  File "/usr/local/lib/python3.6/site-packages/mutagen/_file.py", line 49, in __init__
    self.load(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 129, in wrapper
    return func(self, h, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/mutagen/id3/_file.py", line 406, in load
    self.info = self._Info(fileobj, offset)
  File "/usr/local/lib/python3.6/site-packages/mutagen/_util.py", line 158, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/mutagen/mp3/__init__.py", line 396, in __init__
    raise HeaderNotFoundError("can't sync to MPEG frame")
mutagen.mp3.HeaderNotFoundError: can't sync to MPEG frame
barbeque-squared commented 4 years ago

A further change might be to check if the file is actually an mp3 or ogg to prevent random formats that don't work in browsers from getting in. Or do it the way it is already done if the extension is mp3 (and throw an error if it can't figure it out), do the same for ogg, and throw a more human-readable error if it's anything else.