mirror of
https://github.com/beetbox/beets.git
synced 2026-02-11 09:54:31 +01:00
include global index in TrackInfo objects
This commit is contained in:
parent
7e6e5e5dca
commit
98d46be4a5
3 changed files with 19 additions and 5 deletions
|
|
@ -91,6 +91,7 @@ class TrackInfo(object):
|
|||
- ``artist``: individual track artist name
|
||||
- ``artist_id``
|
||||
- ``length``: float: duration of the track in seconds
|
||||
- ``index``: position on the entire release
|
||||
- ``medium``: the disc number this track appears on in the album
|
||||
- ``medium_index``: the track's position on the disc
|
||||
- ``artist_sort``: name of the track artist for sorting
|
||||
|
|
@ -98,16 +99,18 @@ class TrackInfo(object):
|
|||
- ``artist_credit``: Recording-specific artist name
|
||||
|
||||
Only ``title`` and ``track_id`` are required. The rest of the fields
|
||||
may be None.
|
||||
may be None. The indices ``index``, ``medium``, and ``medium_index``
|
||||
are all 1-based.
|
||||
"""
|
||||
def __init__(self, title, track_id, artist=None, artist_id=None,
|
||||
length=None, medium=None, medium_index=None,
|
||||
length=None, index=None, medium=None, medium_index=None,
|
||||
artist_sort=None, disctitle=None, artist_credit=None):
|
||||
self.title = title
|
||||
self.track_id = track_id
|
||||
self.artist = artist
|
||||
self.artist_id = artist_id
|
||||
self.length = length
|
||||
self.index = index
|
||||
self.medium = medium
|
||||
self.medium_index = medium_index
|
||||
self.artist_sort = artist_sort
|
||||
|
|
|
|||
|
|
@ -95,13 +95,17 @@ def _flatten_artist_credit(credit):
|
|||
''.join(artist_credit_parts),
|
||||
)
|
||||
|
||||
def track_info(recording, medium=None, medium_index=None):
|
||||
def track_info(recording, index=None, medium=None, medium_index=None):
|
||||
"""Translates a MusicBrainz recording result dictionary into a beets
|
||||
``TrackInfo`` object. ``medium_index``, if provided, is the track's
|
||||
index (1-based) on its medium.
|
||||
``TrackInfo`` object. Three parameters are optional and are used
|
||||
only for tracks that appear on releases (non-singletons): ``index``,
|
||||
the overall track number; ``medium``, the disc number;
|
||||
``medium_index``, the track's index on its medium. Each number is a
|
||||
1-based index.
|
||||
"""
|
||||
info = beets.autotag.hooks.TrackInfo(recording['title'],
|
||||
recording['id'],
|
||||
index=index,
|
||||
medium=medium,
|
||||
medium_index=medium_index)
|
||||
|
||||
|
|
@ -139,10 +143,13 @@ def album_info(release):
|
|||
|
||||
# Basic info.
|
||||
track_infos = []
|
||||
index = 0
|
||||
for medium in release['medium-list']:
|
||||
disctitle = medium.get('title')
|
||||
for track in medium['track-list']:
|
||||
index += 1
|
||||
ti = track_info(track['recording'],
|
||||
index,
|
||||
int(medium['position']),
|
||||
int(track['position']))
|
||||
if track.get('title'):
|
||||
|
|
|
|||
|
|
@ -132,7 +132,9 @@ class MBAlbumInfoTest(unittest.TestCase):
|
|||
d = mb.album_info(release)
|
||||
t = d.tracks
|
||||
self.assertEqual(t[0].medium_index, 1)
|
||||
self.assertEqual(t[0].index, 1)
|
||||
self.assertEqual(t[1].medium_index, 2)
|
||||
self.assertEqual(t[1].index, 2)
|
||||
|
||||
def test_parse_medium_numbers_single_medium(self):
|
||||
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
|
||||
|
|
@ -163,8 +165,10 @@ class MBAlbumInfoTest(unittest.TestCase):
|
|||
t = d.tracks
|
||||
self.assertEqual(t[0].medium, 1)
|
||||
self.assertEqual(t[0].medium_index, 1)
|
||||
self.assertEqual(t[0].index, 1)
|
||||
self.assertEqual(t[1].medium, 2)
|
||||
self.assertEqual(t[1].medium_index, 1)
|
||||
self.assertEqual(t[1].index, 2)
|
||||
|
||||
def test_parse_release_year_month_only(self):
|
||||
release = self._make_release('1987-03')
|
||||
|
|
|
|||
Loading…
Reference in a new issue