Пример #1
0
 def shutdown(self, activity_operation_cb=None, operation_user_data=None):
     """Deactivate connection associated to the handle."""
     context = py_object(operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if self.handle:
         libdeezer.dz_connect_deactivate(self.handle, cb, context)
         self.active = False
Пример #2
0
 def shutdown(self, activity_operation_cb=None, operation_user_data=None):
     """Deactivate the player"""
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if self.handle:
         libdeezer.dz_player_deactivate(self.handle, cb, context)
Пример #3
0
    def load(self,
             content,
             activity_operation_cb=None,
             operation_user_data=None):
        """Load the given content or the current track.

        In the first case, set the current_track to the given track.

        :param content: The track/tracklist to load
        :param activity_operation_cb: A callback triggered after operation.
        See module docstring.
        :param operation_user_data:  Any object your operation_callback can
        manipulate. Must inherit from Structure class.
        :type content: str
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_user_data: Same as operation_user_data in your
        callback. Must inherit from Structure as it is used by ctypes
        """
        if content:
            self.current_content = content
        context = py_object(
            operation_user_data) if operation_user_data else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_player_load(
                self.handle, cb, context,
                c_char_p(self.current_content.encode('utf-8'))):
            raise PlayerRequestFailedError("load: Unable to load selected \
                                           track. Check connection and \
                                           tracklist data.")
Пример #4
0
    def play(self,
             activity_operation_cb=None,
             operation_user_data=None,
             command=PlayerCommand.START_TRACKLIST,
             index=PlayerIndex.CURRENT):
        """Play the current track if loaded.
            The player gets data and renders it.

        :param command: Player command
        :param index: Index of the track to play
        :param activity_operation_cb: Called when async result is available
        :param operation_user_data: A reference to user's data
        :type command: PlayerCommand
        :type index: int
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_user_data: Same as operation_user_data in your
            callback. Must inherit from structure as it is used by ctypes.
        """
        context = py_object(
            operation_user_data) if operation_user_data else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_player_play(self.handle, cb, context, command,
                                    index) not in range(0, 2):
            raise PlayerRequestFailedError("play: Unable to play selected \
                                           track. Check player commands and \
                                           info.")
        self.is_playing = True
Пример #5
0
 def stop(self, activity_operation_cb=None, operation_user_data=None):
     """Stop the currently playing track"""
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_stop(self.handle, cb, context):
         raise PlayerRequestFailedError("play: Unable to stop track. Check \
                                        player commands and info.")
     self.is_playing = False
Пример #6
0
 def resume(self, activity_operation_cb=None, operation_user_data=None):
     """Resume the track if it has been paused"""
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_resume(self.handle, cb, context):
         raise PlayerRequestFailedError("play: Unable to resume track. \
                                        Check player commands and info.")
     self.is_playing = True
Пример #7
0
 def play_audio_ads(self,
                    activity_operation_cb=None,
                    operation_user_data=None):
     """Load and play an audio ad when required"""
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_play_audioads(self.handle, cb, context):
         raise PlayerRequestFailedError("play: Unable to play audio ads. \
                                        Check connection.")
Пример #8
0
    def _activate(self, supervisor=None):
        """Activate the player.

        :param supervisor: An object that can be manipulated by your
            dz_player_on_event_cb to store info.
        :type supervisor: Same as userdata in dz_player_on_event_cb
        """
        context = py_object(supervisor) if supervisor else c_void_p(0)
        if libdeezer.dz_player_activate(self.handle, context):
            raise PlayerActivationError("Player activation failed. Check \
                                        player info and your network \
                                        connection.")
        self.active = True
Пример #9
0
    def _activate(self, user_data=None):
        """Launch the connection. Call this after init_handle.

        Calls self.dz_connect_on_event_cb after activation. You can provide any
        object you want through user_data as long as it is managed by this
        callback.

        :param user_data: An object you want to pass to dz_connect_on_event_cb.
        :type user_data: The type of the object you want to manipulate
        """
        context = py_object(user_data) if user_data else c_void_p(0)
        if libdeezer.dz_connect_activate(self.handle, context):
            raise ConnectionActivationError('Failed to activate connection. \
                                            Check your network connection.')
        self.active = True
Пример #10
0
 def set_output_volume(self,
                       volume,
                       activity_operation_cb=None,
                       operation_user_data=None):
     """Set the output volume of the player.
         :param volume: Set to the percentage of the output volume
         :type volume: int
     """
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_set_output_volume(self.handle, cb, context,
                                              volume):
         raise PlayerRequestFailedError("play: Unable to set volume. Check \
                                        player commands and info.")
Пример #11
0
 def set_repeat_mode(self,
                     repeat_mode,
                     activity_operation_cb=None,
                     operation_user_data=None):
     """Set the repeat mode of the player.
         :param repeat_mode: The repeat mode to set
         :type repeat_mode: PlayerRepeatMode
     """
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_set_repeat_mode(self.handle, cb, context,
                                            repeat_mode):
         raise PlayerRequestFailedError("play: Unable to set repeat mode. \
                                        Check player commands and info.")
Пример #12
0
 def set_output_mute(self,
                     is_mute,
                     activity_operation_cb=None,
                     operation_user_data=None):
     """Set the mute mode of the player
         :param is_mute: Set to true to mute the output volume
         :type is_mute: bool
     """
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_set_output_mute(self.handle, cb, context,
                                            is_mute):
         raise PlayerRequestFailedError("play: Unable to (un)mute the \
                                        output. Check player commands \
                                        and info.")
Пример #13
0
 def enable_shuffle_mode(self,
                         shuffle_mode,
                         activity_operation_cb=None,
                         operation_user_data=None):
     """Set the shuffle mode of the player (randomize track selection)
         :param shuffle_mode: Set to true to activate the random track
         selection
         :type shuffle_mode: bool
     """
     context = py_object(
         operation_user_data) if operation_user_data else c_void_p(0)
     cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
     if libdeezer.dz_player_enable_shuffle_mode(self.handle, cb, context,
                                                shuffle_mode):
         raise PlayerRequestFailedError("play: Unable to set repeat mode. \
                                        Check player commands and info.")
Пример #14
0
    def set_cache_max_size(self, cache_max_size, activity_operation_cb=None,
                           operation_user_data=None):
        """Set cache size limitation.

        :param activity_operation_cb: The callback of the operation.
        :param operation_user_data: An object you want to pass to
            activity_operation_cb.
        :param cache_max_size: The maixum size of the cache in kilobyte
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_user_data: The type of the object you want to
            manipulate
        :type cache_max_size: int
        """
        context = py_object(operation_user_data) if operation_user_data else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_connect_smartcache_quota_set(self.handle, cb, context,
                                                     c_int(cache_max_size)):
            raise ConnectionRequestFailedError(
                'connect_cache_max_size: Request failed. Check connection and \
                callbacks if used.')
Пример #15
0
    def cache_path_set(self, user_cache_path, activity_operation_cb=None,
                       operation_userdata=None):
        """Set the cache path for debug purposes and logs.

        Cache will be stored in the specified path. Calls
        activity_operation_cb after the operation.

        :param user_cache_path: The desired path
        :param activity_operation_cb: The callback to this function.
        :param operation_userdata: An object you want to pass to
            activity_operation_cb.
        :type user_cache_path: str
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_userdata: The type of the object you want to manipulate
        """
        context = py_object(operation_userdata) if operation_userdata else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_connect_cache_path_set(self.handle, cb, context,
                                               c_char_p(user_cache_path.encode('utf-8'))):
            raise ConnectionRequestFailedError(
                'cache_path_set: Request failed. Check connection \
                and/or path validity.')
Пример #16
0
    def set_access_token(self, user_access_token, activity_operation_cb=None,
                         operation_user_data=None):
        """
        Set the user access token given by OAuth process.
        Mandatory to allow connection.

        :param user_access_token: The token given by OAuth 2 process.
            Refer to the API documentation.
        :param activity_operation_cb: The callback to this function.
        :param operation_user_data: An object you want to pass to
            activity_operation_cb.
        :type user_access_token: unicode
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_user_data: The type of the object you want to
            manipulate
        """
        context = py_object(operation_user_data) if operation_user_data else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_connect_set_access_token(self.handle, cb, context,
                                                 c_char_p(user_access_token.encode('utf-8'))):
            raise ConnectionRequestFailedError('set_access_token: \
                                               Request failed. Check access \
                                               token or update it.')
Пример #17
0
    def set_offline_mode(self, offline_mode_forced, activity_operation_cb=None,
                         operation_user_data=None):
        """Force offline mode in lib.

        Calling this function is mandatory to force user login.

        :param activity_operation_cb: The callback of the operation.
        :param operation_user_data: An object you want to pass to
            activity_operation_cb.
        :param offline_mode_forced: Force offline mode. Leave to False
            if just to allow connection.
        :type activity_operation_cb: dz_activity_operation_cb_func
        :type operation_user_data: The type of the object you want to
            manipulate
        :type offline_mode_forced: bool
        """
        context = py_object(operation_user_data) if operation_user_data else c_void_p(0)
        cb = activity_operation_cb if activity_operation_cb else c_void_p(0)
        if libdeezer.dz_connect_offline_mode(self.handle, cb, context,
                                             c_bool(offline_mode_forced)):
            raise ConnectionRequestFailedError(
                'connect_offline_mode: Request failed. Check connection and \
                callbacks if used.')