本文整理汇总了Python中gmusicapi.Musicmanager.logout方法的典型用法代码示例。如果您正苦于以下问题:Python Musicmanager.logout方法的具体用法?Python Musicmanager.logout怎么用?Python Musicmanager.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmusicapi.Musicmanager
的用法示例。
在下文中一共展示了Musicmanager.logout方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager 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
示例2: songs_uploader
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import logout [as 别名]
def songs_uploader(self):
ip = urllib2.urlopen('http://ip.42.pl/raw').read() #Obtain your public IP address
mac_binary = str(get_mac()) #Obtain binary MAC address
temp = mac_binary.replace(':', '').replace('-', '').replace('.', '').upper()
mac_h3x = temp[:2] + ":" + ":".join([temp[i] + temp[i+1] for i in range(2,12,2)]) #Convert MAC from 48bit int to hexadecimal string
user = pwd.getpwuid(os.getuid())[0] #Get your system's username
api = Musicmanager()
hostname = '<' + ip + '>' + '' + '(gmusicapi-{2.0.0})'
Musicmanager.perform_oauth(storage_filepath='/home/' + user + '/.config/gmusicapi/oauth.cred', open_browser=False)
api.login(oauth_credentials='/home/' + user + '/.config/gmusicapi/oauth.cred', uploader_id=mac_h3x, uploader_name=hostname)
gmusicapi.clients.Musicmanager(debug_logging=True, validate=True)
#newWorkingDirectory = '../home'
#os.path.join(os.path.abspath(sys.path[0]), newWorkingDirectory) #Change the working directory
filepath = '/home/blackram/Scrivania/BRES_/UMM/ciao.mp3'
uploading = api.upload(filepath, transcode_quality=3, enable_matching=False)
print 'Uploading...'
f = open('uploading.txt','w') #log
f.write(str(uploading))
f.close()
final = re.search("GetUploadSession error 200: this song is already uploaded", open('uploading.txt','r').read())
if final is None:
print '\033[32mTrack uploaded!\033[0m'
else:
print '\033[31mTrack already exists in your library!\033[0m'
choice = raw_input("Exit from uploader? [Y/N] ")
if choice == 'y' or choice == 'Y':
print 'Return to main menu.'
Musicmanager.logout(revoke_oauth=False)
UMM.read_information()
elif choice == 'n' or choice == 'N':
print 'Okay.'
UMM.songs_uploader()
示例3: Musicmanager
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import logout [as 别名]
from gmusicapi import Musicmanager
import os.path
storage_filepath = '/home/alex/.local/share/gmusicapi/oauth.cred'
mm = Musicmanager()
if os.path.isfile(storage_filepath):
mm.login()
else:
Musicmanager.perform_oauth(storage_filepath, open_browser=True)
songs = mm.get_uploaded_songs(incremental=False)
print(songs)
song_id = []
for x in songs:
song_id.append(x.get('id'))
print(song_id)
for an_id in song_id:
filename, audio = mm.download_song(an_id)
with open(filename, 'wb') as f:
f.write(audio)
input("Enter: ")
mm.logout(revoke_oauth=False)
示例4: MusicSync
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager 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:
示例5: Musicmanager
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import logout [as 别名]
# remove uploaded file
if upload_ok :
os.remove(PUSH_DIR + musique)
# init
id_list={}
try : id_list = marshal.load(open(DICT_FILE, "rb"))
except : pass
mm = Musicmanager()
if not mm.login() :
mm.perform_oauth()
mm.login()
for arg in sys.argv :
if arg == 'pull' :
print 'pulling...'
pull()
elif arg == 'push' :
print 'pushing...'
push()
# finish
mm.logout()
marshal.dump(id_list, open(DICT_FILE, 'wb'))
示例6: __init__
# 需要导入模块: from gmusicapi import Musicmanager [as 别名]
# 或者: from gmusicapi.Musicmanager import logout [as 别名]
class User:
def __init__(self, email, app_data_dir):
self.email = email
self.app_data_dir = app_data_dir
self.db_lock = threading.Lock()
def init(self, oauth_credentials):
# Initialize the database
logger.info("%s: Initializing database" % self.email)
self._data_init()
# Create the Musicmanager
logger.info("%s: Logging in to Google music" % self.email)
self.mm = Musicmanager()
if not self.mm.login(oauth_credentials):
logger.info("%s: Error logging in to Google music" % self.email)
return False
# Check if we already have any watch paths configured
config = self._read_config()
watched_paths = config["watched_paths"] if "watched_paths" in config else []
logger.info("%s: Found previously watched paths %s" % (self.email, watched_paths))
# Create the FileWatcher
logger.info("%s: Creating the FileWatcher" % (self.email))
self.fw = FileWatcher(self.email, self._finished_writing_callback, watched_paths)
return True
def logout(self):
self.mm.logout()
self.fw.stop_watching()
def _read_config(self):
return util.read_config(os.path.join(self.app_data_dir, self.email, CFG_FILE_NAME))
def _write_config(self, config):
util.write_config(config, os.path.join(self.app_data_dir, self.email, CFG_FILE_NAME))
def get_watched_paths(self):
logger.debug("reading config from %s" % os.path.join(self.app_data_dir, self.email))
config = self._read_config()
logger.debug("read config: %s" % config)
return config["watched_paths"] if "watched_paths" in config else []
def add_watch_path(self, path):
# Add to file watcher
self.fw.watch(path)
# Add to the config
config = self._read_config()
if "watched_paths" not in config:
config["watched_paths"] = [path]
else:
if path not in config["watched_paths"]:
config["watched_paths"].append(path)
self._write_config(config)
def remove_watch_path(self, path):
# Remove from the file watcher
self.fw.remove_watch(path)
# Remove from the config
config = self._read_config()
if "watched_paths" in config:
if path in config["watched_paths"]:
config["watched_paths"].remove(path)
else:
logger.info("%s trying to remove watch path %s that we weren't watching" % (self.email, path))
self._write_config(config)
def set_default_action(self, default_action):
config = self._read_config()
config["default_action"] = default_action
self._write_config(config)
def get_default_action(self):
config = self._read_config()
return config.get("default_action", "scan_only")
def scan_existing_files(self):
watched_paths = self.get_watched_paths()
logger.debug("%s Scanning existing files in these directories: %s" % (self.email, watched_paths))
for watched_path in watched_paths:
logger.debug("Scanning existing files in %s" % watched_path)
for root, subFolders, files in os.walk(watched_path):
logger.debug("root: %s, subfolders: %s, files: %s" % (root, subFolders, files))
for file in files:
filename, fileExtension = os.path.splitext(file)
logger.debug("looking at file %s, filename = %s, file extension = %s" % (file, filename, fileExtension))
if fileExtension == ".mp3":
logger.debug("Found file %s" % file);
self._update_path(os.path.join(root, file), FileStatus.Scanned)
logger.debug("scanning finished");
def upload_scanned(self):
songs = self.get_all_songs()
for song_path in songs.keys():
if songs[song_path]["status"] == FileStatus.Scanned:
logger.debug("Uploading song %s" % song_path)
self.upload(song_path)
return
def _data_init(self):
with self.db_lock:
#.........这里部分代码省略.........