当前位置: 首页>>代码示例>>Python>>正文


Python Track.replace方法代码示例

本文整理汇总了Python中mopidy.models.Track.replace方法的典型用法代码示例。如果您正苦于以下问题:Python Track.replace方法的具体用法?Python Track.replace怎么用?Python Track.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mopidy.models.Track的用法示例。


在下文中一共展示了Track.replace方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: tracks

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
def tracks(item, formats, uri=uri):
    identifier = item['metadata']['identifier']
    track = Track(album=album(item['metadata']))
    tracks = []
    for obj in files(item, formats):
        filename = obj.get('name')
        tracks.append(track.replace(
            uri=uri(identifier, filename),
            name=obj.get('title', filename),
            artists=artists(obj) or track.album.artists,
            genre=obj.get('genre'),
            track_no=parse_track(obj.get('track')),
            length=parse_length(obj.get('length')),
            bitrate=parse_bitrate(obj.get('bitrate')),
            last_modified=parse_mtime(obj.get('mtime'))
        ))
    return tracks
开发者ID:tkem,项目名称:mopidy-internetarchive,代码行数:19,代码来源:translator.py

示例2: TagsToTrackTest

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [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': ['2006-01-01'],
            'container-format': ['ID3 tag'],
            'genre': ['genre'],
            'comment': ['comment'],
            'musicbrainz-trackid': ['trackid'],
            'musicbrainz-albumid': ['albumid'],
            'musicbrainz-artistid': ['artistid'],
            'musicbrainz-sortname': ['sortname'],
            'musicbrainz-albumartistid': ['albumartistid'],
            'bitrate': [1000],
        }

        artist = Artist(name='artist', musicbrainz_id='artistid',
                        sortname='sortname')
        composer = Artist(name='composer')
        performer = Artist(name='performer')
        albumartist = Artist(name='albumartist',
                             musicbrainz_id='albumartistid')

        album = Album(name='album', date='2006-01-01',
                      num_tracks=2, num_discs=3,
                      musicbrainz_id='albumid', artists=[albumartist])

        self.track = Track(name='track',
                           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 = tags.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.replace(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.replace(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.replace(name=None))

    def test_multiple_track_name(self):
        self.tags['title'] = ['name1', 'name2']
        self.check(self.track.replace(name='name1; name2'))

    def test_missing_track_musicbrainz_id(self):
        del self.tags['musicbrainz-trackid']
        self.check(self.track.replace(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.replace(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.replace(genre=None))

    def test_multiple_track_genre(self):
        self.tags['genre'] = ['genre1', 'genre2']
        self.check(self.track.replace(genre='genre1; genre2'))

    def test_missing_track_date(self):
        del self.tags['date']
#.........这里部分代码省略.........
开发者ID:Afolabi28,项目名称:mopidy,代码行数:103,代码来源:test_tags.py

示例3: test_replace_track_with_private_internal_value

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
 def test_replace_track_with_private_internal_value(self):
     artist1 = Artist(name='foo')
     artist2 = Artist(name='bar')
     track = Track(artists=[artist1])
     other = track.replace(artists=[artist2])
     self.assertIn(artist2, other.artists)
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:8,代码来源:test_models.py

示例4: test_replace_track_with_missing_values

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
 def test_replace_track_with_missing_values(self):
     track = Track(uri='bar')
     other = track.replace(name='baz')
     self.assertEqual('baz', other.name)
     self.assertEqual('bar', other.uri)
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:7,代码来源:test_models.py

示例5: test_replace_track_with_basic_values

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
 def test_replace_track_with_basic_values(self):
     track = Track(name='foo', uri='bar')
     other = track.replace(name='baz')
     self.assertEqual('baz', other.name)
     self.assertEqual('bar', other.uri)
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:7,代码来源:test_models.py

示例6: test_replace_track

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
 def test_replace_track(self):
     track = Track()
     self.compare(track, track.replace())
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:5,代码来源:test_models.py

示例7: test_different_instance_with_replace

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
 def test_different_instance_with_replace(self):
     t = Track(uri='test1')
     self.assertIsNot(t, t.replace(uri='test2'))
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:5,代码来源:test_models.py

示例8: parse_m3u

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [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.
    - m3u8 files are utf-8
    """
    # TODO: uris as bytes
    file_encoding = 'utf-8' if file_path.endswith(b'.m3u8') else 'latin1'

    tracks = []
    try:
        with codecs.open(file_path, 'rb', file_encoding, 'replace') as m3u:
            contents = m3u.readlines()
    except IOError as error:
        logger.warning('Couldn\'t open m3u: %s', encoding.locale_decode(error))
        return tracks

    if not contents:
        return tracks

    # Strip newlines left by codecs
    contents = [line.strip() for line in contents]

    extended = contents[0].startswith('#EXTM3U')

    track = Track()
    for line in contents:
        if line.startswith('#'):
            if extended and line.startswith('#EXTINF'):
                track = m3u_extinf_to_track(line)
            continue

        if urlparse.urlsplit(line).scheme:
            tracks.append(track.replace(uri=line))
        elif os.path.normpath(line) == os.path.abspath(line):
            uri = path.path_to_uri(line)
            tracks.append(track.replace(uri=uri))
        elif media_dir is not None:
            uri = path.path_to_uri(os.path.join(media_dir, line))
            tracks.append(track.replace(uri=uri))

        track = Track()
    return tracks
开发者ID:HaBaLeS,项目名称:mopidy,代码行数:70,代码来源:translator.py

示例9: path_to_data_dir

# 需要导入模块: from mopidy.models import Track [as 别名]
# 或者: from mopidy.models.Track import replace [as 别名]
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')
song3_path = path_to_data_dir('φοο.mp3')
encoded_path = path_to_data_dir('æøå.mp3')
song1_uri = path.path_to_uri(song1_path)
song2_uri = path.path_to_uri(song2_path)
song3_uri = path.path_to_uri(song3_path)
encoded_uri = path.path_to_uri(encoded_path)
song1_track = Track(uri=song1_uri)
song2_track = Track(uri=song2_uri)
song3_track = Track(uri=song3_uri)
encoded_track = Track(uri=encoded_uri)
song1_ext_track = song1_track.replace(name='song1')
song2_ext_track = song2_track.replace(name='song2', length=60000)
encoded_ext_track = encoded_track.replace(name='æøå')


# FIXME use mock instead of tempfile.NamedTemporaryFile

class M3UToUriTest(unittest.TestCase):

    def parse(self, name):
        return translator.parse_m3u(name, data_dir)

    def test_empty_file(self):
        tracks = self.parse(path_to_data_dir('empty.m3u'))
        self.assertEqual([], tracks)
开发者ID:HaBaLeS,项目名称:mopidy,代码行数:32,代码来源:test_translator.py


注:本文中的mopidy.models.Track.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。