Skip to main content

A python library to communicate with the WebNowPlaying-Redux browser extension

Project description

PyWNP

A Python library to communicate with the WebNowPlaying-Redux browser extension.

Refer to this if you want to create or submit your own adapter.

Installing

Install via pip: pip install pywnp

Native APIs

Built-in support for Native APIs.

Usage

from pywnp import WNPRedux
import time

# Custom logger, type can be 'Error', 'Debug' or 'Warning'
def logger(type, message):
  print(f'{type}: {message}')

# Start WNP, providing a port, version number and a logger
WNPRedux.start(1234, '1.0.0', logger)

# Write the current title to the console and pause/unpause the video for 30 seconds
for i in range(30):
  print(WNPRedux.media_info.title)
  # You don't need to check for `supports_play_pause`, but it's good to know about.
  if WNPRedux.media_info.controls.supports_play_pause:
    WNPRedux.media_info.controls.try_toggle_play_pause()
  time.sleep(1)

# Stop WNP
WNPRedux.stop()

WNPRedux.start(port, version, logger, listenAddress = '127.0.0.1')

Starts WNP if it isn't already started.
port should not be used by other adapters already, or interfere with any other programs.
version has to be 'x.x.x'.


WNPRedux.is_started

Whether WNPRedux is started or not.


WNPRedux.is_using_native_apis

Whether WNPRedux is pulling info from native APIs.
This is read-only, the actual value is set by the user.
It's toggled in the browser extensions settings panel.
Read more about it here.


WNPRedux.log(type, message)

Calls the logger provided in WNPRedux.start()


WNPRedux.stop()

Stops WNP if it's started.


WNPRedux.clients

Number of clients currently connected.


WNPRedux.media_info

Information about the currently active media.

Name Default Description
controls '' Instance of MediaControls (Read below this table)
player_name '' Current player, e.g. YouTube, Spotify, etc.
state 'STOPPED' Current state of the player ('STOPPED', 'PLAYING', 'PAUSED')
title '' Title
artist '' Artist
album '' Album
cover_url '' URL to the cover image
duration '0:00' Duration in (hh):mm:ss (Hours are optional)
duration_seconds 0 Duration in seconds
position '0:00' Position in (hh):mm:ss (Hours are optional)
position_seconds 0 Position in seconds
position_percent 0.0 Position in percent
volume 100 Volume from 1-100
rating 0 Rating from 0-5; Thumbs Up = 5; Thumbs Down = 1; Unrated = 0;
repeat_mode 'NONE' Current repeat mode ('NONE', 'ONE', 'ALL')
shuffle_active False If shuffle is enabled

MediaControls

Used in WNPRedux.media_info.controls

Name Description
supports_play_pause If the current player supports play_pause
supports_skip_previous If the current player supports skip_previous
supports_skip_next If the current player supports skip_next
supports_set_position If the current player supports set_position
supports_set_volume If the current player supports set_volume
supports_toggle_repeat_mode If the current player supports toggle_repeat_mode
supports_toggle_shuffle_active If the current player supports toggle_shuffle_active
supports_set_rating If the current player supports set_rating
rating_system 'NONE' or 'LIKE_DISLIKE' or 'LIKE' or 'SCALE' (SCALE is 0-5)
try_play() Tries to play the current media
try_pause() Tries to pause the current media
try_toggle_play_pause() Tries to play/pause the current media
try_skip_previous() Try to skip to the previous media/section
try_skip_next() Try to skip to the next media/section
try_set_position_seconds(seconds) Try to set the medias playback progress in seconds
try_revert_position_seconds(seconds) Try to revert the medias playback progress by x seconds
try_forward_position_seconds(seconds) Try to forward the medias playback progress by x seconds
try_set_position_percent(percent) Try to set the medias playback progress in percent
try_revert_position_percent(percent) Try to revert the medias playback progress by x percent
try_forward_position_percent(percent) Try to forward the medias playback progress by x percent
try_set_volume(volume) Try to set the medias volume from 1-100
try_toggle_repeat_mode() Try to toggle through repeat modes
try_toggle_shuffle_active() Try to toggle shuffle mode
try_set_rating(rating) Sites with a binary rating system fall back to: 0 = None; 1 = Thumbs Down; 5 = Thumbs Up

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywnp-2.0.2.tar.gz (13.0 kB view hashes)

Uploaded Source

Built Distribution

pywnp-2.0.2-py3-none-any.whl (11.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page