2009-10-23 14:35:51 +00:00
|
|
|
# Created By: Virgil Dupras
|
|
|
|
# Created On: 2009-10-23
|
2012-03-15 18:28:40 +00:00
|
|
|
# Copyright 2012 Hardcoded Software (http://www.hardcoded.net)
|
2009-10-23 14:35:51 +00:00
|
|
|
#
|
2010-09-30 10:17:41 +00:00
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
2009-10-23 14:35:51 +00:00
|
|
|
# which should be included with this package. The terms are also available at
|
2010-09-30 10:17:41 +00:00
|
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
2009-10-23 14:35:51 +00:00
|
|
|
|
2010-12-29 12:17:30 +00:00
|
|
|
from hsaudiotag import auto
|
2011-01-11 12:36:05 +00:00
|
|
|
from hscommon.util import get_file_ext
|
2009-12-30 10:37:57 +00:00
|
|
|
from core import fs
|
2009-10-23 14:35:51 +00:00
|
|
|
|
2010-12-29 12:17:30 +00:00
|
|
|
TAG_FIELDS = {'audiosize', 'duration', 'bitrate', 'samplerate', 'title', 'artist',
|
|
|
|
'album', 'genre', 'year', 'track', 'comment'}
|
2009-10-23 14:35:51 +00:00
|
|
|
|
|
|
|
class MusicFile(fs.File):
|
|
|
|
INITIAL_INFO = fs.File.INITIAL_INFO.copy()
|
|
|
|
INITIAL_INFO.update({
|
|
|
|
'audiosize': 0,
|
|
|
|
'bitrate' : 0,
|
|
|
|
'duration' : 0,
|
|
|
|
'samplerate':0,
|
|
|
|
'artist' : '',
|
|
|
|
'album' : '',
|
|
|
|
'title' : '',
|
|
|
|
'genre' : '',
|
|
|
|
'comment' : '',
|
|
|
|
'year' : '',
|
|
|
|
'track' : 0,
|
|
|
|
})
|
2012-05-29 21:39:54 +00:00
|
|
|
__slots__ = fs.File.__slots__ + tuple(INITIAL_INFO.keys())
|
2009-10-23 14:35:51 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def can_handle(cls, path):
|
|
|
|
if not fs.File.can_handle(path):
|
|
|
|
return False
|
2010-12-29 12:17:30 +00:00
|
|
|
return get_file_ext(path[-1]) in auto.EXT2CLASS
|
2009-10-23 14:35:51 +00:00
|
|
|
|
2012-05-29 21:39:54 +00:00
|
|
|
def _get_md5partial_offset_and_size(self):
|
|
|
|
f = auto.File(str(self.path))
|
|
|
|
return (f.audio_offset, f.audio_size)
|
|
|
|
|
2009-10-23 14:35:51 +00:00
|
|
|
def _read_info(self, field):
|
2010-12-29 12:17:30 +00:00
|
|
|
fs.File._read_info(self, field)
|
2009-10-23 14:35:51 +00:00
|
|
|
if field in TAG_FIELDS:
|
2010-12-29 12:17:30 +00:00
|
|
|
f = auto.File(str(self.path))
|
|
|
|
self.audiosize = f.audio_size
|
|
|
|
self.bitrate = f.bitrate
|
|
|
|
self.duration = f.duration
|
|
|
|
self.samplerate = f.sample_rate
|
|
|
|
self.artist = f.artist
|
|
|
|
self.album = f.album
|
|
|
|
self.title = f.title
|
|
|
|
self.genre = f.genre
|
|
|
|
self.comment = f.comment
|
|
|
|
self.year = f.year
|
|
|
|
self.track = f.track
|
2009-10-23 14:35:51 +00:00
|
|
|
|