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


Python Webclient.logout方法代码示例

本文整理汇总了Python中gmusicapi.Webclient.logout方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.logout方法的具体用法?Python Webclient.logout怎么用?Python Webclient.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gmusicapi.Webclient的用法示例。


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

示例1: __init__

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
class gmObject:
    
    def __init__(self):
        self.mc = Mobileclient()
        self.wc = Webclient()
        self.mm = Musicmanager()
    
    def login(self, username, password):
        error.e = 0
        
        if not self.mc.login(username, password):
            gmtPrintV("gmObject.login: Wrong username or password (or no internet connection)")
            error.e = error.LOGIN_FAILED
            return
        
        if not self.wc.login(username, password):
            gmtPrintV("gmObject.login: Wrong username or password (or no internet connection)")
            error.e = error.LOGIN_FAILED
            return
        
        if not self.mm.login(config.cred_path):
            gmtPrintV("gmObject.login: Wrong credentials (or no internet connection)")
            error.e = error.LOGIN_FAILED
            return
        
    def logout(self):
        error.e = 0
        
        try:
            self.mc.logout()
            self.wc.logout()
            self.mm.logout()
        except:
            gmtPrintV("gmObject.logout: Logout failed")
            error.e = error.LOGOUT_FAILED
开发者ID:Shadowigor,项目名称:gmusic-tools,代码行数:37,代码来源:gmobject.py

示例2: gMusicClient

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [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."
开发者ID:vulcanfk,项目名称:PlayMusicCL,代码行数:62,代码来源:PlayMusicCL.py

示例3: get_deviceid

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
 def get_deviceid(self, username, password):
     logger.warning(u'No mobile device ID configured. '
                    u'Trying to detect one.')
     webapi = Webclient(validate=False)
     webapi.login(username, password)
     devices = webapi.get_registered_devices()
     deviceid = None
     for device in devices:
         if device['type'] == 'PHONE' and device['id'][0:2] == u'0x':
             # Omit the '0x' prefix
             deviceid = device['id'][2:]
             break
     webapi.logout()
     if deviceid is None:
         logger.error(u'No valid mobile device ID found. '
                      u'Playing songs will not work.')
     else:
         logger.info(u'Using mobile device ID %s', deviceid)
     return deviceid
开发者ID:bubbltrubl,项目名称:mopidy-gmusic,代码行数:21,代码来源:session.py

示例4: main

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
def main():
    parser = argparse.ArgumentParser(description = 'List all devices registered for Google Play Music')

    parser.add_argument('username', help = 'Your Google Play Music username')
    parser.add_argument('password', help = 'Your very secret password')

    args = parser.parse_args()
    
    api = Webclient(validate = False)

    if not api.login(args.username, args.password):
        print "Could not login to Google Play Music. Incorrect username or password."
        return

    for device in api.get_registered_devices():
        print '%s | %s | %s | %s' % (device['name'],
                                     device.get('manufacturer'),
                                     device['model'],
                                     device['id'])

    api.logout()
开发者ID:digiltd,项目名称:squeezebox-googlemusic,代码行数:23,代码来源:mobile_devices.py

示例5: main

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
def main():
  api = Webclient()
  login(api)
  playlists = api.get_all_playlist_ids().pop('user')
  indexed_playlist_names = index_playlists(playlists)
  curlist = choose_playlist(api, indexed_playlist_names, playlists)[0]
  songs = api.get_playlist_songs(curlist)
  print songs

  curpos = 0;
  cursongid = songs[curpos]['id']
  cursongurl = api.get_stream_url(cursongid)
  print cursongurl
  #cursong = play(cursongurl)

  while 1:
    if cursong.poll() is not None:
      curpos += 1
      cursongid = songs[curpos]['id']
      cursong = play(get_stream_url(cursongid))
    c = getch() 
    if (c == 'q'):
      api.logout() 
      break
开发者ID:skrblr,项目名称:gmusicbar,代码行数:26,代码来源:gmusicbar.py

示例6: MusicSync

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]

