本文整理汇总了Python中gmusicapi.Webclient.is_authenticated方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.is_authenticated方法的具体用法?Python Webclient.is_authenticated怎么用?Python Webclient.is_authenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Webclient
的用法示例。
在下文中一共展示了Webclient.is_authenticated方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GoogleMusic
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import is_authenticated [as 别名]
class GoogleMusic(object):
def __init__(self):
self.webclient = Webclient()
self.mobileclient = Mobileclient()
def is_authenticated(self):
if not 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, Mobileclient.FROM_MAC_ADDRESS)
self.webclient.login(username, password)
except Exception as e:
raise Exception('Couldn\'t log into Google Music: ' + e.message)
def search(self, query, kind):
if self.is_authenticated():
results = self.mobileclient.search(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:
url = self.mobileclient.get_stream_url(track.get('storeId'))
stream_file.truncate(0)
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()
示例2: initDevice
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import is_authenticated [as 别名]
def initDevice(self):
device_id = self.settings.getSetting('device_id')
if not device_id:
self.main.log('Trying to fetch the device_id')
webclient = Webclient(debug_logging=False,validate=False)
self.checkCredentials()
username = self.settings.getSetting('username')
password = self.settings.getSetting('password')
webclient.login(username, password)
if webclient.is_authenticated():
devices = webclient.get_registered_devices()
for device in devices:
if device["type"] == "PHONE":
device_id = str(device["id"])
break
if device_id.lower().startswith('0x'): device_id = device_id[2:]
self.settings.setSetting('device_id',device_id)
self.main.log('device_id: '+device_id)
示例3: GoogleMusicLogin
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import is_authenticated [as 别名]
class GoogleMusicLogin():
def __init__(self):
self.main = sys.modules["__main__"]
self.xbmcgui = self.main.xbmcgui
self.xbmc = self.main.xbmc
self.settings = self.main.settings
#self.gmusicapi = gmusicapi
self.initDevice()
if self.getDevice():
self.gmusicapi = Mobileclient(debug_logging=True,validate=False)
else:
self.gmusicapi = Webclient(debug_logging=True,validate=False)
def checkCookie(self):
# Remove cookie data if it is older then 14 days
if self.settings.getSetting('cookie-date') != None and len(self.settings.getSetting('cookie-date')) > 0:
if (datetime.now() - datetime(*time.strptime(self.settings.getSetting('cookie-date'), '%Y-%m-%d %H:%M:%S.%f')[0:6])).days >= 14:
self.clearCookie()
def checkCredentials(self):
if not self.settings.getSetting('username'):
self.settings.openSettings()
def getApi(self):
return self.gmusicapi
def getDevice(self):
return self.settings.getSetting('device_id')
def initDevice(self):
device_id = self.settings.getSetting('device_id')
if not device_id:
self.main.log('Trying to fetch the device_id')
webclient = Webclient(debug_logging=False,validate=False)
self.checkCredentials()
username = self.settings.getSetting('username')
password = self.settings.getSetting('password')
webclient.login(username, password)
if webclient.is_authenticated():
devices = webclient.get_registered_devices()
for device in devices:
if device["type"] == "PHONE":
device_id = str(device["id"])
break
if device_id.lower().startswith('0x'): device_id = device_id[2:]
self.settings.setSetting('device_id',device_id)
self.main.log('device_id: '+device_id)
def clearCookie(self):
self.settings.setSetting('logged_in', "")
self.settings.setSetting('authtoken', "")
self.settings.setSetting('cookie-xt', "")
self.settings.setSetting('cookie-sjsaid', "")
self.settings.setSetting('device_id', "")
def login(self,nocache=False):
# Continue with normal procedure
if nocache or not self.settings.getSetting('logged_in'):
#if not self.gmusicapi.session.is_authenticated:
self.main.log('Logging in')
username = self.settings.getSetting('username')
password = self.settings.getSetting('password')
try:
self.gmusicapi.login(username, password)
except Exception as e:
self.main.log(repr(e))
if not self.gmusicapi.is_authenticated():
self.main.log("Login failed")
self.settings.setSetting('logged_in', "")
self.language = self.settings.getLocalizedString
dialog = self.xbmcgui.Dialog()
dialog.ok(self.language(30101), self.language(30102))
else:
self.main.log("Login succeeded")
if not nocache:
self.settings.setSetting('logged_in', "1")
self.settings.setSetting('authtoken', self.gmusicapi.session._authtoken)
self.settings.setSetting('cookie-xt', self.gmusicapi.session._rsession.cookies['xt'])
self.settings.setSetting('cookie-sjsaid', self.gmusicapi.session._rsession.cookies['sjsaid'])
self.settings.setSetting('cookie-date', str(datetime.now()))
else:
self.main.log("Loading auth from cache")
self.gmusicapi.session._authtoken = self.settings.getSetting('authtoken')
self.gmusicapi.session._rsession.cookies['xt'] = self.settings.getSetting('cookie-xt')
self.gmusicapi.session._rsession.cookies['sjsaid'] = self.settings.getSetting('cookie-sjsaid')
self.gmusicapi.session.is_authenticated = True
示例4: Pygmy
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import is_authenticated [as 别名]
#.........这里部分代码省略.........
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 ):
if not self.api.is_authenticated() == True:
return
self.library = self.api.get_all_songs()
for track in self.library:
self.add_song_to_store( track )
for artist in self.artist_dictionary:
self.artist_store.append([
artist + " (" + str( self.artist_dictionary[ artist ] ) + ")"
])
self.artist_store.append([
"All " + str( len( self.artist_dictionary ) ) + " artists (" + str( len( self.song_store ) ) + ")"
])
self.show_all()
# parse through every directory listed in the library
#for directory in self.directories:
# parse through all sub-folders looking for audio audio files
#for r,d,f in os.walk( directory ):
#for filename in f:
# mime = mimetypes.guess_type( filename )
#mime = magic.from_file( os.path.join( r, filename ), mime = True )
#print(mime)
# make sure mime-type is not None, otherwise the match will throw an error on some files
#if not mime == None:
#match = re.match( "^audio", mime )
#if match:
# it's an audio file, add it to the library even though we're not sure gstreamer can play it
#self.add_song_to_store( r, filename )
def get_image( self, icon ):
image = Gtk.Image()
image.set_from_stock( icon, Gtk.IconSize.BUTTON )
return image
def play_pause( self, widget ):
if self.playing == False:
#filepath = self.entry.get_text()
#if os.path.isfile(filepath):
self.playing = True
self.button_stop.set_sensitive( True )
image = self.get_image( Gtk.STOCK_MEDIA_PAUSE )
#self.player.set_property("uri", "file://" + filepath)
#self.player.set_state(gst.STATE_PLAYING)
else:
self.playing = False
image = self.get_image( Gtk.STOCK_MEDIA_PLAY )
self.button_play.set_image( image )
def do_stop( self, w ):
self.button_play.set_image( self.get_image( Gtk.STOCK_MEDIA_PLAY ) )
#self.player.set_state(gst.STATE_NULL)
self.playing = False
self.button_stop.set_sensitive( False )
示例5: GoogleMusic
# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import is_authenticated [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()