本文整理汇总了Python中mopidy.models.Track.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Track.copy方法的具体用法?Python Track.copy怎么用?Python Track.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mopidy.models.Track
的用法示例。
在下文中一共展示了Track.copy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scan
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
def test_scan(self, mock_scan):
mock_scan.return_value = {
'tags': {
'image': [GIF_DATA, PNG_DATA],
'preview-image': [JPEG_DATA]
}
}
album = Album(name='foo')
track = Track(uri=b'local:track:foo.mp3', album=album)
images = ['/images/' + name for name in GIF_NAME, PNG_NAME, JPEG_NAME]
image_track = track.copy(album=album.copy(images=images))
self.library.add(track)
mock_library.add.assert_called_with(image_track, None, None)
self.assertTrue(os.path.isfile(os.path.join(self.tempdir, GIF_NAME)))
self.assertTrue(os.path.isfile(os.path.join(self.tempdir, PNG_NAME)))
self.assertTrue(os.path.isfile(os.path.join(self.tempdir, JPEG_NAME)))
self.library.close()
self.assertEqual(os.listdir(self.tempdir), [])
示例2: test_copying_track_with_private_internal_value
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
def test_copying_track_with_private_internal_value(self):
artist1 = Artist(name="foo")
artist2 = Artist(name="bar")
track = Track(artists=[artist1])
copy = track.copy(artists=[artist2])
self.assertIn(artist2, copy.artists)
示例3: test_copying_track_with_missing_values
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
def test_copying_track_with_missing_values(self):
track = Track(uri="bar")
copy = track.copy(name="baz")
self.assertEqual("baz", copy.name)
self.assertEqual("bar", copy.uri)
示例4: test_copying_track
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
def test_copying_track(self):
track = Track()
self.compare(track, track.copy())
示例5: TranslatorTest
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
class TranslatorTest(unittest.TestCase):
def setUp(self):
self.data = {
'uri': 'uri',
'duration': 4531000000,
'mtime': 1234,
'tags': {
'album': ['album'],
'track-number': [1],
'artist': ['artist'],
'composer': ['composer'],
'performer': ['performer'],
'album-artist': ['albumartist'],
'title': ['track'],
'track-count': [2],
'album-disc-number': [2],
'album-disc-count': [3],
'date': [FakeGstDate(2006, 1, 1,)],
'container-format': ['ID3 tag'],
'genre': ['genre'],
'comment': ['comment'],
'musicbrainz-trackid': ['trackid'],
'musicbrainz-albumid': ['albumid'],
'musicbrainz-artistid': ['artistid'],
'musicbrainz-albumartistid': ['albumartistid'],
'bitrate': [1000],
},
}
artist = Artist(name='artist', musicbrainz_id='artistid')
composer = Artist(name='composer')
performer = Artist(name='performer')
albumartist = Artist(name='albumartist',
musicbrainz_id='albumartistid')
album = Album(name='album', num_tracks=2, num_discs=3,
musicbrainz_id='albumid', artists=[albumartist])
self.track = Track(uri='uri', name='track', date='2006-01-01',
genre='genre', track_no=1, disc_no=2, length=4531,
comment='comment', musicbrainz_id='trackid',
last_modified=1234, album=album, bitrate=1000,
artists=[artist], composers=[composer],
performers=[performer])
def check(self, expected):
actual = scan.audio_data_to_track(self.data)
self.assertEqual(expected, actual)
def test_track(self):
self.check(self.track)
def test_none_track_length(self):
self.data['duration'] = None
self.check(self.track.copy(length=None))
def test_none_track_last_modified(self):
self.data['mtime'] = None
self.check(self.track.copy(last_modified=None))
def test_missing_track_no(self):
del self.data['tags']['track-number']
self.check(self.track.copy(track_no=None))
def test_multiple_track_no(self):
self.data['tags']['track-number'].append(9)
self.check(self.track)
def test_missing_track_disc_no(self):
del self.data['tags']['album-disc-number']
self.check(self.track.copy(disc_no=None))
def test_multiple_track_disc_no(self):
self.data['tags']['album-disc-number'].append(9)
self.check(self.track)
def test_missing_track_name(self):
del self.data['tags']['title']
self.check(self.track.copy(name=None))
def test_multiple_track_name(self):
self.data['tags']['title'] = ['name1', 'name2']
self.check(self.track.copy(name='name1; name2'))
def test_missing_track_musicbrainz_id(self):
del self.data['tags']['musicbrainz-trackid']
self.check(self.track.copy(musicbrainz_id=None))
def test_multiple_track_musicbrainz_id(self):
self.data['tags']['musicbrainz-trackid'].append('id')
self.check(self.track)
def test_missing_track_bitrate(self):
del self.data['tags']['bitrate']
self.check(self.track.copy(bitrate=None))
def test_multiple_track_bitrate(self):
self.data['tags']['bitrate'].append(1234)
self.check(self.track)
#.........这里部分代码省略.........
示例6: path_to_data_dir
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
from mopidy.models import Track
from mopidy.utils.path import path_to_uri
from tests import path_to_data_dir
data_dir = path_to_data_dir('')
song1_path = path_to_data_dir('song1.mp3')
song2_path = path_to_data_dir('song2.mp3')
encoded_path = path_to_data_dir('æøå.mp3')
song1_uri = path_to_uri(song1_path)
song2_uri = path_to_uri(song2_path)
encoded_uri = path_to_uri(encoded_path)
song1_track = Track(uri=song1_uri)
song2_track = Track(uri=song2_uri)
encoded_track = Track(uri=encoded_uri)
song1_ext_track = song1_track.copy(name='song1')
song2_ext_track = song2_track.copy(name='song2', length=60000)
encoded_ext_track = encoded_track.copy(name='æøå')
# FIXME use mock instead of tempfile.NamedTemporaryFile
class M3UToUriTest(unittest.TestCase):
def test_empty_file(self):
tracks = parse_m3u(path_to_data_dir('empty.m3u'), data_dir)
self.assertEqual([], tracks)
def test_basic_file(self):
tracks = parse_m3u(path_to_data_dir('one.m3u'), data_dir)
self.assertEqual([song1_track], tracks)
示例7: parse_m3u
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
def parse_m3u(file_path, media_dir=None):
r"""
Convert M3U file list to list of tracks
Example M3U data::
# This is a comment
Alternative\Band - Song.mp3
Classical\Other Band - New Song.mp3
Stuff.mp3
D:\More Music\Foo.mp3
http://www.example.com:8000/Listen.pls
http://www.example.com/~user/Mine.mp3
Example extended M3U data::
#EXTM3U
#EXTINF:123, Sample artist - Sample title
Sample.mp3
#EXTINF:321,Example Artist - Example title
Greatest Hits\Example.ogg
#EXTINF:-1,Radio XMP
http://mp3stream.example.com:8000/
- Relative paths of songs should be with respect to location of M3U.
- Paths are normally platform specific.
- Lines starting with # are ignored, except for extended M3U directives.
- Track.name and Track.length are set from extended M3U directives.
- m3u files are latin-1.
"""
# TODO: uris as bytes
tracks = []
try:
with open(file_path) as m3u:
contents = m3u.readlines()
except IOError as error:
logger.warning('Couldn\'t open m3u: %s', locale_decode(error))
return tracks
if not contents:
return tracks
extended = contents[0].decode('latin1').startswith('#EXTM3U')
track = Track()
for line in contents:
line = line.strip().decode('latin1')
if line.startswith('#'):
if extended and line.startswith('#EXTINF'):
track = m3u_extinf_to_track(line)
continue
if urlparse.urlsplit(line).scheme:
tracks.append(track.copy(uri=line))
elif os.path.normpath(line) == os.path.abspath(line):
path = path_to_uri(line)
tracks.append(track.copy(uri=path))
elif media_dir is not None:
path = path_to_uri(os.path.join(media_dir, line))
tracks.append(track.copy(uri=path))
track = Track()
return tracks
示例8: TagsToTrackTest
# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import copy [as 别名]
class TagsToTrackTest(unittest.TestCase):
def setUp(self): # noqa: N802
self.tags = {
"album": ["album"],
"track-number": [1],
"artist": ["artist"],
"composer": ["composer"],
"performer": ["performer"],
"album-artist": ["albumartist"],
"title": ["track"],
"track-count": [2],
"album-disc-number": [2],
"album-disc-count": [3],
"date": [datetime.date(2006, 1, 1)],
"container-format": ["ID3 tag"],
"genre": ["genre"],
"comment": ["comment"],
"musicbrainz-trackid": ["trackid"],
"musicbrainz-albumid": ["albumid"],
"musicbrainz-artistid": ["artistid"],
"musicbrainz-albumartistid": ["albumartistid"],
"bitrate": [1000],
}
artist = Artist(name="artist", musicbrainz_id="artistid")
composer = Artist(name="composer")
performer = Artist(name="performer")
albumartist = Artist(name="albumartist", musicbrainz_id="albumartistid")
album = Album(name="album", num_tracks=2, num_discs=3, musicbrainz_id="albumid", artists=[albumartist])
self.track = Track(
name="track",
date="2006-01-01",
genre="genre",
track_no=1,
disc_no=2,
comment="comment",
musicbrainz_id="trackid",
album=album,
bitrate=1000,
artists=[artist],
composers=[composer],
performers=[performer],
)
def check(self, expected):
actual = utils.convert_tags_to_track(self.tags)
self.assertEqual(expected, actual)
def test_track(self):
self.check(self.track)
def test_missing_track_no(self):
del self.tags["track-number"]
self.check(self.track.copy(track_no=None))
def test_multiple_track_no(self):
self.tags["track-number"].append(9)
self.check(self.track)
def test_missing_track_disc_no(self):
del self.tags["album-disc-number"]
self.check(self.track.copy(disc_no=None))
def test_multiple_track_disc_no(self):
self.tags["album-disc-number"].append(9)
self.check(self.track)
def test_missing_track_name(self):
del self.tags["title"]
self.check(self.track.copy(name=None))
def test_multiple_track_name(self):
self.tags["title"] = ["name1", "name2"]
self.check(self.track.copy(name="name1; name2"))
def test_missing_track_musicbrainz_id(self):
del self.tags["musicbrainz-trackid"]
self.check(self.track.copy(musicbrainz_id=None))
def test_multiple_track_musicbrainz_id(self):
self.tags["musicbrainz-trackid"].append("id")
self.check(self.track)
def test_missing_track_bitrate(self):
del self.tags["bitrate"]
self.check(self.track.copy(bitrate=None))
def test_multiple_track_bitrate(self):
self.tags["bitrate"].append(1234)
self.check(self.track)
def test_missing_track_genre(self):
del self.tags["genre"]
self.check(self.track.copy(genre=None))
def test_multiple_track_genre(self):
self.tags["genre"] = ["genre1", "genre2"]
self.check(self.track.copy(genre="genre1; genre2"))
#.........这里部分代码省略.........