py_now_playing ============== .. py:module:: py_now_playing .. autoapi-nested-parse:: py_now_playing - A Python library for interacting with the Now Playing API. This library provides classes and functions to retrieve and manage information about the currently playing media, including playback status, media timeline, and media details. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/py_now_playing/__main__/index /autoapi/py_now_playing/core/index /autoapi/py_now_playing/dataclasses/index Classes ------- .. autoapisummary:: py_now_playing.MediaTimeline py_now_playing.PlaybackInfo py_now_playing.MediaPlaybackStatus py_now_playing.MediaPlaybackType py_now_playing.MediaPlaybackAutoRepeatMode py_now_playing.PyNowPlaying py_now_playing.MediaInfo Package Contents ---------------- .. py:class:: MediaTimeline Timeline properties of the media This class holds details about the media timeline such as start time, end time, maximum seek time, current position, minimum seek time, and the last updated time. .. py:attribute:: start_time :type: datetime.timedelta | None :value: None .. py:attribute:: end_time :type: datetime.timedelta | None :value: None .. py:attribute:: max_seek_time :type: datetime.timedelta | None :value: None .. py:attribute:: position :type: datetime.timedelta | None :value: None .. py:attribute:: min_seek_time :type: datetime.timedelta | None :value: None .. py:attribute:: last_updated_time :type: datetime.datetime | None :value: None .. py:class:: PlaybackInfo Playback information for the current media session. This class holds details such as the playback type, status, rate, auto-repeat mode, and shuffle state. Attributes: playback_type: Type of media playback (e.g., music, video, image) playback_status: Current status of the media playback playback_rate: Rate at which the media is being played (1.0 for normal speed) auto_repeat_mode: Auto-repeat mode for the media playback is_shuffle_active: Whether shuffle mode is active .. py:attribute:: playback_type :type: MediaPlaybackType | None :value: None .. py:attribute:: playback_status :type: MediaPlaybackStatus | None :value: None .. py:attribute:: playback_rate :type: float | None :value: None .. py:attribute:: auto_repeat_mode :type: MediaPlaybackAutoRepeatMode | None :value: None .. py:attribute:: is_shuffle_active :type: bool | None :value: None .. py:attribute:: controls :type: py_now_playing.dataclasses.enabled_controls.EnabledControls | None :value: None .. py:class:: MediaPlaybackStatus Bases: :py:obj:`enum.IntEnum` Playback status of the media .. py:attribute:: CLOSED :value: 0 .. py:attribute:: OPENED :value: 1 .. py:attribute:: CHANGING :value: 2 .. py:attribute:: STOPPED :value: 3 .. py:attribute:: PLAYING :value: 4 .. py:attribute:: PAUSED :value: 5 .. py:class:: MediaPlaybackType Bases: :py:obj:`enum.IntEnum` Type of media playback. .. py:attribute:: UNKNOWN :value: 0 .. py:attribute:: MUSIC :value: 1 .. py:attribute:: VIDEO :value: 2 .. py:attribute:: IMAGE :value: 3 .. py:class:: MediaPlaybackAutoRepeatMode Bases: :py:obj:`enum.IntEnum` Auto-repeat enum mode for media playback. .. py:attribute:: NONE :value: 0 .. py:attribute:: TRACK :value: 1 .. py:attribute:: LIST :value: 2 .. py:class:: PyNowPlaying(*args, **kwargs) Playback Controls Class This class provides methods to control media playback and retrieve media information. It interacts with the Windows Media Control API to manage playback sessions. Attributes: aumid (str): The AppUserModelId of the application. _manager (MediaManager): The MediaManager instance for managing media sessions. .. py:method:: create(aumid: str) :classmethod: :async: Async factory method to initialize PyNowPlaying with a MediaManager. Args: aumid (str): The AppUserModelId of the application. Returns: PyNowPlaying: An initialized instance with MediaManager ready. .. py:method:: _init(aumid: str, media_manager: winrt.windows.media.control.GlobalSystemMediaTransportControlsSessionManager) :classmethod: Initializes the PyNowPlaying class. Args: aumid (str): The AppUserModelId of the application. media_manager (MediaManager): The MediaManager instance. Raises: ValueError: If aumid is None. .. py:method:: pause() -> bool :async: Pause the media Returns: bool: True if successful, False .. py:method:: play() -> bool :async: Play the media Returns: bool: True if successful, False .. py:method:: toggle_play_pause() -> bool :async: Toggle play/pause the media Returns: bool: True if successful, False .. py:method:: stop() -> bool :async: Stop the media Returns: bool: True if successful, False .. py:method:: record() -> bool :async: Tell the application to record Returns: bool: True if successful, False .. py:method:: rewind() -> bool :async: Rewind the media Returns: bool: True if successful, False .. py:method:: fast_forward() -> bool :async: Fast forward the media Returns: bool: True if successful, False .. py:method:: next_track() -> bool :async: Skip to the next track Returns: bool: True if successful, False .. py:method:: previous_track() -> bool :async: Skip to the previous track Returns: bool: True if successful, False .. py:method:: change_playback_rate(rate: float) -> bool :async: Changes the playback rate for supported apps/media. Args: rate (float): The new playback rate. Returns: bool: True if successful, False .. py:method:: change_shuffle_active(state: bool) -> bool :async: Changes the shuffle active state. Args: state (bool): The new shuffle active state. Returns: bool: True if successful, False .. py:method:: change_auto_repeat_mode(mode: int) -> bool :async: Changes the auto repeat mode. Args: mode (int): The new auto repeat mode. 0 = None, 1 = Track, 2 = List Returns: bool: True if successful, False .. py:method:: seek(position: int) -> bool :async: Changes the playback position (Time Elapsed) Args: position (int): The new playback position in seconds. Returns: bool: True if successful, False .. py:method:: channel_up() -> bool :async: Sends a channel up command to the media session. Returns: bool: True if successful, False .. py:method:: channel_down() -> bool :async: Sends a channel down command to the media session. Returns: bool: True if successful, False .. py:method:: get_timeline_properties() -> py_now_playing.dataclasses.media_timeline.MediaTimeline | None :async: Gets the timeline properties of the media. Note: Windows updates the Media Timeline information at it's own pace, so if you want a live position marker, use get_interpolated_timeline_properties() Returns: MediaTimeline: The timeline properties of the media. .. py:method:: get_interpolated_timeline_properties() -> py_now_playing.dataclasses.media_timeline.MediaTimeline | None :async: Gets the interpolated timeline properties of the media. Note: MediaTimeline.last_updated_time is the last update by WinRT, not since the update of this function. Returns: MediaTimeline: The interpolated timeline properties of the media. .. py:method:: get_thumbnail() -> PIL.Image.Image | None :async: Gets the thumbnail of the media. Returns: Image: The thumbnail of the media as a PIL Image. .. py:method:: get_media_info() -> py_now_playing.dataclasses.media_info.MediaInfo | None :async: Gets the media info of the media. Returns: MediaInfo: The media info of the media. .. py:method:: get_playback_info() -> py_now_playing.dataclasses.playback_info.PlaybackInfo | None :async: Gets the playback info of the media. Returns: PlaybackInfo: The playback info of the media. .. py:method:: thumbnail_to_image(thumbnail) -> PIL.Image.Image | None :async: Converts a thumbnail to a PIL Image. Args: thumbnail: The thumbnail to convert. Returns: Image: The PIL Image. .. py:method:: get_active_app_user_model_ids() -> list[dict[str, str]] :staticmethod: :async: Gets AppUserModelIds of apps which are actively playing media. Returns: list: The active AppUserModelIds in the format [{Name, AppID}, ...] .. py:method:: get_all_aumids_by_name(name: str) -> list[str] | None :staticmethod: :async: Gets the AUMID by the name of the app. Note that this gets the first match of the app name. If there are multiple apps with the same name, it will return the first one installed on your system, not the one currently running. Args: name (str): The name of the app. Returns: list[str]: A list of AppUserModelIds that match the name. None: If no matches are found. .. py:method:: _internal_playback_info_changed_callback(sender, args) Internal callback for playback info changes. .. py:method:: _internal_timeline_properties_changed_callback(sender, args) Internal callback for timeline properties changes. .. py:method:: _internal_media_properties_changed_callback(sender, args) Internal callback for media properties changes. .. py:method:: register_playback_info_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.playback_info.PlaybackInfo], None]) -> None Registers a callback for playback info changes. Args: callback: The callback function. .. py:method:: register_timeline_properties_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.media_timeline.MediaTimeline], None]) -> None Registers a callback for timeline properties changes. Args: callback: The callback function. .. py:method:: register_media_properties_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.media_info.MediaInfo], None]) -> None Registers a callback for media properties changes. Args: callback: The callback function. .. py:method:: deregister_playback_info_changed_callback() -> None Deregisters the playback info changed callback. .. py:method:: deregister_timeline_properties_changed_callback() -> None Deregisters the timeline properties changed callback. .. py:method:: deregister_media_properties_changed_callback() -> None Deregisters the media properties changed callback. .. py:class:: MediaInfo Media Information Class This class holds details about the currently playing media, including artist, title, album information, track number, genres, playback type, and thumbnail image. Attributes: artist: Name of the artist title: Title of the media album_title: Title of the album album_artist: Artist of the album album_track_count: Number of tracks in the album track_number: Track number in the album genres: List of genres associated with the media playback_type: Type of playback (e.g., music, video) thumbnail: Thumbnail image of the media .. py:attribute:: artist :type: str | None :value: None .. py:attribute:: title :type: str | None :value: None .. py:attribute:: album_title :type: str | None :value: None .. py:attribute:: album_artist :type: str | None :value: None .. py:attribute:: album_track_count :type: int | None :value: None .. py:attribute:: track_number :type: int | None :value: None .. py:attribute:: genres :type: list | None :value: None .. py:attribute:: playback_type :type: str | None :value: None .. py:attribute:: thumbnail :type: PIL.Image.Image | None :value: None