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.1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

pywnp-2.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pywnp-2.0.1.tar.gz.

File metadata

  • Download URL: pywnp-2.0.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pywnp-2.0.1.tar.gz
Algorithm Hash digest
SHA256 5daa80a25b8af842cd49a28f51bfe05e07bf4bfb827cd1f2fd3da003637a0efb
MD5 585fa204f578405d29770c430c797a06
BLAKE2b-256 8efc56dd50985f7d7d98081478409811e65498779e9277ea297f2765f2233667

See more details on using hashes here.

File details

Details for the file pywnp-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: pywnp-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for pywnp-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d19df97447cccfd120a3584ae8465a5c6148676b480459852196315d657266a
MD5 dd667d28bd92404ee3f76630f961aea7
BLAKE2b-256 5db66fac0b1a07371998eac747e34a039b4f741eedd1543fdb979383bf79085e

See more details on using hashes here.

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