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

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 the WebSocket, providing a port, version number and a logger
WNPRedux.Initialize(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.mediaInfo.Title)
  WNPRedux.mediaEvents.TogglePlaying()
  time.sleep(1)

# Close the WebSocket
WNPRedux.Close()

WNPRedux.Initialize(port, version, logger, loopback = '127.0.0.1')

Opens the WebSocket if it isn't already opened.
port should not be used by other adapters already, or interfere with any other programs.
version has to be 'x.x.x'.


WNPRedux.isInitialized

Whether the WebSocket is initialized or not


WNPRedux.Log(type, message)

Calls the logger provided in WNPRedux.Initialize()


WNPRedux.Close()

Closes the WebSocket if it's opened.


WNPRedux.clients

A set of connected clients, useful with len(WNPRedux.clients) to see if there are any active connections.


WNPRedux.mediaInfo

Information about the currently active media.

Name Default Description
Player '' Current player, e.g. YouTube, Spotify, etc.
State 'STOPPED' Current state of the player ('STOPPED', 'PLAYING', 'PAUSED')
Title '' Title
Artist '' Artist
Album '' Album
CoverUrl '' URL to the cover image
Duration '0:00' Duration in (hh):mm:ss (Hours are optional)
DurationSeconds 0 Duration in seconds
Position '0:00' Position in (hh):mm:ss (Hours are optional)
PositionSeconds 0 Position in seconds
PositionPercent 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;
RepeatState 'NONE' Current repeat state ('NONE', 'ONE', 'ALL')
Shuffle False If shuffle is enabled

WNPRedux.mediaEvents

Events to interact with the currently active media.
This isn't guaranteed to always work, since e.g. Spotify has no 'dislike' button,
skip buttons might be disabled in certain scenarios, etc.

Name Description
TogglePlaying() Pauses / Unpauses the media
Next() Skips to the next media/section
Previous() Skips to the previous media/section
SetPositionSeconds(seconds) Sets the medias playback progress in seconds
RevertPositionSeconds(seconds) Reverts the medias playback progress by x seconds
ForwardPositionSeconds(seconds) Forwards the medias playback progress by x seconds
SetPositionPercent(percent) Sets the medias playback progress in percent
RevertPositionPercent(percent) Reverts the medias playback progress by x percent
ForwardPositionPercent(percent) Forwards the medias playback progress by x percent
SetVolume(volume) Set the medias volume from 1-100
ToggleRepeat() Toggles through repeat modes
ToggleShuffle() Toggles shuffle mode
ToggleThumbsUp() Toggles thumbs up or similar
ToggleThumbsDown() Toggles thumbs down or similar
SetRating(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-1.0.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

pywnp-1.0.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pywnp-1.0.2.tar.gz
Algorithm Hash digest
SHA256 271e44b7bdc6e31c226d001ee1445ab5223483a34ddf7cf7495b83815fac0d68
MD5 6a12ec68f0e57cf7d3c2e98638165731
BLAKE2b-256 379db7dce2be81c418d52e87feee91478613097d84e4acc5e1514d54e92fda8c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pywnp-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0da81af56ae3582359d8956ea76471b988e9196a45c7fc3a8b95e0d081362422
MD5 6b0dad711a86663d0a57772f4f646789
BLAKE2b-256 82c3a5fcbf2d85393d9c4f9d3d5515c3d25f15ed0425be43a5f155e17337e5ce

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