Example #1
0
def writeAlbumArt():
    #TODO: https://github.com/simon-weber/gmusicapi/issues/352
    # see branch: https://github.com/simon-weber/gmusicapi/issues/242
    wc = Webclient()
    wc.__init__()
    #wc.oauth_login(Mobileclient.FROM_MAC_ADDRESS)
    if wc.login(uname, password):
        print "webclient login successful"
    else:
        print "LOGIN FAILED for Webclient"
Example #2
0
    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)
Example #3
0
 def __init__(self):
     self.webclient = Webclient(debug_logging=False)
     self.mobileclient = Mobileclient(debug_logging=False)
     self.email = None
     self.password = None
     self.mc_authenticated = False
     self.wc_authenticated = False
     self.authenticated = False
     self.device = None
     self.all_songs = list()
     self.playlists = list()
Example #4
0
def main():
    api = Webclient()
    loggedIn = connect(api, raw_input('Username: '******'Password: '))

    if not loggedIn:
        print "Authorization unsuccessful"
        sys.exit(0)
    else:
        print "Authorization successful!"

    print api.get_all_songs()[0]
Example #5
0
 def __init__(self):
     self.authenticated = False
     self.all_access = False
     self._device = None
     self._webclient = Webclient(debug_logging=False)
     self._mobileclient = Mobileclient(debug_logging=False)
     self._playlists = []
     self._playlist_contents = []
     self._all_songs = []
     self._all_artists = {}
     self._all_albums = {}
     self._all_genres = {}
     self._stations = []
    def __init__(self, email=None, password=None):
        self.mm = Musicmanager()
        self.wc = Webclient()
        if not email:
            email = raw_input("Email: ")
        if not password:
            password = getpass()

        self.email = email
        self.password = password

        self.logged_in = self.auth()

        print "Fetching playlists from Google..."
        self.playlists = self.wc.get_all_playlist_ids(auto=False)
        print "Got %d playlists." % len(self.playlists['user'])
        print ""
Example #7
0
 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
Example #8
0
def ask_for_credentials():
    """Make an instance of the api and attempts to login with it.
    Return the authenticated api.
    """

    # We're not going to upload anything, so the webclient is what we want.
    api = Webclient()

    logged_in = False
    attempts = 0

    while not logged_in and attempts < 3:
        email = raw_input("Email: ")
        password = getpass()

        logged_in = api.login(email, password)
        attempts += 1

    return api
Example #9
0
 def __init__(self):
     self.authenticated = False
     self.all_access = False
     self.library_loaded = False
     self.all_songs = []
     self.letters = {}
     self.artists = {}
     self.albums = {}
     self.genres = {}
     self.tracks_by_letter = {}
     self.tracks_by_artist = {}
     self.tracks_by_album = {}
     self.tracks_by_genre = {}
     self._device = None
     self._webclient = Webclient(debug_logging=False)
     self._mobileclient = Mobileclient(debug_logging=False)
     self._playlists = []
     self._playlist_contents = []
     self._stations = []
Example #10
0
    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()
                for device in devices:
                    if device["type"] == "PHONE":
                        device_id = str(device["id"])
                        break
                if device_id.lower().startswith('0x'):
                    device_id = device_id[2:]
                self.settings.setSetting('device_id', device_id)
            self.main.log('device_id: ' + device_id)
Example #11
0
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()
    def __init__(self, email=None, password=None):
        self.mm = Musicmanager()
        self.wc = Webclient()
        self.mc = Mobileclient()
        if not email:
            email = raw_input("Email: ")
        if not password:
            password = getpass()

        self.email = email
        self.password = password

        self.logged_in = self.auth()

        print "Fetching playlists from Google..."
        self.playlists = self.mc.get_all_user_playlist_contents()
        #self.playlists = self.mc.get_all_playlists()
        #self.playlists = self.wc.get_all_playlist_ids(auto=False)
        self.all_songs = self.mc.get_all_songs()
        #print "Got %d playlists." % len(self.playlists['user'])
        print "Got %d playlists containing %d songs." % (len(
            self.playlists), len(self.all_songs))
        print ""
Example #13
0
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
Example #14
0
    def handle(self, *args, **options):
        if GPLAY_PASS == "" or GPLAY_USER == "":
            self.stdout.write(
                'Credentials not set up. Please edit settings.py')
            return

        api = Webclient()
        if not api.login(GPLAY_USER, GPLAY_PASS):
            self.stdout.write('Incorrect credentials, login failed')
            return

        self.stdout.write('Connected to Google Music, downloading data...')
        library = api.get_all_songs()
        self.stdout.write('Data downloaded!')
        self.stdout.write('Clearing DB...')
        cursor = connection.cursor()
        # This can take a long time using ORM commands on the Pi, so lets Truncate
        cursor.execute('DELETE FROM ' + Track._meta.db_table)
        cursor.execute('DELETE FROM ' + Album._meta.db_table)
        cursor.execute('DELETE FROM ' + Artist._meta.db_table)
        cursor.execute('DELETE FROM ' + Playlist._meta.db_table)
        cursor.execute('DELETE FROM ' + PlaylistConnection._meta.db_table)
        self.stdout.write('Parsing new data...')

        # Easier to keep track of who we've seen like this...
        artists = []
        albums = []

        for song in library:
            track = Track()

            if song['albumArtist'] == "":
                if song['artist'] == "":
                    a = "Unknown Artist"
                else:
                    a = song['artist']
            else:
                a = song['albumArtist']

            if a not in artists:
                artist = Artist()
                artist.name = a
                try:
                    artist.art_url = song['artistImageBaseUrl']
                except:
                    artist.art_url = ""
                artist.save()
                artists.append(a)
                self.stdout.write('Added artist: ' + a)
            else:
                artist = Artist.objects.get(name=a)
            track.artist = artist

            if song['album'] not in albums:
                album = Album()
                album.name = song['album']
                album.artist = artist
                try:
                    album.art_url = song['albumArtUrl']
                except:
                    album.art_url = ""
                album.save()
                albums.append(song['album'])
            else:
                album = Album.objects.get(name=song['album'])
            track.album = album

            track.name = song['title']
            track.stream_id = song['id']
            try:
                track.track_no = song['track']
            except:
                track.track_no = 0
            track.save()

        self.stdout.write('All tracks saved!')
        self.stdout.write('Getting Playlists...')
        playlists = api.get_all_playlist_ids(auto=False, user=True)
        self.stdout.write('Saving playlists...')
        for name in playlists['user']:
            for pid in playlists['user'][name]:
                p = Playlist()
                p.pid = pid
                p.name = name
                p.save()

        for playlist in Playlist.objects.all():
            self.stdout.write('Getting playlist contents for ' + playlist.name)
            songs = api.get_playlist_songs(playlist.pid)
            for song in songs:
                track = Track.objects.get(stream_id=song['id'])
                pc = PlaylistConnection()
                pc.playlist = playlist
                pc.track = track
                pc.save()

        self.stdout.write('Library saved!')
