Пример #1
0
    def log_in(self, use_token=True):
        """
        Called when this page is shown.

        Request user authorization.
        """
        config = Settings.get_config()
        username, password, device_id, authtoken = [
            config.get(x)
            for x in ('username', 'password', 'device_id', 'authtoken')
        ]
        if self._login_notification:
            self._login_notification.close()
        if use_token and authtoken:
            self._login_notification = NotificationArea.notify(
                'Using cached auth token...')
            GP.get().use_authtoken_async(authtoken,
                                         device_id,
                                         callback=self.on_check_authtoken)
        elif username and password and device_id:
            self._login_notification = NotificationArea.notify('Logging in...')
            GP.get().login_async(username,
                                 password,
                                 device_id,
                                 callback=self.on_login)
        else:
            self._login_notification = NotificationArea.notify(
                'Please set your credentials on the settings page.')
Пример #2
0
 def perform_search(self, query):
     """
     Search tracks by query.
     """
     self.songlist.set_placeholder(u' \U0001F50D Searching for "{}"...'.format(
         query
     ))
     GP.get().search_async(query, callback=self.search_finished)
Пример #3
0
    def get_all_songs(self, *_):
        """
        Called when auth state changes or GP caches are invalidated.
        """
        if GP.get().is_authenticated:
            self.songlist.set_placeholder(u'\n \uf01e Loading song list...')

            GP.get().get_all_tracks_async(callback=self.on_get_all_songs)
            self.app.redraw()
Пример #4
0
    def __init__(self, app):
        self.app = app
        self.songlist = SongListBox(app)
        self.notification = None

        GP.get().auth_state_changed += self.get_all_songs
        GP.get().caches_invalidated += self.get_all_songs

        super(MyLibraryPage, self).__init__([self.songlist])
Пример #5
0
    def __init__(self, app):
        self.app = app

        self.walker = urwid.SimpleListWalker([urwid.Text('Not ready')])
        self.notification = None

        GP.get().auth_state_changed += self.auth_state_changed

        super(MyPlaylistListBox, self).__init__(self.walker)
Пример #6
0
    def auth_state_changed(self, is_auth):
        """
        Called when auth state changes (e. g. user is logged in).
        Requests fetching of playlists.
        """
        if is_auth:
            self.walker[:] = [
                urwid.Text(u'\n \uf01e Loading playlists...', align='center')
            ]

            GP.get().get_all_user_playlist_contents_async(
                callback=self.on_get_playlists)
Пример #7
0
    def on_login(self, success, error):
        """
        Called once user authorization finishes.
        If *error* is ``None`` and *success* is ``True``, switch app to "My library" page.
        """
        if error:
            self._login_notification.update('Failed to log in: {}'.format(
                str(error)))
            return

        if not success:
            self._login_notification.update(
                'Google Play Music login failed (API returned false)')
            return

        Settings.set_config(dict(authtoken=GP.get().get_authtoken()))

        self._login_notification.close()
Пример #8
0
 def __init__(self, songitem):
     self.songitem = songitem
     options = [
         urwid.AttrWrap(urwid.Text(' ' + songitem.full_title), 'panel'),
         urwid.AttrWrap(
             urwid.Text(' Source: {}'.format(songitem.track.source)),
             'panel_divider'),
         urwid.AttrWrap(
             urwid.Text(' StoreID: {}'.format(songitem.track.store_id)),
             'panel_divider')
     ]
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if not GP.get().get_track_by_id(songitem.track.id):
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Add to my library',
                              on_press=self.add_to_my_library), 'panel',
                 'panel_focus'))
     else:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Remove from my library',
                              on_press=self.remove_from_my_library),
                 'panel', 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     options.append(
         urwid.AttrWrap(
             urwid.Button('Create station', on_press=self.create_station),
             'panel', 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if self.songitem.track in Player.get().get_queue_tracks():
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Remove from queue',
                              on_press=self.remove_from_queue), 'panel',
                 'panel_focus'))
     else:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Append to queue',
                              on_press=self.append_to_queue), 'panel',
                 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Divider(u'\u2500'), 'panel_divider',
                        'panel_divider_focus'))
     if self.songitem.track.cached_url is not None:
         options.append(
             urwid.AttrWrap(
                 urwid.Button('Copy URL to clipboard',
                              on_press=self.copy_url), 'panel',
                 'panel_focus'))
     options.append(
         urwid.AttrWrap(urwid.Button('Close', on_press=self.close), 'panel',
                        'panel_focus'))
     super(SongListBoxPopup, self).__init__(urwid.Pile(options))