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


Python models.Playlist类代码示例

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


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

示例1: refresh

    def refresh(self):
        playlists = []

        for playlist in self.backend.session.get_all_playlist_contents():
            tracks = []
            for track in playlist['tracks']:
                if not track['deleted']:
                    tracks += self.backend.library.lookup('gmusic:track:' +
                                                          track['trackId'])

            playlist = Playlist(uri='gmusic:playlist:' + playlist['id'],
                                name=playlist['name'],
                                tracks=tracks)
            playlists.append(playlist)

        for playlist in self.backend.session.get_all_playlists():
            if playlist.get('type') == 'SHARED':
                tracks = []
                tracklist = self.backend.session.get_shared_playlist_contents(
                    playlist['shareToken'])
                for track in tracklist:
                        tracks += self.backend.library.lookup('gmusic:track:' +
                                                              track['trackId'])
                playlist = Playlist(uri='gmusic:playlist:' + playlist['id'],
                                    name=playlist['name'],
                                    tracks=tracks)
                playlists.append(playlist)

        self.playlists = playlists
        listener.BackendListener.send('playlists_loaded')
开发者ID:bubbltrubl,项目名称:mopidy-gmusic,代码行数:30,代码来源:playlists.py

示例2: test_with_new_name

 def test_with_new_name(self):
     tracks = [Track()]
     last_modified = datetime.datetime.utcnow()
     playlist = Playlist(uri="an uri", name="a name", tracks=tracks, last_modified=last_modified)
     new_playlist = playlist.copy(name="another name")
     self.assertEqual(new_playlist.uri, "an uri")
     self.assertEqual(new_playlist.name, "another name")
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, last_modified)
开发者ID:serman,项目名称:mopidy,代码行数:9,代码来源:models_test.py

示例3: test_with_new_uri

 def test_with_new_uri(self):
     tracks = [Track()]
     last_modified = dt.datetime.now()
     playlist = Playlist(uri=u"an uri", name=u"a name", tracks=tracks, last_modified=last_modified)
     new_playlist = playlist.copy(uri=u"another uri")
     self.assertEqual(new_playlist.uri, u"another uri")
     self.assertEqual(new_playlist.name, u"a name")
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, last_modified)
开发者ID:Amli,项目名称:mopidy,代码行数:9,代码来源:models_test.py

示例4: test_with_new_last_modified

 def test_with_new_last_modified(self):
     tracks = [Track()]
     last_modified = datetime.datetime.utcnow()
     new_last_modified = last_modified + datetime.timedelta(1)
     playlist = Playlist(uri="an uri", name="a name", tracks=tracks, last_modified=last_modified)
     new_playlist = playlist.copy(last_modified=new_last_modified)
     self.assertEqual(new_playlist.uri, "an uri")
     self.assertEqual(new_playlist.name, "a name")
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, new_last_modified)
开发者ID:serman,项目名称:mopidy,代码行数:10,代码来源:models_test.py

示例5: test_with_new_uri

 def test_with_new_uri(self):
     tracks = [Track()]
     last_modified = datetime.datetime.utcnow()
     playlist = Playlist(
         uri='an uri', name='a name', tracks=tracks,
         last_modified=last_modified)
     new_playlist = playlist.copy(uri='another uri')
     self.assertEqual(new_playlist.uri, 'another uri')
     self.assertEqual(new_playlist.name, 'a name')
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, last_modified)
开发者ID:eisnerd,项目名称:mopidy,代码行数:11,代码来源:models_test.py

示例6: test_with_new_name

 def test_with_new_name(self):
     tracks = [Track()]
     last_modified = 1390942873000
     playlist = Playlist(
         uri='an uri', name='a name', tracks=tracks,
         last_modified=last_modified)
     new_playlist = playlist.replace(name='another name')
     self.assertEqual(new_playlist.uri, 'an uri')
     self.assertEqual(new_playlist.name, 'another name')
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, last_modified)
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:11,代码来源:test_models.py

示例7: test_with_new_last_modified

 def test_with_new_last_modified(self):
     tracks = [Track()]
     last_modified = 1390942873000
     new_last_modified = last_modified + 1000
     playlist = Playlist(
         uri='an uri', name='a name', tracks=tracks,
         last_modified=last_modified)
     new_playlist = playlist.copy(last_modified=new_last_modified)
     self.assertEqual(new_playlist.uri, 'an uri')
     self.assertEqual(new_playlist.name, 'a name')
     self.assertEqual(list(new_playlist.tracks), tracks)
     self.assertEqual(new_playlist.last_modified, new_last_modified)
