1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Changed mimetype guessing

First look in system-known extensions/types through `mimetypes` module,
then in supysonic configuration
This commit is contained in:
spl0k 2013-10-15 18:16:16 +02:00
parent 2d0774abeb
commit b3aa61731a

View File

@ -3,18 +3,10 @@
import os, os.path import os, os.path
import time, mimetypes import time, mimetypes
import mutagen import mutagen
import db import config, db
def get_mime(ext): def get_mime(ext):
ret = mimetypes.guess_type('dummy.' + ext, False)[0] return mimetypes.guess_type('dummy.' + ext, False)[0] or config.get('mimetypes', ext) or 'application/octet-stream'
if ret:
return ret
try:
module = __import__('mutagen.' + ext, fromlist = [ 'Open' ])
inst = module.Open()
return inst.mime[0]
except:
return None
class Scanner: class Scanner:
def __init__(self, session): def __init__(self, session):
@ -84,7 +76,7 @@ class Scanner:
tr.duration = int(tag.info.length) tr.duration = int(tag.info.length)
tr.album = self.__find_album(self.__try_read_tag(tag, 'artist'), self.__try_read_tag(tag, 'album')) tr.album = self.__find_album(self.__try_read_tag(tag, 'artist'), self.__try_read_tag(tag, 'album'))
tr.bitrate = tag.info.bitrate / 1000 tr.bitrate = tag.info.bitrate / 1000
tr.content_type = mimetypes.guess_type(path, False)[0] or tag.mime[0] tr.content_type = get_mime(os.path.splitext(path)[1][1:])
tr.last_modification = os.path.getmtime(path) tr.last_modification = os.path.getmtime(path)
def __find_album(self, artist, album): def __find_album(self, artist, album):