当前位置: 首页>>代码示例>>Python>>正文


Python Webclient.get_registered_devices方法代码示例

本文整理汇总了Python中gmusicapi.Webclient.get_registered_devices方法的典型用法代码示例。如果您正苦于以下问题:Python Webclient.get_registered_devices方法的具体用法?Python Webclient.get_registered_devices怎么用?Python Webclient.get_registered_devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gmusicapi.Webclient的用法示例。


在下文中一共展示了Webclient.get_registered_devices方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getDeviceId

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
def getDeviceId(verbose=False):
    cred_path = os.path.join(os.path.expanduser('~'), '.gmusicfs')
    if not os.path.isfile(cred_path):
        raise NoCredentialException(
            'No username/password was specified. No config file could '
            'be found either. Try creating %s and specifying your '
            'username/password there. Make sure to chmod 600.'
            % cred_path)
    if not oct(os.stat(cred_path)[os.path.stat.ST_MODE]).endswith('00'):
        raise NoCredentialException(
            'Config file is not protected. Please run: '
            'chmod 600 %s' % cred_path)
    config = ConfigParser.ConfigParser()
    config.read(cred_path)
    username = config.get('credentials','username')
    password = config.get('credentials','password')
    if not username or not password:
        raise NoCredentialException(
            'No username/password could be read from config file'
            ': %s' % cred_path)

    api = GoogleMusicWebAPI(debug_logging=verbose)
    log.info('Logging in...')
    api.login(username, password)
    log.info('Login successful.')

    for device in api.get_registered_devices():
        if not device['name']:
            device['name']='NoName'
        if device['id'][1]=='x':
            print '%s : %s' % (device['name'], device['id'])
开发者ID:bestlibre,项目名称:GMusicFS,代码行数:33,代码来源:gmusicfs.py

示例2: authenticate

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
    def authenticate(self, USER_DATA_FILENAME):
        self.G_username = raw_input("Google Play Account Email: ")
        self.G_password = getpass.getpass("Google Play Account Pass: ")

        Deviceclient = Webclient()
        Deviceclient.login(self.G_username, self.G_password)

        DList = Deviceclient.get_registered_devices()

        for device in DList:
            if device['type'] == "PHONE":
                self.GOOGLE_DEVICE_ID = device["id"]
                if self.GOOGLE_DEVICE_ID[:2] == '0x':
                    self.GOOGLE_DEVICE_ID = self.GOOGLE_DEVICE_ID[2:]
                break

        self.S_username = raw_input("Soundcloud Account Username: ")
        self.S_password = getpass.getpass("Soundcloud Account Password: ")
        self.SOUNDCLOUD_CLIENT_ID = raw_input("Soundcloud Client ID: ")
        self.SOUNDCLOUD_CLIENT_SECRET_ID = raw_input("Soundcloud Secret Client ID: ")

        File = open(USER_DATA_FILENAME, 'w+')
        File.write(self.encode(self.enc_key, self.G_username) + '\n')
        File.write(self.encode(self.enc_key, self.G_password) + '\n')
        File.write(self.encode(self.enc_key, self.S_username) + '\n')
        File.write(self.encode(self.enc_key, self.S_password) + '\n')
        File.write(self.GOOGLE_DEVICE_ID + '\n')
        File.write(self.SOUNDCLOUD_CLIENT_ID + '\n')
        File.write(self.SOUNDCLOUD_CLIENT_SECRET_ID + '\n')
        File.close()
开发者ID:nightfire8199,项目名称:project-hermes,代码行数:32,代码来源:User.py

示例3: initthread

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
def initthread(mwc, mc):
    library = mwc.library
    mwc.status_msg("Initializing..")
    wc = Webclient()
    wc.login(config.user, config.password)
    devices = wc.get_registered_devices()

    mwc.status_msg("Retrieving usable device ID..")
    for dev in devices:
        if dev["type"] == "PHONE":
            # strip 0x if present
            config.devid = dev["id"][2:] if dev["id"].startswith("0x") else dev["id"]
            print("Found a usable device id: " + config.devid)
            break
    else:
        md = Gtk.MessageDialog(parent=mwc.ui, buttons=Gtk.ButtonsType.OK, message_type=Gtk.MessageType.ERROR, message_format="Could not find a usable device id. Please run the Google Play Music app at least once on your phone.")
        GLib.idle_add(modal_dialog_func, md)

    mc.login(config.user, config.password)
    player = Player(mc, config.devid)
    mwc.setplayer(player)

    def getalbumart(structure):
        if "albumArtRef" in structure:
            a = structure["albumArtRef"]
            for entry in a:
                if "url" in entry:
                    return entry["url"]
        return None

    mwc.status_msg("Retrieving library..")
    songs = mc.get_all_songs()
    for song in songs:
        track = Track(song["id"], song["title"], song["artist"], song["album"],
                      song["trackNumber"] if "trackNumber" in song else 0)
        track.albumarturl = getalbumart(song)
        library.add_track(track)

    mwc.status_msg("Retrieving playlists..")
    playlists = mc.get_all_user_playlist_contents()


    for x in playlists:
        tracks = []
        for t in x["tracks"]:
            if t["trackId"].startswith("T"): # all access track
                trackEntry = t["track"]
                track = Track(t["trackId"], trackEntry["title"], trackEntry["artist"], trackEntry["album"], trackEntry["trackNumber"])
                track.albumarturl = getalbumart(trackEntry)
                tracks.append(track)

            else:
                libtrack = library.find_track(t["trackId"])
                if libtrack is not None:
                    tracks.append(libtrack)
        library.add_list(Playlist(x["name"], tracks))

    mwc.status_msg("Idle")
