Skip to main content

A Python library for scraping and retrieving song information from the Muzak WPN (What's Playing Now) website. This tool allows you to get current and historical song data for various music channels/stations.

Project description

WPN - What's Playing Now

A Python library for scraping and retrieving song information from the Muzak WPN (What's Playing Now) website. This tool allows you to get current and historical song data for various music channels/stations.

Features

  • Get a directory of available music channels
  • Retrieve the current song playing on a specific channel
  • Get a list of previous songs played on a channel
  • Get a complete list of current and previous songs for a channel
  • Fetch and process all song data for all available channels
  • Export song data to JSON format
  • Command-line interface for all functionality

Installation

Requirements

  • Python 3.12 or higher
  • Dependencies are specified in pyproject.toml

Installation steps

  1. Clone this repository:

    git clone https://github.com/lancereinsmith/wpn.git
    cd wpn
    
  2. Install using uv (recommended):

    pip install uv
    uv venv
    uv pip install -e .
    
  3. Alternatively, you can use a standard venv:

    python -m venv .venv
    source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
    pip install -e .
    

Usage

Python API Usage

from wpn import WPN

# Create an instance
wpn = WPN()

# Get all available channels
channels = wpn.channel_list
print(f"Available channels: {len(channels)}")

# Get current song on a specific channel (by name or index)
song, artist = wpn.get_current_song("Channel Name")  # Using channel name
# Or
song, artist = wpn.get_current_song(5)  # Using channel index
print(f"Now playing: {song} by {artist}")

# Get all songs (current and previous) for a channel
songs = wpn.get_all_songs("Channel Name")  # Using channel name
# Or
songs = wpn.get_all_songs(5)  # Using channel index

# Current song is at index 0
current_song, current_artist = songs[0]
print(f"Now playing: {current_song} by {current_artist}")

# Previous songs can be accessed using negative indices
# Most recent previous song
if len(songs) > 1:
    prev_song, prev_artist = songs[-1]
    print(f"Previously played: {prev_song} by {prev_artist}")
    
    # Second most recent previous song
    if len(songs) > 2:
        older_song, older_artist = songs[-2]
        print(f"Before that: {older_song} by {older_artist}")

# Or iterate through all songs
for i, (song, artist) in enumerate(songs):
    if i == 0:
        print(f"Current: {song} by {artist}")
    else:
        print(f"Previous ({len(songs)-i}): {song} by {artist}")

# Get previous songs only (by name or index)
previous_songs = wpn.get_previous_songs("Channel Name")  # Using channel name
# Or
previous_songs = wpn.get_previous_songs(5)  # Using channel index

# Get all song data for all channels
all_data = wpn.get_all_song_data()

Command-Line Interface

WPN provides a comprehensive command-line interface for accessing all functionality.

After installing the package, the wpn command will be available:

wpn --help

List all available channels

wpn list

Get the current song playing on a channel

wpn current "Channel Name"
# Or using channel index
wpn current 5

Get previous songs played on a channel

wpn previous "Channel Name"
# Or using channel index
wpn previous 5

This will display a list of previously played songs from most recent to least recent.

Get all songs (current and previous) for a channel

wpn songs "Channel Name"
# Or using channel index
wpn songs 5

Get all song data for all channels

wpn all-data
# Or specify custom output path
wpn all-data --output data.json

API Reference

WPN Class

__init__()

Initialize the WPN scraper with an up-to-date directory of channels.

get_directory(sort=True)

Create an up-to-date directory of channels and URLs from the WPN website.

get_channel_name(channel_input)

Filter input to match a valid channel name or accept an integer to get a channel by index.

get_current_song(channel_input)

Get the current song playing on a specified channel, returned as a tuple of (song, artist). The channel_input can be either a string (channel name) or an integer (channel index).

get_previous_songs(channel_input)

Get a list of previous songs played on a channel as a list of (song, artist) tuples, ordered from oldest to most recent. The channel_input can be either a string (channel name) or an integer (channel index).

get_all_songs(channel_input)

Get a list of current and previous songs for a channel as a list of (song, artist) tuples. The list is structured so that:

  • Index 0 contains the current song
  • Negative indices can be used to access previous songs chronologically
  • songs[-1] is the most recently played previous song
  • songs[-2] is the second most recently played previous song, and so on

The channel_input can be either a string (channel name) or an integer (channel index).

get_all_song_data()

Generate the song data for all songs currently playing on all channels.

Project Structure

├── src/
│   └── wpn/
│       ├── __init__.py
│       └── wpn.py
├── tests/
│   └── test_wpn.py
├── pyproject.toml
└── README.md

Testing

Run tests using pytest:

python -m pytest

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

wpn-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wpn-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file wpn-0.1.0.tar.gz.

File metadata

  • Download URL: wpn-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for wpn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a7340649ad7e56bab7038437d2f86e14a08741e0ef90bb371fd27749823f571
MD5 910a02504578a79d112ea32ac6d8d082
BLAKE2b-256 101854b4ec6ebbde5269bcc8ea6c17b2b98e1249728af7a98c2d998807c9a5ed

See more details on using hashes here.

File details

Details for the file wpn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wpn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for wpn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb4f7cfa432f7a499f5ad5dac639119c2513d8dbb723237e5b6b475c32f68ff
MD5 dc5f99a07c4e86e400b6da94fbeced82
BLAKE2b-256 5c0727f07bc26128aff6e93b526a0980c52afb0972d7d93d64efbb52856d9ca3

See more details on using hashes here.

Supported by

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