mirror of
https://github.com/beetbox/beets.git
synced 2025-12-14 20:43:41 +01:00
use track length over recording length
Closes #341. Also, 666 tests! Woohoo! --HG-- extra : amend_source : f00626f20e2475edcf220772223080ef62f46d84
This commit is contained in:
parent
c5de56c4fd
commit
a5422eeaf7
3 changed files with 23 additions and 7 deletions
|
|
@ -156,7 +156,7 @@ def track_info(recording, index=None, medium=None, medium_index=None):
|
|||
info.artist_id = artist['id']
|
||||
|
||||
if recording.get('length'):
|
||||
info.length = int(recording['length'])/(1000.0)
|
||||
info.length = int(recording['length']) / (1000.0)
|
||||
|
||||
info.decode()
|
||||
return info
|
||||
|
|
@ -203,6 +203,10 @@ def album_info(release):
|
|||
# Track title may be distinct from underlying recording
|
||||
# title.
|
||||
ti.title = track['title']
|
||||
if track.get('length'):
|
||||
# Track duration is preferred over the recording
|
||||
# duration.
|
||||
ti.length = int(track['length']) / (1000.0)
|
||||
ti.disctitle = disctitle
|
||||
track_infos.append(ti)
|
||||
info = beets.autotag.hooks.AlbumInfo(
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ And some fixes:
|
|||
* Fix a crash when a file's metadata included a very large number (one wider
|
||||
than 64 bits). These huge numbers are now replaced with zeroes in the
|
||||
database.
|
||||
* When a track on a MusicBrainz release has a different length from the
|
||||
underlying recording's length, the track length is now used instead.
|
||||
|
||||
.. _Opus: http://www.opus-codec.org/
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from beets.autotag import mb
|
|||
from beets import config
|
||||
|
||||
class MBAlbumInfoTest(_common.TestCase):
|
||||
def _make_release(self, date_str='2009', tracks=None):
|
||||
def _make_release(self, date_str='2009', tracks=None, track_length=None):
|
||||
release = {
|
||||
'title': 'ALBUM TITLE',
|
||||
'id': 'ALBUM ID',
|
||||
|
|
@ -57,11 +57,15 @@ class MBAlbumInfoTest(_common.TestCase):
|
|||
}
|
||||
if tracks:
|
||||
track_list = []
|
||||
for i, track in enumerate(tracks):
|
||||
track_list.append({
|
||||
'recording': track,
|
||||
'position': str(i+1),
|
||||
})
|
||||
for i, recording in enumerate(tracks):
|
||||
track = {
|
||||
'recording': recording,
|
||||
'position': str(i + 1),
|
||||
}
|
||||
if track_length:
|
||||
# Track lengths are distinct from recording lengths.
|
||||
track['length'] = track_length
|
||||
track_list.append(track)
|
||||
release['medium-list'].append({
|
||||
'position': '1',
|
||||
'track-list': track_list,
|
||||
|
|
@ -186,6 +190,12 @@ class MBAlbumInfoTest(_common.TestCase):
|
|||
d = mb.album_info(release)
|
||||
self.assertEqual(d.tracks[0].length, None)
|
||||
|
||||
def test_track_length_overrides_recording_length(self):
|
||||
tracks = [self._make_track('TITLE', 'ID', 1.0 * 1000.0)]
|
||||
release = self._make_release(tracks=tracks, track_length=2.0 * 1000.0)
|
||||
d = mb.album_info(release)
|
||||
self.assertEqual(d.tracks[0].length, 2.0)
|
||||
|
||||
def test_no_release_date(self):
|
||||
release = self._make_release(None)
|
||||
d = mb.album_info(release)
|
||||
|
|
|
|||
Loading…
Reference in a new issue