开发者ID:hrkfdn,项目名称:gomusic,代码行数:60,代码来源:main.py

示例4: get_deviceid

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
 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
开发者ID:bubbltrubl,项目名称:mopidy-gmusic,代码行数:21,代码来源:session.py

示例5: initDevice

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
    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)
开发者ID:lykos26,项目名称:Bunkford,代码行数:21,代码来源:GoogleMusicLogin.py

示例6: main

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
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()
开发者ID:digiltd,项目名称:squeezebox-googlemusic,代码行数:23,代码来源:mobile_devices.py

示例7: GMusic

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
class GMusic(object):
    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 _get_device_id(self):
        if self.authenticated:
            devices = self._webclient.get_registered_devices()
            for dev in devices:
                if dev['type'] == 'PHONE':
                    self._device = dev['id'][2:]
                    break

    def _set_all_access(self):
        settings = self._webclient._make_call(webclient.GetSettings, '')
        self.all_access = True if 'isSubscription' in settings['settings'] and settings['settings']['isSubscription'] == True else False

    def authenticate(self, email, password):
        try:
            mcauthenticated = self._mobileclient.login(email, password)
        except AlreadyLoggedIn:
            mcauthenticated = True

        try:
            wcauthenticated = self._webclient.login(email, password)
        except AlreadyLoggedIn:
            wcauthenticated = True

        self.authenticated = mcauthenticated and wcauthenticated
        self._get_device_id()
        self._set_all_access()
        return self.authenticated

    def get_all_songs(self, id=None):
        if len(self._all_songs) == 0:
            try:
                self._all_songs = self._mobileclient.get_all_songs()
            except NotLoggedIn:
                if self.authenticate():
                    self._all_songs = self._mobileclient.get_all_songs()
                else:
                    return []

        if id:
            return [x for x in self._all_songs if x['id'] == id][0]
        else:
            return self._all_songs

    def get_all_artists(self):
        if not self._all_artists:
            songs = self.get_all_songs()
            for song in songs:
                artist = song['artist']
                thumb = None
                if artist not in self._all_artists:
                    self._all_artists[artist] = []

                track = {'title': song['title'],
                        'album': song['album'],
                        'artist': artist,
                        'durationMillis': song['durationMillis'],
                        'trackType': song['trackNumber'],
                        'id': song['id']}

                if 'albumArtRef' in song:
                    track['albumArtRef'] = song['albumArtRef']

                if 'artistArtRef' in song:
                    thumb = song['artistArtRef'][0]['url']

                if 'storeId' in song:
                    track['storeId'] = song['storeId']

                self._all_artists[artist].append({'track': track, 'thumb': thumb, 'id': song['id']})

        return self._all_artists

    def get_all_albums(self):
        if not self._all_albums:
            songs = self.get_all_songs()
            for song in songs:
                album = song['album']
                thumb = None
                if album not in self._all_albums:
                    self._all_albums[album] = []

                track = {'title': song['title'],
                        'album': album,
                        'artist': song['artist'],
                        'durationMillis': song['durationMillis'],
#.........这里部分代码省略.........
开发者ID:realsilver,项目名称:GoogleMusic.bundle,代码行数:103,代码来源:gmusic.py

示例8: get_registered_devices

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
def get_registered_devices(login, password):

    websession = Webclient()
    websession.login(login, password)

    return websession.get_registered_devices()
开发者ID:brian-dawn,项目名称:CLI-Music-Streamer,代码行数:8,代码来源:googlemusic.py

示例9: MusicPlayer

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
class MusicPlayer(object):

    def __init__(self):
        self.playlist = []                  # Array of all tracks
        self.playlist_id = 0                # Id of playlist
        self.current_track_index = 0        # Index of current song
        self.player = Player()              # MPlayer instance
        self.webclient = Webclient()        # Client for WebInterface
        self.mobileclient = Mobileclient()  # Client for MobileInterface
        self.timer = None                   # Timer to start next track
        self.deviceid = 0                   # DeviceId to use
        self.playtype = PlayType.LINEAR     # LINEAR or SHUFFLE

    def login(self, username, password):
        """ Login to Google Music.

        Keyword arguments:
        username -- the username
        password -- the password

        Returns:
        True if successful else False

        """

        # If either the web client or the mobile client failed to login return False
        if not self.webclient.login(username, password) or not self.mobileclient.login(username, password):
            return False

        # Use first found devices as ID
        devices = self.webclient.get_registered_devices();

        # Convert HEX to INT
        self.deviceid = int(devices[0]['id'], 16)

        return True

    def load_playlist(self, playlist_name):
        # Load playlist
        for playlist in self.mobileclient.get_all_user_playlist_contents():
            if playlist['name'] == playlist_name:
                for track_obj in playlist['tracks']:
                    track_obj['track']['id'] = track_obj['id']
                    self.playlist.append(track_obj['track'])

                # Set playlist_id
                self.playlist_id = playlist['id']
                break;

        # If playlist has not been found, create it
        if self.playlist_id == 0:
            self.playlist_id = self.mobileclient.create_playlist(playlist_name)

    def add_track_to_playlist(self, track):
        """ Append a track to the end of playlist

        Keyword arguments:
        track -- a dictionary containing the track informations

        """
        track_id = self.mobileclient.add_songs_to_playlist(self.playlist_id, track['nid'])[0]
        track['id'] = track_id
        self.playlist.append(track)

        # Notify all clients about the new track
        factory.forwarder.dispatch(PLAYLIST_EVENT_TRACK_ADDED, json.dumps(track))

    def remove_track_from_playlist(self, track_id):
        """ Removes a track from the playlist

        Keyword arguments:
        track_id -- The id of the track to remove

        """
        self.mobileclient.remove_entries_from_playlist(track_id)

        index_to_remove = self._find_index_of_track_id(track_id)

        del self.playlist[index_to_remove]

        factory.forwarder.dispatch(PLAYLIST_EVENT_TRACK_REMOVED, track_id)

    def play_track(self, track_id):
        """ Play a track

        Keyword arguments:
        track_id -- Id of the track to play

        """

        index_of_track = self._find_index_of_track_id(track_id)

        track_to_play = self.playlist[index_of_track]

        if track_to_play is not None:
            # Request stream url from google music
            stream_url = self.mobileclient.get_stream_url(track_to_play["storeId"], self.deviceid)

            # Load stream url to mplayer
            self.player.loadfile(stream_url)
#.........这里部分代码省略.........
开发者ID:dmichels,项目名称:gmusicplayer,代码行数:103,代码来源:MusicPlayer.py

示例10: GMusic

# 需要导入模块: from gmusicapi import Webclient [as 别名]
# 或者: from gmusicapi.Webclient import get_registered_devices [as 别名]
class GMusic(object):
    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 = []

    def _get_device_id(self):
        if self.authenticated:
            devices = self._webclient.get_registered_devices()
            for dev in devices:
                if dev['type'] == 'PHONE':
                    self._device = dev['id'][2:]
                    break
                elif dev['type'] == 'IOS':
                    self._device = dev['id']
                    break

    def _set_all_access(self):
        settings = self._webclient._make_call(webclient.GetSettings, '')
        self.all_access = True if 'isSubscription' in settings['settings'] and settings['settings']['isSubscription'] == True else False

    def _set_all_songs(self):
        if len(self.all_songs) == 0:
            try:
                self.all_songs = self._mobileclient.get_all_songs()
            except NotLoggedIn:
                if self.authenticate():
                    self.all_songs = self._mobileclient.get_all_songs()
                else:
                    return []

        else:
            return self.all_songs

    def authenticate(self, email, password):
        try:
            mcauthenticated = self._mobileclient.login(email, password)
        except AlreadyLoggedIn:
            mcauthenticated = True

        try:
            wcauthenticated = self._webclient.login(email, password)
        except AlreadyLoggedIn:
            wcauthenticated = True

        self.authenticated = mcauthenticated and wcauthenticated
        self._set_all_access()
        self._get_device_id()
        return self.authenticated

    def load_data(self):
        self._set_all_songs()
        for song in self.all_songs:
            thumb = None
            letter = song['title'][0]
            artist = song['artist']
            album = song['album']
            genre = song['genre'] if 'genre' in song else '(None)'

            if letter not in self.tracks_by_letter:
                self.tracks_by_letter[letter] = []
                self.letters[letter] = None

            if artist not in self.tracks_by_artist:
                self.tracks_by_artist[artist] = []
                self.artists[artist] = None

            if album not in self.tracks_by_album:
                self.tracks_by_album[album] = []
                self.albums[album] = None

            if genre not in self.tracks_by_genre:
                self.tracks_by_genre[genre] = []
                self.genres[genre] = None

            track = {'artist': artist, 'album': album}

            if 'title' in song:
                track['title'] = song['title']

            if 'album' in song:
                track['album'] = song['album']

            if 'artist' in song:
                track['artist'] = song['artist']
#.........这里部分代码省略.........
开发者ID:Mulefire,项目名称:GoogleMusic.bundle,代码行数:103,代码来源:gmusic.py


注:本文中的gmusicapi.Webclient.get_registered_devices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。