本文整理汇总了Python中gmusicapi.Webclient.get_stream_urls方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.get_stream_urls方法的具体用法?Python Webclient.get_stream_urls怎么用?Python Webclient.get_stream_urls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Webclient
的用法示例。
在下文中一共展示了Webclient.get_stream_urls方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gMusicClient
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [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."
示例2: __init__
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [as 别名]
class UrlGetter:
def __init__(self, sck_path, user, passwd):
pygame.init()
pygame.mixer.init()
self.sck_path = sck_path
self.webapi = Webclient()
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# Look if socket has been created
try:
os.remove(self.sck_path)
except OSError:
pass
# GMusic login
try:
self.webapi.login(user, passwd)
except:
sys.stderr.write('Problem with authentication on Google server\n')
self.init_socket()
def init_socket(self):
self.socket.bind(self.sck_path)
self.socket.listen(3)
while 1:
conn, addr = self.socket.accept()
self.manage_connection(conn)
def manage_connection(self, conn):
data = conn.recv(50)
if data:
try:
stream_url = self.webapi.get_stream_urls(data)
except exceptions.CallFailure:
conn.close()
return
conn.send(stream_url[0])
print('url_getter.py: Ottenuta URL -> ' + stream_url[0])
conn.close()
示例3: Pygmy
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [as 别名]
#.........这里部分代码省略.........
self.songs.append_column( songs_columns[ "playing" ] )
self.songs.append_column( songs_columns[ "track" ] )
self.songs.append_column( songs_columns[ "title" ] )
self.songs.append_column( songs_columns[ "artist" ] )
self.songs.append_column( songs_columns[ "album" ] )
self.songs.append_column( songs_columns[ "year" ] )
self.songs.append_column( songs_columns[ "time" ] )
songs_scroll.add( self.songs )
# put together the browser window
browser.add( columns )
browser.add( songs_scroll )
self.find_songs()
# demo comparison for sorting treemodelsorted
def compare( self, model, row1, row2, user_data ):
sort_column, _ = model.get_sort_column_id()
value1 = model.get_value(row1, sort_column)
value2 = model.get_value(row2, sort_column)
if value1 < value2:
return -1
elif value1 == value2:
return 0
else:
return 1
def on_song_activate( self, widget, path, col ):
# set the player state to null
self.player.set_state( Gst.State.NULL )
# set the player uri to the activated song url
# HEYYYYYY
self.player.set_property( "uri", self.api.get_stream_urls( self.song_store[ path ][ 1 ] )[ 0 ] )
# set the player state to playing
self.player.set_state( Gst.State.PLAYING )
def add_artist_to_store( self, artist ):
if not artist in self.artist_dictionary:
self.artist_dictionary[ artist ] = 0
self.artist_dictionary[ artist ] += 1
def add_song_to_store( self, track ):
this_artist = track[ "artist" ] if not track[ "artist" ] == "" else "Unknown"
self.add_artist_to_store( this_artist )
# format the time to minutes:seconds and remove the leading 0
time_string = re.sub(
"^0", "",
time.strftime( "%H:%M:%S", time.gmtime( int( track[ "durationMillis" ] ) / 1000 ) )
)
self.song_store.append([
"",
track["id"],
track["track"],
track["title"] if not track[ "title" ] == "" else "Unknown",
this_artist,
track["album"] if not track[ "album" ] == "" else "Unknown",
str( track[ "year" ] if not track[ "year" ] == 0 else "" ),
str( time_string )
])
def find_songs( self ):
示例4: GoogleMusic
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [as 别名]
class GoogleMusic(RadiopieModule):
def run(self):
log.info("Google Music started")
self._lcd.setFirst(" Google")
self.__player = None
self.__api = None
self.__library = None
self.loadConfiguration()
self.googleMusicConnection()
while not self._terminate.isSet():
if(self._ok.isSet()):
self._ok.clear()
self.playCurrentSong()
if(self._left.isSet()):
self._left.clear()
self._terminate.set()
time.sleep(1)
self.setdown()
def googleMusicConnection(self):
log.info("Login as user " + self.__user + " ...")
self._lcd.setLast(" Login..")
self.__api = Webclient()
self.__api.login(self.__user, self.__password)
log.info("Loading Library")
self._lcd.setLast(" Loading")
self.__library = self.__api.get_all_songs()
self._lcd.setLast(" Ready")
def playCurrentSong(self):
log.info("Playing a song")
if(self.__player == None):
self.setup()
else:
self.__player.set_state(gst.STATE_NULL)
self.__currentsong = self.__library[random.randint(0,len(self.__library))]
self._lcd.setLast(self.__currentsong["title"].encode("utf-8"))
url = self.__api.get_stream_urls(self.__currentsong["id"])
self.__player.set_property("uri", url[0])
self.__player.set_state(gst.STATE_PLAYING)
log.info("Playing song " + self.__currentsong["title"] + " ... ")
def setup(self):
self.__player = gst.element_factory_make("playbin2", "player")
bus = self.__player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_status)
def loadConfiguration(self):
log.info("Loading settings from json ...")
json_data = open('defaults.json')
data = json.load(json_data)
self.__user = data["google-music-user"]
self.__password = data["google-music-password"]
def setdown(self):
self.__player.set_state(gst.STATE_NULL)
def on_status(self, bus, message):
t = message.type
if(t == gst.MESSAGE_EOS):
log.info("Song end")
self.playCurrentSong()
if(t == pygst.MESSAGE_ERROR):
err, debug = message.parse_error()
log.error(err)
log.debug(debug)
self.__player.set_state(gst.STATE_NONE)
@staticmethod
def getName():
return "Google Music"
示例5: GoogleMusic
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [as 别名]
class GoogleMusic(object):
def __init__(self):
self.webclient = Webclient()
self.mobileclient = Mobileclient()
def is_authenticated(self):
if self.webclient.is_authenticated():
if self.mobileclient.is_authenticated():
return True
return False
def login(self, username, password):
if not self.is_authenticated():
try:
self.mobileclient.login(username, password)
self.webclient.login(username, password)
except:
raise Exception('Couldn\'t log into Google Music')
def search(self, query, kind):
if self.is_authenticated():
results = self.mobileclient.search_all_access(query)[kind + '_hits']
return results
def get_track(self, store_id):
return self.mobileclient.get_track_info(store_id)
def save_stream(self, track, destination):
if self.is_authenticated():
with open(destination, 'w+b') as stream_file:
urls = self.webclient.get_stream_urls(track.get('storeId'))
if len(urls) == 1:
stream_file.write(self.webclient.session._rsession.get(urls[0]).content)
range_pairs = [[int(s) for s in val.split('-')]
for url in urls
for key, val in parse_qsl(urlparse(url)[4])
if key == 'range']
for url, (start, end) in zip(urls, range_pairs):
stream_file.truncate(start)
stream_file.seek(0, 2)
audio = self.webclient.session._rsession.get(url).content
stream_file.write(audio)
tag = easyid3.EasyID3()
tag['title'] = track.get('title').__str__()
tag['artist'] = track.get('artist').__str__()
tag['album'] = track.get('album').__str__()
tag['date'] = track.get('year').__str__()
tag['discnumber'] = track.get('discNumber').__str__()
tag['tracknumber'] = track.get('trackNumber').__str__()
tag['performer'] = track.get('albumArtist').__str__()
tag.save(destination)
tag = mp3.MP3(destination)
tag.tags.add(
id3.APIC(3, 'image/jpeg', 3, 'Front cover', urllib.urlopen(track.get('albumArtRef')[0].get('url')).read())
)
tag.save()
示例6: Webclient
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_stream_urls [as 别名]
#!/usr/bin/python
from gmusicapi import Webclient
import sys
api = Webclient()
api.login(sys.argv[1],sys.argv[2])
if sys.argv[3] != '':
streamurl = api.get_stream_urls(sys.argv[3])[0]
print streamurl