#!python

from getpass import getpass
from gmusicapi import Mobileclient


# Try to print out some valid device IDs.

try:
    mc = Mobileclient()
    email = input('Enter your email: ').strip()
    if '@' not in email or '.' not in email:
        print('Invalid email format.')
        exit(1)
    password = getpass('Enter password for %s: ' % email)

    if not mc.login(email, password, mc.FROM_MAC_ADDRESS):
        print('Login failed, verify your email and password.')
        exit(1)

    for i, id in enumerate([
        d['id'][2:] if d['id'].startswith('0x') else d['id'].replace(':', '')  # noqa
        for d in mc.get_registered_devices()
    ]):
        print('%d: %s' % (i + 1, id))

except KeyboardInterrupt:
    exit(1)
