本文整理汇总了Python中gmusicapi.Webclient.get_stream_audio方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.get_stream_audio方法的具体用法?Python Webclient.get_stream_audio怎么用?Python Webclient.get_stream_audio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Webclient
的用法示例。
在下文中一共展示了Webclient.get_stream_audio方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_audio [as 别名]
class Player:
def __init__(self, library_manager):
pygame.init()
pygame.mixer.init()
self.library_manager = library_manager
self.webapi = Webclient()
try:
self.webapi.login(setting.GUSER, setting.GPASS)
except:
sys.stderr.write('Problem with authentication on Google server\n')
def play(self, songId):
f = open('tostream.mp3', 'w')
song = self.webapi.get_stream_audio(songId)
f.write(song)
f.close()
#songFile = StringIO.StringIO(song)
pygame.mixer.music.load('tostream.mp3')
pygame.mixer.music.play()
print('streaming audio: ' + songId)
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)
示例2: gMusicClient
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_audio [as 别名]
class gMusicClient(object):
logged_in = False
api = None
playlists = dict()
library = dict()
def __init__(self, email, password):
self.api = Webclient()
logged_in = False
attempts = 0
if len(password) is 0:
password = getpass("Google password:")
while not self.logged_in and attempts < 3:
self.logged_in = self.api.login(email, password)
attempts += 1
def __del__(self):
self.api.logout()
def updateLocalLib(self):
songs = list()
self.library = dict()
self.playlists = dict()
songs = self.api.get_all_songs()
for song in songs:
song_title = song["title"]
if song["artist"] == "":
song_artist = "Unknown Artist"
else:
song_artist = song["artist"]
if song["album"] == "":
song_album = "Unknown Album"
else:
song_album = song["album"]
if not (song_artist in self.library):
albums_dict = dict()
self.library[song_artist] = albums_dict
if not (song_album in self.library[song_artist]):
song_list = list()
self.library[song_artist][song_album] = song_list
self.library[song_artist][song_album].append(song)
plists = self.api.get_all_playlist_ids(auto=True, user=True)
for u_playlist, u_playlist_id in plists["user"].iteritems():
self.playlists[u_playlist] = self.api.get_playlist_songs(u_playlist_id[0])
self.playlists["Thumbs Up"] = [song for song in songs if song['rating'] == 5]
def getSongStream(self, song):
return self.api.get_stream_urls(song["id"])
def getStreamAudio(self, song):
return self.api.get_stream_audio(song["id"])
def thumbsUp(self, song):
try:
song["rating"] = 5
song_list = [song]
self.api.change_song_metadata(song_list)
print "Gave a Thumbs Up to {0} by {1} on Google Play.".format(song["title"].encode("utf-8"), song["artist"].encode("utf-8"))
except:
print "Error giving a Thumbs Up on Google Play."
示例3: raw_input
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_audio [as 别名]
chosen = playlist
tracks = []
for x in chosen.get("tracks"):
tracks.append(x)
if raw_input("Shuffle?\n").lower() == "yes":
random.shuffle(tracks)
for song in tracks:
print(song.get("trackId"))
# info = mc.get_track_info(song.get("id"))
# print(info.get("title"))
f = open("test.mp3", "w")
f.write(wc.get_stream_audio(song.get("trackId"), use_range_header=None))
f.close()
pygame.mixer.init()
pygame.mixer.music.load("test.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
ctr = open("ctr.txt", "r")
if ctr.read() == "pause":
pygame.mixer.music.pause()
while True:
ctr = open("ctr.txt", "r")
if ctr.read() == "play":
pygame.mixer.music.unpause()
break
sleep(2)
sleep(1)