开发者ID:FabrizioCongia,项目名称:mopidy,代码行数:12,代码来源:test_models.py

示例8: __init__

 def __init__(self, config, backend):
     super(InternetArchivePlaylistsProvider, self).__init__(backend)
     self._bookmarks = []
     self._username = config[Extension.ext_name]['username']
     self._playlist = Playlist(
         uri='%s://%s/bookmarks' % (Extension.ext_name, self._username),
         name='Internet Archive Bookmarks'
     )
     self.playlists = [self._playlist]
开发者ID:soujak,项目名称:mopidy-internetarchive,代码行数:9,代码来源:playlists.py

示例9: InternetArchivePlaylistsProvider

class InternetArchivePlaylistsProvider(backend.PlaylistsProvider):

    def __init__(self, config, backend):
        super(InternetArchivePlaylistsProvider, self).__init__(backend)
        self._bookmarks = []
        self._username = config[Extension.ext_name]['username']
        self._playlist = Playlist(
            uri='%s://%s/bookmarks' % (Extension.ext_name, self._username),
            name='Internet Archive Bookmarks'
        )
        self.playlists = [self._playlist]

    def create(self, name):
        pass  # TODO

    def delete(self, uri):
        pass  # TODO

    def lookup(self, uri):
        for playlist in self.playlists:
            if playlist.uri == uri:
                return playlist
        return None

    def refresh(self):
        try:
            bookmarks = self.backend.client.bookmarks(self._username)
            logger.info('Loaded %d Internet Archive bookmarks', len(bookmarks))
            if bookmarks == self._bookmarks:
                return  # unchanged
            # FIXME: this can probably be removed when playlists return refs...
            tracks = self._tracks(bookmarks)
            logger.info('Loaded %d Internet Archive tracks', len(tracks))
            self.playlists = [self._playlist.copy(tracks=tracks)]
            backend.BackendListener.send('playlists_loaded')
            self._bookmarks = bookmarks
        except Exception as e:
            logger.error('Error loading Internet Archive bookmarks: %s', e)

    def save(self, playlist):
        pass  # TODO

    def _tracks(self, bookmarks):
        tracks = []
        for doc in bookmarks:
            tracks.extend(self.backend.library._lookup(doc['identifier']))
        return tracks
开发者ID:soujak,项目名称:mopidy-internetarchive,代码行数:47,代码来源:playlists.py

示例10: test_copying_playlist

 def test_copying_playlist(self):
     playlist = Playlist()
     self.compare(playlist, playlist.copy())
开发者ID:serman,项目名称:mopidy,代码行数:3,代码来源:models_test.py

示例11: test_last_modified

 def test_last_modified(self):
     last_modified = 1390942873000
     playlist = Playlist(last_modified=last_modified)
     self.assertEqual(playlist.last_modified, last_modified)
     with self.assertRaises(AttributeError):
         playlist.last_modified = None
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:6,代码来源:test_models.py

示例12: test_tracks

 def test_tracks(self):
     tracks = [Track(), Track(), Track()]
     playlist = Playlist(tracks=tracks)
     self.assertEqual(list(playlist.tracks), tracks)
     with self.assertRaises(AttributeError):
         playlist.tracks = None
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:6,代码来源:test_models.py

示例13: test_name

 def test_name(self):
     name = 'a name'
     playlist = Playlist(name=name)
     self.assertEqual(playlist.name, name)
     with self.assertRaises(AttributeError):
         playlist.name = None
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:6,代码来源:test_models.py

示例14: test_uri

 def test_uri(self):
     uri = 'an_uri'
     playlist = Playlist(uri=uri)
     self.assertEqual(playlist.uri, uri)
     with self.assertRaises(AttributeError):
         playlist.uri = None
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:6,代码来源:test_models.py

示例15: test_replace_playlist

 def test_replace_playlist(self):
     playlist = Playlist()
     self.compare(playlist, playlist.replace())
开发者ID:AddBassStudios,项目名称:mopidy,代码行数:3,代码来源:test_models.py


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