def set_wallpaper_random(cls):

        options = cls.get_user_options()

        selected_albums = options.get('selectedAlbums', None)
        new_album = random.choice(selected_albums)

        new_album_id = new_album.get('id')
        album_media_items = new_album.get('mediaItems', None)

        # TODO: Store album title in options.json instead of retrieving it each time
        if (new_album_id == 'FAVORITES'):
            new_album['title'] = 'Favorites'
        else:
            new_album = GoogleApi.get_album(new_album_id)

        new_wall = random.choice(album_media_items)

        # Refresh base url
        new_wall = GoogleApi.get_media_item(new_wall.get('id'))
        new_album.pop('mediaItems', None)
        new_wall['source'] = new_album

        cls.set_current_wallpaper(new_wall)
        return new_wall
    def set_selected_albums(cls, selected_items):
        with open(OPTIONS_PATH, 'r') as f:
            options = json.load(f)
            f.close()

        original_selection = options.get('selectedAlbums', [])
        new_selection = []

        # Iterate through new selection
        for album_id in selected_items:
            # Search in original selection for item containing album_id
            search = find_in_list_by_val(original_selection, 'id', album_id)

            if search == None:
                # User has selected a new album
                if album_id == FAVORITES:
                    media_items = GoogleApi.get_all_favorites()
                else:
                    media_items = GoogleApi.get_all_album_media_items(album_id)

                # Remove these baseUrl and productUrl - not needed for storage
                for item in media_items:
                    item.pop('baseUrl')
                    item.pop('productUrl')

                new_selection.append({
                    'id': album_id,
                    'mediaItems': media_items
                })
            else:
                # Album already selected, use old data
                new_selection.append(search)

        options['selectedAlbums'] = new_selection

        with open(OPTIONS_PATH, 'w') as f:
            json.dump(options, f)
            f.close()
    def set_wallpaper_by_direction(cls, direction='next'):

        options = cls.get_user_options()
        current_wall = options.get('currentWallpaper', None)

        if (current_wall == None):
            # No current wallpaper set
            return None

        current_album = current_wall.get('source')
        current_album_id = current_album.get('id')
        current_wall_id = current_wall.get('id')

        # Get the album that the current wallpaper is in
        current_album_items = find_in_list_by_val(
            options.get('selectedAlbums'), 'id',
            current_album_id).get('mediaItems')

        # Get the index of the current wallpaper
        current_wall_index = find_index_in_list_by_val(current_album_items,
                                                       'id', current_wall_id)

        if (direction == 'next'):
            index = current_wall_index + 1
        elif (direction == 'prev'):
            index = current_wall_index - 1

        if (index == len(current_album_items)
                and direction == 'next') or (index < 0
                                             and direction == 'prev'):
            # Out of bounds
            # TODO: Change to next album when going out of bounds
            return
        else:
            new_wall_id = current_album_items[index].get('id')
            new_wall = GoogleApi.get_media_item(new_wall_id)
            new_wall['source'] = current_album

            cls.set_current_wallpaper(new_wall)
            return new_wall
Beispiel #4
0
def get_media_item(media_item_id):
    # Retreive data for a media item
    return GoogleApi.get_media_item(media_item_id)
Beispiel #5
0
def get_album_media_items(album_id):
    # Get media items from a photo album
    return GoogleApi.get_album_media_items(album_id)
Beispiel #6
0
def get_albums():
    # Get user's photo albums
    return GoogleApi.get_albums()
Beispiel #7
0
def get_favorites():
    # Get user's favorited media items
    return GoogleApi.get_favorites()
Beispiel #8
0
def sign_in():
    # If creds are invalid, send user to sign in flow
    GoogleApi.ensure_valid_token()
Beispiel #9
0
def is_authenticated():
    # Check if user has valid credentials
    return GoogleApi.is_authenicated()