#.........这里部分代码省略.........

        for fn in pc_songs:
            if self.file_already_in_list(fn, goog_songs, self.all_songs):
                existing_files += 1
                continue
            print ""
            print "Adding: %s" % os.path.basename(fn).encode('cp1252')
            #print "Adding: %s" % os.path.basename(fn)
            #online = False
            online = self.find_song(fn, goog_songs, self.all_songs)
            #online = self.find_song(fn)
            song_id = None
            if online:
                song_id = online['id']
                print "   already uploaded [%s]" % song_id
            else:
                attempts = 0
                result = []
                while not result and attempts < MAX_UPLOAD_ATTEMPTS_PER_FILE:
                    print "   uploading... (may take a while)"
                    attempts += 1
                    try:
                        result = self.mm.upload(fn)
                    except (BadStatusLine, CannotSendRequest):
                        # Bail out if we're getting too many disconnects
                        if fatal_count >= MAX_CONNECTION_ERRORS_BEFORE_QUIT:
                            print ""
                            print "Too many disconnections - quitting. Please try running the script again."
                            print ""
                            exit()

                        print "Connection Error -- Reattempting login"
                        fatal_count += 1
                        self.wc.logout()
                        self.mc.logout()
                        self.mm.logout()
                        result = []
                        time.sleep(STANDARD_SLEEP)

                    except:
                        result = []
                        time.sleep(STANDARD_SLEEP)

                try:
                    if result[0]:
                        song_id = result[0].itervalues().next()
                    else:
                        song_id = result[1].itervalues().next()
                    print "   upload complete [%s]" % song_id
                except:
                    print "      upload failed - skipping"
                    tag = self.get_id3_tag(fn)
                    print "      failed song:\t%s\t%s\t%s" % (tag['title'].encode('cp1252'), tag['artist'].encode('cp1252'), tag['album'].encode('cp1252'))

            if not song_id:
                failed_files += 1
                continue

            added = self.mc.add_songs_to_playlist(plid, song_id)
            time.sleep(.3) # Don't spam the server too fast...
            print "   done adding to playlist"
            added_files += 1

        if remove_missing:
            for g in goog_songs:
                for s in self.all_songs:
开发者ID:Platinkreuz,项目名称:m3uGoogleMusicSync,代码行数:70,代码来源:musicsync.py

示例7: int

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
while True:
	chosen_number = int(raw_input('Choose a playlist to export (enter the number): '))
	if chosen_number < i and chosen_number >= 0:
		break
	else:
		print 'Error, try again'

i = 1
for playlist in api.get_all_playlist_ids()['user']:
	if i == chosen_number:
		chosen_id = api.get_all_playlist_ids()['user'][playlist][0]
		chosen_name = playlist
		break
	else:
		i += 1

songs = []

for song in api.get_playlist_songs(chosen_id):
	songs.append(song['artist'] + ' - ' + song['album'] + ' - ' + song['name'])

songs.sort(key=lambda s: s.lower())

f = open(os.path.join(os.path.dirname(__file__), playlist + '.txt'), "w")
for song in songs:
 	f.write(song.encode("utf-8") + "\n")

api.logout()

raw_input('Success! Press enter to exit.')
开发者ID:joebartlett94,项目名称:GMusicPlaylistExporter,代码行数:32,代码来源:GmusicPlaylistExporter.py

示例8: GoogleMusicLogin

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [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

        if self.getDevice():
            self.gmusicapi = Mobileclient(debug_logging=False,validate=False)
        else:
            self.gmusicapi = Webclient(debug_logging=False,validate=False)


    def checkCookie(self):
        # Remove cookie data if it is older then 7 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 >= 7:
                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()
                self.main.log(repr(devices))
                for device in devices:
                    if device["type"] in ("PHONE","IOS"):
                        device_id = str(device["id"])
                        break
            if device_id:
                if device_id.lower().startswith('0x'): device_id = device_id[2:]
                self.settings.setSetting('device_id',device_id)
                self.main.log('Found 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 logout(self):
        self.gmusicapi.logout()

    def login(self,nocache=False):
        if nocache or not self.settings.getSetting('logged_in'):
            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))
                self.settings.openSettings()
            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
开发者ID:Mondego,项目名称:pyreco,代码行数:96,代码来源:allPythonContent.py

示例9: str

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import logout [as 别名]
	reporting_json = reporting_json + str(error_playlist) + ','
if (len(reporting_playlists_error) > 0):
	reporting_json = reporting_json[:-1] #Removes last ","
reporting_json = reporting_json + u']}}'
logger.debug('REPORTING JSON: ' + str(reporting_json))

reporting_json_filename = 'reports/report_' + now.strftime("%Y-%m-%d") + '.json'
with open(reporting_json_filename, 'w') as output_file:
	output_file.write(reporting_json)

### UPDATE favorites_uploaded JSON
updated_favorites = u'{"favorites_uploaded": {"tracks": ['
for track in uploaded_tracks:
	updated_favorites = updated_favorites + '{"id": ' + str(track) + '},'
if (len(uploaded_tracks) > 0):
	updated_favorites = updated_favorites[:-1] #Removes last ","
updated_favorites = updated_favorites + u'], "playlists": ['
for playlist in uploaded_playlists:
	updated_favorites = updated_favorites + '{"id": ' + str(playlist) + '},'
if (len(uploaded_playlists) > 0):
	updated_favorites = updated_favorites[:-1] #Removes last ","
updated_favorites = updated_favorites + u']}}'

logger.debug('UPDATED UPLOADED FAVORITES: ' + str(updated_favorites))

with open('favorites_uploaded.json', 'w') as outfile:
	outfile.write(updated_favorites)

### LOG OUT
webclient.logout()
logger.info('Done! Edgar out!')
开发者ID:FischerLouis,项目名称:Edgar,代码行数:33,代码来源:edgar.py


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