mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
Switch from hsaudiotag to mutagen, close #440
- This opens up the ability to support more tags and audio information - Also makes progress on #333
This commit is contained in:
parent
6b8f85e39a
commit
58c04ff9ad
@ -6,7 +6,7 @@
|
|||||||
# which should be included with this package. The terms are also available at
|
# which should be included with this package. The terms are also available at
|
||||||
# http://www.gnu.org/licenses/gpl-3.0.html
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
from hsaudiotag import auto
|
import mutagen
|
||||||
from hscommon.util import get_file_ext, format_size, format_time
|
from hscommon.util import get_file_ext, format_size, format_time
|
||||||
|
|
||||||
from core.util import format_timestamp, format_perc, format_words, format_dupe_count
|
from core.util import format_timestamp, format_perc, format_words, format_dupe_count
|
||||||
@ -26,6 +26,9 @@ TAG_FIELDS = {
|
|||||||
"comment",
|
"comment",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This is a temporary workaround for migration from hsaudiotag for the can_handle method
|
||||||
|
SUPPORTED_EXTS = {"mp3", "wma", "m4a", "m4p", "ogg", "flac", "aif", "aiff", "aifc"}
|
||||||
|
|
||||||
|
|
||||||
class MusicFile(fs.File):
|
class MusicFile(fs.File):
|
||||||
INITIAL_INFO = fs.File.INITIAL_INFO.copy()
|
INITIAL_INFO = fs.File.INITIAL_INFO.copy()
|
||||||
@ -50,7 +53,7 @@ class MusicFile(fs.File):
|
|||||||
def can_handle(cls, path):
|
def can_handle(cls, path):
|
||||||
if not fs.File.can_handle(path):
|
if not fs.File.can_handle(path):
|
||||||
return False
|
return False
|
||||||
return get_file_ext(path.name) in auto.EXT2CLASS
|
return get_file_ext(path.name) in SUPPORTED_EXTS
|
||||||
|
|
||||||
def get_display_info(self, group, delta):
|
def get_display_info(self, group, delta):
|
||||||
size = self.size
|
size = self.size
|
||||||
@ -95,21 +98,23 @@ class MusicFile(fs.File):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _get_md5partial_offset_and_size(self):
|
def _get_md5partial_offset_and_size(self):
|
||||||
f = auto.File(str(self.path))
|
# No longer calculating the offset and audio size, just whole file
|
||||||
return (f.audio_offset, f.audio_size)
|
size = self.path.stat().st_size
|
||||||
|
return (0, size)
|
||||||
|
|
||||||
def _read_info(self, field):
|
def _read_info(self, field):
|
||||||
fs.File._read_info(self, field)
|
fs.File._read_info(self, field)
|
||||||
if field in TAG_FIELDS:
|
if field in TAG_FIELDS:
|
||||||
f = auto.File(str(self.path))
|
# The various conversions here are to make this look like the previous implementation
|
||||||
self.audiosize = f.audio_size
|
file = mutagen.File(str(self.path), easy=True)
|
||||||
self.bitrate = f.bitrate
|
self.audiosize = self.path.stat().st_size
|
||||||
self.duration = f.duration
|
self.bitrate = file.info.bitrate / 1000
|
||||||
self.samplerate = f.sample_rate
|
self.duration = file.info.length
|
||||||
self.artist = f.artist
|
self.samplerate = file.info.sample_rate
|
||||||
self.album = f.album
|
self.artist = ", ".join(file.tags.get("artist") or [])
|
||||||
self.title = f.title
|
self.album = ", ".join(file.tags.get("album") or [])
|
||||||
self.genre = f.genre
|
self.title = ", ".join(file.tags.get("title") or [])
|
||||||
self.comment = f.comment
|
self.genre = ", ".join(file.tags.get("genre") or [])
|
||||||
self.year = f.year
|
self.comment = ", ".join(file.tags.get("comment") or [""])
|
||||||
self.track = f.track
|
self.year = ", ".join(file.tags.get("date") or [])
|
||||||
|
self.track = (file.tags.get("tracknumber") or [""])[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user