Metadata-Version: 2.1
Name: pywnp
Version: 1.0.8
Summary: A python library to communicate with the WebNowPlaying-Redux browser extension
Author-email: keifufu <keifufu@noonly.net>
License: Copyright 2023 keifufu
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/keifufu/PyWNP
Project-URL: Bug Tracker, https://github.com/keifufu/PyWNP/issues
Keywords: webnowplaying,wnp,youtube,spotify,media,music
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE

# PyWNP
A Python library to communicate with the [WebNowPlaying-Redux](https://github.com/keifufu/WebNowPlaying-Redux) browser extension.

Refer to [this](https://github.com/keifufu/WebNowPlaying-Redux/blob/main/CreatingAdapters.md) if you want to create or submit your own adapter.

## Installing
Install via pip: `pip install pywnp`

## Usage
```py
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, listenAddress = '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 WNPRedux 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`
Number of clients currently connected.

---
### `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
