def list_devices(show_desktop, show_mobile): """ List device IDs registered with Google Music. Defaults to showing both desktop and mobile IDs. """ from gmusicapi.clients import Webclient from keyring import get_password webclient = Webclient() email = app.config['GACCOUNT_EMAIL'] password = get_password('gmusicprocurator', email) if password is None: error('Password not set. Please run the set_password subcommand.') return success = webclient.login(email, password) if not success: error('Login failed.') return for device in webclient.get_registered_devices(): dname = device['name'] if len(device['name']) > 0 else device['model'] if not show_desktop and device['type'] == 'DESKTOP_APP': continue if not show_mobile and device['type'] == 'PHONE': continue print(u'* {dname} ({type}): {id}'.format(dname=dname, **device))
def list_devices(show_desktop, show_mobile): """ List device IDs registered with Google Music. Defaults to showing both desktop and mobile IDs. """ from gmusicapi.clients import Webclient from keyring import get_password webclient = Webclient() email = app.config["GACCOUNT_EMAIL"] password = get_password("gmusicprocurator", email) if password is None: error("Password not set. Please run the set_password subcommand.") return success = webclient.login(email, password) if not success: error("Login failed.") return for device in webclient.get_registered_devices(): dname = device["name"] if len(device["name"]) > 0 else device["model"] if not show_desktop and device["type"] == "DESKTOP_APP": continue if not show_mobile and device["type"] == "PHONE": continue print(u"* {dname} ({type}): {id}".format(dname=dname, **device))
def _login_mc(self): APP_NAME = 'gmusic-sync-playlist' CONFIG_FILE = 'auth.cfg' config = SafeConfigParser({ 'username': '', 'device_id': '' }) config.read(CONFIG_FILE) if not config.has_section('auth'): config.add_section('auth') username = config.get('auth','username') password = None if username != '': password = keyring.get_password(APP_NAME, username) if password == None or not self.mc.login(username, password): while 1: username = raw_input("Username: "******"Password: "******"Sign-on failed." config.set('auth', 'username', username) with open(CONFIG_FILE, 'wb') as f: config.write(f) keyring.set_password(APP_NAME, username, password) device_id = config.get('auth', 'device_id') if device_id == '': wc = Webclient() if not wc.login(username, password): raise Exception('could not log in via Webclient') devices = wc.get_registered_devices() mobile_devices = [d for d in devices if d[u'type'] in (u'PHONE', u'IOS')] if len(mobile_devices) < 1: raise Exception('could not find any registered mobile devices') device_id = mobile_devices[0][u'id'] if device_id.startswith(u'0x'): device_id = device_id[2:] config.set('auth', 'device_id', device_id) with open(CONFIG_FILE, 'wb') as f: config.write(f) print('Device ID: {}'.format(device_id)) self.mc.device_id = device_id
def prompt_for_wc_auth(): """Return a valid (user, pass) 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") wclient = Webclient() valid_wc_auth = False while not valid_wc_auth: print email = raw_input("Email: ") passwd = getpass() valid_wc_auth = wclient.login(email, passwd) return email, passwd
def list_devices(show_desktop, show_mobile): """ List device IDs registered with Google Music. Defaults to showing both desktop and mobile IDs. """ from gmusicapi.clients import Webclient webclient = Webclient() success = webclient.login(app.config['GACCOUNT_EMAIL'], app.config['GACCOUNT_PASSWORD']) if not success: print('Login failed.', file=sys.stderr) return for device in webclient.get_registered_devices(): dname = device['name'] if len(device['name']) > 0 else device['model'] if not show_desktop and device['type'] == 'DESKTOP_APP': continue if not show_mobile and device['type'] == 'PHONE': continue print(u'* {dname} ({type}): {id}'.format(dname=dname, **device))
def prompt_for_wc_auth(): """Return a valid (user, pass) 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") wclient = Webclient() valid_wc_auth = False while not valid_wc_auth: print() email = input("Email: ") passwd = getpass() valid_wc_auth = wclient.login(email, passwd) return email, passwd
def freeze_login_details(): """Searches the environment for credentials, and freezes them to client.login if found. If no auth is present in the env, the user is prompted. OAuth is read from the default path. If running on Travis, the prompt will never be fired; sys.exit is called if the envvars are not present. """ #Attempt to get auth from environ. user, passwd, refresh_tok = [ os.environ.get(name) for name in ('GM_USER', 'GM_PASS', 'GM_OAUTH') ] on_travis = os.environ.get('TRAVIS') mm_kwargs = {} wc_kwargs = {} has_env_auth = user and passwd and refresh_tok if not has_env_auth and on_travis: print 'on Travis but could not read auth from environ; quitting.' sys.exit(1) if os.environ.get('TRAVIS'): #Travis runs on VMs with no "real" mac - we have to provide one. mm_kwargs.update({ 'uploader_id': travis_id, 'uploader_name': travis_name }) if has_env_auth: wc_kwargs.update({'email': user, 'password': passwd}) # mm expects a full OAuth2Credentials object credentials = credentials_from_refresh_token(refresh_tok) mm_kwargs.update({'oauth_credentials': credentials}) else: # no travis, no credentials # we need to login here to verify their credentials. # the authenticated api is then thrown away. wclient = Webclient() valid_auth = False 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." "You must have oauth credentials stored at the default" " path by Musicmanager.perform_oauth prior to running.") while not valid_auth: print email = raw_input("Email: ") passwd = getpass() valid_auth = wclient.login(email, passwd) wc_kwargs.update({'email': email, 'password': passwd}) # globally freeze our params in place. # they can still be overridden manually; they're just the defaults now. Musicmanager.login = MethodType( update_wrapper(partial(Musicmanager.login, **mm_kwargs), Musicmanager.login), None, Musicmanager) Webclient.login = MethodType( update_wrapper(partial(Webclient.login, **wc_kwargs), Webclient.login), None, Webclient)
def no_client_auth_initially(): wc = Webclient() assert_false(wc.is_authenticated()) mm = Musicmanager() assert_false(mm.is_authenticated())
def freeze_login_details(): """Searches the environment for credentials, and freezes them to client.login if found. If no auth is present in the env, the user is prompted. OAuth is read from the default path. If running on Travis, the prompt will never be fired; sys.exit is called if the envvars are not present. """ #Attempt to get auth from environ. user, passwd, refresh_tok = [os.environ.get(name) for name in ('GM_USER', 'GM_PASS', 'GM_OAUTH')] on_travis = os.environ.get('TRAVIS') mm_kwargs = {} wc_kwargs = {} has_env_auth = user and passwd and refresh_tok if not has_env_auth and on_travis: print 'on Travis but could not read auth from environ; quitting.' sys.exit(1) if os.environ.get('TRAVIS'): #Travis runs on VMs with no "real" mac - we have to provide one. mm_kwargs.update({'uploader_id': travis_id, 'uploader_name': travis_name}) if has_env_auth: wc_kwargs.update({'email': user, 'password': passwd}) # mm expects a full OAuth2Credentials object credentials = credentials_from_refresh_token(refresh_tok) mm_kwargs.update({'oauth_credentials': credentials}) else: # no travis, no credentials # we need to login here to verify their credentials. # the authenticated api is then thrown away. wclient = Webclient() valid_auth = False 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." "You must have oauth credentials stored at the default" " path by Musicmanager.perform_oauth prior to running.") while not valid_auth: print email = raw_input("Email: ") passwd = getpass() valid_auth = wclient.login(email, passwd) wc_kwargs.update({'email': email, 'password': passwd}) # globally freeze our params in place. # they can still be overridden manually; they're just the defaults now. Musicmanager.login = MethodType( update_wrapper(partial(Musicmanager.login, **mm_kwargs), Musicmanager.login), None, Musicmanager ) Webclient.login = MethodType( update_wrapper(partial(Webclient.login, **wc_kwargs), Webclient.login), None, Webclient )
import os import subprocess from django.shortcuts import render from gmusicapi.clients import Webclient, Mobileclient import mutagen from mutagen.easyid3 import EasyID3 import TTR.settings from django.http import HttpResponse import yaml from game.models import DownloadedTrack import json from django.core.serializers.json import DjangoJSONEncoder api = Mobileclient() webCli = Webclient() api.login(TTR.settings.UN, TTR.settings.P) webCli.login(TTR.settings.UN, TTR.settings.P) # TODO: Will want to separate these files. # ============================================================================== # Page Renderings # 1) Search Page Rendering # ============================================================================= # def index(request): # def search(request):