Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possible ReplayGain values for loudgain #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,30 @@ def __set__(self, mediafile, value):
super(QNumberField, self).__set__(mediafile, q_num)


class ReferenceLoudnessField(MediaField):
"""Access loudness reference field

Access a floating point replaygain loudness reference field, which could be
negative (LUFS) or positive (dB). dB values will be converted to LUFS
so we get a uniform representation within beets. (LUFS = dB - 107.0)
"""
def __init__(self, *args, **kwargs):
super(ReferenceLoudnessField, self).__init__(*args, **kwargs)

def __get__(self, mediafile, owner=None):
value = super(ReferenceLoudnessField, self).__get__(mediafile, owner)
if value is None:
return None
if value <= 0.0:
return value
return value - 107.0

def __set__(self, mediafile, value):
if value > 0.0:
value = value - 107.0
super(ReferenceLoudnessField, self).__set__(mediafile, value)


class ImageListField(ListMediaField):
"""Descriptor to access the list of images embedded in tags.

Expand Down Expand Up @@ -1960,6 +1984,10 @@ def update(self, dict):
index=0, desc=u'iTunNORM',
id3_lang='eng'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_TRACK_GAIN',
float_places=2, suffix=' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_track_gain',
float_places=2, suffix=' dB'
Expand All @@ -1972,6 +2000,10 @@ def update(self, dict):
u'REPLAYGAIN_TRACK_GAIN',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'REPLAYGAIN_TRACK_GAIN',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'replaygain_track_gain',
float_places=2, suffix=u' dB'
Expand All @@ -1987,6 +2019,10 @@ def update(self, dict):
u'replaygain_album_gain',
float_places=2, suffix=u' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_ALBUM_GAIN',
float_places=2, suffix=' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_album_gain',
float_places=2, suffix=' dB'
Expand All @@ -1995,6 +2031,10 @@ def update(self, dict):
u'REPLAYGAIN_ALBUM_GAIN',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'REPLAYGAIN_ALBUM_GAIN',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'replaygain_album_gain',
float_places=2, suffix=u' dB'
Expand All @@ -2015,6 +2055,10 @@ def update(self, dict):
index=1, desc=u'iTunNORM',
id3_lang='eng'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_TRACK_PEAK',
float_places=6
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_track_peak',
float_places=6
Expand All @@ -2024,6 +2068,7 @@ def update(self, dict):
index=1
),
StorageStyle(u'REPLAYGAIN_TRACK_PEAK', float_places=6),
ASFStorageStyle(u'REPLAYGAIN_TRACK_PEAK', float_places=6),
ASFStorageStyle(u'replaygain_track_peak', float_places=6),
out_type=float,
)
Expand All @@ -2036,14 +2081,112 @@ def update(self, dict):
u'replaygain_album_peak',
float_places=6
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_ALBUM_PEAK',
float_places=6
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_album_peak',
float_places=6
),
StorageStyle(u'REPLAYGAIN_ALBUM_PEAK', float_places=6),
ASFStorageStyle(u'REPLAYGAIN_ALBUM_PEAK', float_places=6),
ASFStorageStyle(u'replaygain_album_peak', float_places=6),
out_type=float,
)
rg_track_range = MediaField(
MP3DescStorageStyle(
u'REPLAYGAIN_TRACK_RANGE',
float_places=2, suffix=u' dB'
),
MP3DescStorageStyle(
u'replaygain_track_range',
float_places=2, suffix=u' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_TRACK_RANGE',
float_places=2, suffix=' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_track_range',
float_places=2, suffix=' dB'
),
StorageStyle(
u'REPLAYGAIN_TRACK_RANGE',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'REPLAYGAIN_TRACK_RANGE',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'replaygain_track_range',
float_places=2, suffix=u' dB'
),
out_type=float
)
rg_album_range = MediaField(
MP3DescStorageStyle(
u'REPLAYGAIN_ALBUM_RANGE',
float_places=2, suffix=u' dB'
),
MP3DescStorageStyle(
u'replaygain_album_range',
float_places=2, suffix=u' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_ALBUM_RANGE',
float_places=2, suffix=' dB'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_album_range',
float_places=2, suffix=' dB'
),
StorageStyle(
u'REPLAYGAIN_ALBUM_RANGE',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'REPLAYGAIN_ALBUM_RANGE',
float_places=2, suffix=u' dB'
),
ASFStorageStyle(
u'replaygain_album_range',
float_places=2, suffix=u' dB'
),
out_type=float
)
rg_reference = ReferenceLoudnessField(
MP3DescStorageStyle(
u'REPLAYGAIN_REFERENCE_LOUDNESS',
float_places=2, suffix=u' LUFS'
),
MP3DescStorageStyle(
u'replaygain_reference_loudness',
float_places=2, suffix=u' LUFS'
),
MP4StorageStyle(
'----:com.apple.iTunes:REPLAYGAIN_REFERENCE_LOUDNESS',
float_places=2, suffix=' LUFS'
),
MP4StorageStyle(
'----:com.apple.iTunes:replaygain_reference_loudness',
float_places=2, suffix=' LUFS'
),
StorageStyle(
u'REPLAYGAIN_REFERENCE_LOUDNESS',
float_places=2, suffix=u' LUFS'
),
ASFStorageStyle(
u'REPLAYGAIN_REFERENCE_LOUDNESS',
float_places=2, suffix=u' LUFS'
),
ASFStorageStyle(
u'replaygain_reference_loudness',
float_places=2, suffix=u' LUFS'
),
out_type=float
)

# EBU R128 fields.
r128_track_gain = QNumberField(
Expand Down
5 changes: 5 additions & 0 deletions test/test_mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,11 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin,
'label',
'rg_track_peak',
'rg_track_gain',
'rg_track_range',
'rg_album_peak',
'rg_album_gain',
'rg_album_range',
'rg_reference',
'r128_track_gain',
'r128_album_gain',
'albumartist',
Expand Down Expand Up @@ -699,6 +702,8 @@ def _generate_tags(self, base=None):
tags[key] = -1
else:
tags[key] = 'value\u2010%s' % key
# rg_reference = 1.0 would evaluate to -106.0
tags['rg_reference'] = -18.0

for key in ['disc', 'disctotal', 'track', 'tracktotal', 'bpm']:
tags[key] = 1
Expand Down