Example #15
0
class Gmusic:
    artists = []
    playlists = []
    api = Webclient()
    player = Player(api)

    def telnetCmd(self, cmd):
        tn = telnetlib.Telnet('localhost', '6600')
        tn.read_until('OK MPD 0.16.0')
        tn.write(cmd + "\n")
        result = tn.read_until('OK', 10)
        tn.close()
        return result

    def playSong(self, songId):
        url = self.api.get_stream_urls(songId)[0]
        self.telnetCmd('clear')
        self.telnetCmd('add ' + str(url))
        self.telnetCmd('play')

    def playList(self, playlistId):
        self.player.setPlaylist(self.playlists[playlistId])
        self.player.playSong()
 
    def login(self):
        usuario = '*****@*****.**'
        senha = 'vd001989'
        loggedin = Gmusic.api.login(usuario, senha)
        return loggedin
    
    def loadSongs(self):
        songsApi = Gmusic.api.get_all_songs()
        for s in songsApi:
            artistC = Artist()
            artistC.name = s["artist"]
            artistC.url = s.get('artistImageBaseUrl', '')
            artistIndex = -1
            if not (artistC in self.artists):
                artistC.id = len(Gmusic.artists)
                artistIndex = artistC.id
                self.artists.append(artistC)
            else:
                artistIndex = self.artists.index(artistC)
            
            albumC = Album()
            albumC.name = s["album"]
            albumC.url = s.get('albumArtUrl', '')
            albumC.artistId = self.artists[artistIndex].id
            if not (albumC in self.artists[artistIndex].albums):
                albumC.id = len(self.artists[artistIndex].albums)
                self.artists[artistIndex].albums.append(albumC)
                albumIndex = albumC.id
            else:
                albumIndex = self.artists[artistIndex].albums.index(albumC)

            song = Song()
            song.id = s["id"]
            song.title = s["title"]
            self.artists[artistIndex].albums[albumIndex].songs.append(song)


    def loadPlaylists(self):
        plApi = Gmusic.api.get_all_playlist_ids()
        for name,pids in plApi['user'].iteritems():
            for pid in pids:
                playlist = Playlist()
                playlist.name = name
                playlist.id = pid
                playlist.index = len(self.playlists)
                tracks = self.api.get_playlist_songs(pid)
                for s in tracks:
                    song = Song()
                    song.id = s["id"]
                    song.title = s["title"]
                    song.album = s["album"]
                    song.artist = s["artist"]
                    playlist.songs.append(song)
                self.playlists.append(playlist)

    def __init__(self):
        a = ""
Example #16
0
 def __init__(self, speaker):
     self.speaker = speaker
     self.api = Webclient()
Example #17
0
	def playLogin(self, username, password):
		self.api = Webclient()
		self.api.login(username, password)
		self.playlibrary = self.api.get_all_songs()
Example #18
0
from gmusicapi import Webclient
import json

api = Webclient()
api.login('*****@*****.**', 'biffyclyro')
# => True

library = api.get_all_songs()
print json.dumps(library)
Example #19
0
import sys
from gmusicapi import Webclient

if __name__ == "__main__":
    if sys.argv[1] == "1":
        wc = Webclient()
        success = wc.login(sys.argv[2], sys.argv[3])
        if success == True:
            devices = wc.get_registered_devices()
            valid = [
                device['id'][2:] + " (" + device['model'] + ")"
                for device in devices if device['type'] == 'PHONE'
            ]
            deviceid = valid[0].split(' ', 1)[0]
            print(deviceid)
    if sys.argv[1] == "2":
        print("Spotify is not yet supported.")
Example #20
0
 def __init__(self):
     self.webclient = Webclient()
     self.mobileclient = Mobileclient()
Example #21
0
import urllib

# Use Google account credintials. If two factor is enabled, use application specific password.
email = '*****@*****.**'
password = '******'

# Device ID for API queries. Leave blank if unknown.
device_id = ''

if email == '':
    email = raw_input("Email: ")

if password == '':
    password = raw_input("Password: "******"Logging in..."

logged_in = web_client.login(email, password)
logged_in = mobile_client.login(email, password)

# logged_in is True if login was successful
if logged_in == True:
    print "Successfully logged in"
    
    if device_id == '':
        devices = web_client.get_registered_devices()
Example #22
0
 def __init__(self):
     super(GMusicSession, self).__init__()
     logger.info('Mopidy uses Google Music')
     self.api = Webclient()