本文整理汇总了Python中gmusicapi.Musicmanager.get_purchased_songs方法的典型用法代码示例。如果您正苦于以下问题:Python Musicmanager.get_purchased_songs方法的具体用法?Python Musicmanager.get_purchased_songs怎么用?Python Musicmanager.get_purchased_songs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Musicmanager
的用法示例。
在下文中一共展示了Musicmanager.get_purchased_songs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FreeClient
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import get_purchased_songs [as 别名]
class FreeClient(Client):
"""
Client for free users with limited functionality.
Free users only have access to songs that they have either purchased
or uploaded, and they must be downloaded before they can be played.
Artists and albums cannot be generated, so the expand and radio methods
have no use.
"""
def __init__(self):
"""
Log into Musicmanager and get the library, either by loading an
existing library file, or by generating a new one.
"""
self.kind = 'free'
self.mm = Musicmanager()
self.mm.login()
self.songs = []
self.load_library()
if not self.songs:
self.gen_library()
def load_library(self):
path = join(common.DATA_DIR, 'library.zip')
common.w.outbar_msg('Loading library...')
if not isfile(path):
common.w.addstr(common.w.infobar, 'Could not find library file.')
return
try:
with zipfile.ZipFile(path) as z:
try:
lib = json.loads(z.read('library.json').decode('utf-8'))
except json.JSONDecodeError: # The .json file is invalid.
common.w.addstr(
common.w.infobar, 'Library file is corrupt.'
)
return
except zipfile.BadZipFile: # The .zip file is invalid.
common.w.addstr(common.w.infobar, 'Library file is corrupt.')
return
for item in lib['songs']:
try:
self.songs.append(
music_objects.LibrarySong(item, source='json'))
except KeyError: # The file has the wrong data.
common.w.addstr(common.w.infobar, 'Library file is corrupt.')
return
l = len(self.songs)
common.w.outbar_msg('Loaded %s song%s.' % (l, '' if l is 1 else 's'))
def gen_library(self):
ids = [] # Avoid duplicates between purchased and uploaded songs.
common.w.outbar_msg('Generating your library...')
for song in self.mm.get_uploaded_songs():
if song['id'] not in ids:
self.songs.append(music_objects.LibrarySong(song))
ids.append(song['id'])
for song in self.mm.get_purchased_songs():
if song['id'] not in ids:
self.songs.append(music_objects.LibrarySong(song))
ids.append(song['id'])
# Todo: Use something other than json for library storage since it
# doesn't really make logical sense (songs is a list, not a dict),
# but for now it's very easy to use.
with zipfile.ZipFile(join(common.DATA_DIR, 'library.zip'), 'w') as z:
z.writestr('library.json', json.dumps({'songs': self.songs}))
l = len(self.songs)
common.w.outbar_msg(
'Generated %d song%s.' % (l, '' if l is 1 else 's')
)
common.w.now_playing()
def expand(self, arg=None):
"""
Artists/albums cannot be generated. so free users cannot expand songs..
Keyword arguments:
arg=None: Irrelevant.
"""
common.q.error_msg('Free users cannot use expand')
def radio(self, arg=None):
"""
Artists/albums cannot be generated. so free users cannot create radio
stations.
Keyword arguments:
arg=None: Irrelevant.
"""
common.q.error_msg('Free users cannot use radio')
def search(self, query):
"""
Search the library for some query. and update the
view with the results.
Keyword arguments:
query=None: The search query.
#.........这里部分代码省略.........