def prompt_for_mc_auth(): """Return a valid (user, pass, android_id) tuple by continually prompting the user.""" print("These tests will never delete or modify your music." "\n\n" "If the tests fail, you *might* end up with a test" " song/playlist in your library, though." "\n") mclient = Mobileclient() valid_mc_auth = False while not valid_mc_auth: print() email = input("Email: ") passwd = getpass() try: android_id = os.environ['GM_AA_D_ID'] except KeyError: android_id = input("Device ID ('mac' for FROM_MAC_ADDRESS): ") if android_id == "mac": android_id = Mobileclient.FROM_MAC_ADDRESS if not android_id: print('a device id must be provided') sys.exit(1) valid_mc_auth = mclient.login(email, passwd, android_id) return email, passwd, android_id
def create_api_client(self): client = Mobileclient() success = client.login(config.EMAIL, config.PASSWORD, Mobileclient.FROM_MAC_ADDRESS) if not success: raise Exception("Failed to login API client") print("Logged in API client") return client
def no_client_auth_initially(): # wc = Webclient() # assert_false(wc.is_authenticated()) mc = Mobileclient() assert_false(mc.is_authenticated()) mm = Musicmanager() assert_false(mm.is_authenticated())
def login(self): # log in to google music suppressing it's debugging messages oldloglevel = logging.getLogger().level logging.getLogger().setLevel(logging.ERROR) self.api = Mobileclient(debug_logging=False) logging.getLogger("gmusicapi.Mobileclient1").setLevel(logging.WARNING) rv = self.api.oauth_login(self.gmusic_client_id) logging.getLogger().setLevel(oldloglevel) if not rv: raise ExBpmCrawlGeneric( f"Please login to Google Music first (run gmusic-login.py)")
def init_client(self): for cred in self.cred_dir.glob("*.auth"): cli = Mobileclient() if cli.oauth_login(Mobileclient.FROM_MAC_ADDRESS, str(cred)): self.gpm[cred.stem] = cli log.info(f"Authorized: {cred.stem}") else: log.error(f"Failed to authorize: {cred.stem}") # get subscribed user for name, cli in self.gpm.items(): if cli.is_subscribed: log.info(f'Subscribed account: {name}') self.subscribed = cli
def __init__(self): assert self.__class__.instance is None, 'Can be created only once!' self.is_debug = os.getenv('CLAY_DEBUG') self.mobile_client = Mobileclient() if self.is_debug: self.mobile_client._make_call = self._make_call_proxy( self.mobile_client._make_call) self.debug_file = open('/tmp/clay-api-log.json', 'w') self._last_call_index = 0 self.cached_tracks = None self.cached_playlists = None self.invalidate_caches() self.auth_state_changed = EventHook()
def __init__(self): # self.is_debug = os.getenv('CLAY_DEBUG') self.mobile_client = Mobileclient() self.mobile_client._make_call = self._make_call_proxy( self.mobile_client._make_call) # if self.is_debug: # self.debug_file = open('/tmp/clay-api-log.json', 'w') # self._last_call_index = 0 self.cached_tracks = None self.cached_liked_songs = LikedSongs() self.cached_playlists = None self.cached_stations = None self.invalidate_caches() self.auth_state_changed = EventHook()
logging.getLogger("urllib3").setLevel(logging.ERROR) logging.getLogger("sqlitedict").setLevel(logging.ERROR) if len(sys.argv) <= 1: print( "parameters: -l | dirname [ dirname ... ]" " if dirname given, walk through it and try to make mapping between mp3 file and gmusic tracks" " and save results to local db file" " if -l given, load info from db to gmusic playlist", file=sys.stderr ) sys.exit(1) oldloglevel = logging.getLogger().level logging.getLogger().setLevel(logging.ERROR) api = Mobileclient(debug_logging=False) logging.getLogger("gmusicapi.Mobileclient1").setLevel(logging.WARNING) if not api.oauth_login(gmusic_client_id): print(f"Please login to Google Music first (run gmusic-login.py)") sys.exit(1) logging.getLogger().setLevel(oldloglevel) debug("logged in") if sys.argv[1] == "-l": # load to playlist mode playlists = api.get_all_user_playlist_contents() # find prevously created playlist with our name playlist = None for pl in playlists: if pl["name"] == playlist_name: playlist = pl
from gmusicapi.clients import Mobileclient api = Mobileclient() logged_in = api.login('<<email_address>>', '<<password>>', Mobileclient.FROM_MAC_ADDRESS) print(logged_in) playlists = api.get_all_playlists() myplaylists = list( filter(lambda p: p['name'].find('My Library') == 0, playlists)) for playlist in myplaylists: api.delete_playlist(playlist['id']) print(playlist['name'])
src = sys.argv[1] dst = sys.argv[2] with open(path.join(siteDir, 'lyrics.html')) as f: lyricsLines = f.readlines() headerLines = find(lyricsLines, '<div id="header">') contentLines = find(lyricsLines, '<div id="content">') previousLine = find(lyricsLines, PREVIOUS_FILE) nextLine = find(lyricsLines, NEXT_FILE) links = [] songs = sorted(listdir(src)) # Play Music Client mc = Mobileclient() mc.oauth_login(Mobileclient.FROM_MAC_ADDRESS) tracks = get_playlist_tracks(mc, 'Spanish') sorted_songs = [None] * len(songs) for song in songs: order = get_song_order(song, tracks) sorted_songs[order] = song for (songNumber, song) in enumerate(sorted_songs): dir = path.join(src, song) with open(path.join(dir, "original.txt")) as f: originalLines = f.readlines()
def __init__(self): self.api = Mobileclient()
def __init__(self, log=False, quiet=False): self.api = Mobileclient(debug_logging=log) self.api.logger.addHandler(logging.NullHandler()) self.print_ = safe_print if not quiet else lambda *args, **kwargs: None