Initial Commit
This commit is contained in:
commit
d9eeb838c1
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Patrick Ulrich
|
||||
|
||||
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.
|
75
README.md
Normal file
75
README.md
Normal file
@ -0,0 +1,75 @@
|
||||
# AzuraCast Nostr Bot
|
||||
|
||||
AzuraCast Nostr Bot is a Node.js bot that broadcasts AzuraCast's 'Now Playing' information to a set of Nostr relays in real-time.
|
||||
|
||||
## Broadcast Now Playing Information on the Nostr Network
|
||||
|
||||
The bot listens for incoming webhooks from AzuraCast and publishes real-time "Now Playing" information about the currently playing song or podcast episode on your radio station to the defined Nostr relays. Listeners and followers on Nostr can stay updated about what's currently playing on your station and join the live broadcast with a single click.
|
||||
|
||||
## Key Features
|
||||
|
||||
- Real-time publication of "Now Playing" information to Nostr.
|
||||
- Supports broadcasting to multiple Nostr relays for increased visibility.
|
||||
- Configurable webhook endpoint and SSL support for secure communication.
|
||||
- Easy integration with AzuraCast stations.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Node.js and npm installed on your system.
|
||||
- AzuraCast instance with webhook integration enabled.
|
||||
- SSL certificate and key for secure communication (e.g., Let's Encrypt).
|
||||
- A Nostr private key (hex format) to be specified in the configuration file.
|
||||
|
||||
## Setup and Configuration
|
||||
|
||||
1. Clone this repository or download the source code.
|
||||
|
||||
```
|
||||
git clone https://github.com/patrickulrich/azuracast-nostr-bot.git
|
||||
cd azuracast-nostr-bot
|
||||
```
|
||||
|
||||
2. Install the required npm packages.
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
3. Configure the bot by editing the `config.js` file. Specify the following information:
|
||||
|
||||
- `privateKey`: Your pre-existing Nostr private key (hex string).
|
||||
- `stationWebpageUrl`: The URL of your AzuraCast station's public webpage.
|
||||
- `sslOptions`: The file paths for your SSL certificate and key.
|
||||
- `relayUrls`: An array of Nostr relay URLs to which you want to publish events.
|
||||
|
||||
4. Start the bot.
|
||||
|
||||
```
|
||||
node anb.js
|
||||
```
|
||||
|
||||
The bot will start listening for incoming webhooks on port 3000.
|
||||
|
||||
5. Configure the webhook integration in your AzuraCast instance. Set the webhook URL to `https://your-domain:3000/webhook`.
|
||||
|
||||
## Usage
|
||||
|
||||
Once the bot is running and the webhook is configured, it will automatically publish "Now Playing" information to the specified Nostr relays whenever a new song or podcast episode starts playing on your AzuraCast station. The published event will include the title, artist, station name, and a link to the station's webpage.
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions, issues, and feature requests are welcome. Feel free to check the [Issues](https://github.com/patrickulrich/azuracast-nostr-bot/issues) page if you want to contribute.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the [MIT License](LICENSE).
|
||||
|
||||
## Contact
|
||||
|
||||
- Patrick Ulrich - npub1patrlck0muvqevgytp4etpen0xsvrlw0hscp4qxgy40n852lqwwsz79h9a
|
||||
- Project Link: https://github.com/patrickulrich/azuracast-nostr-bot
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
- [AzuraCast](https://www.azuracast.com/)
|
||||
- [Nostr](https://github.com/fiatjaf/nostr)
|
75
anb.js
Normal file
75
anb.js
Normal file
@ -0,0 +1,75 @@
|
||||
// anb.js
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const { getPublicKey, signEvent, getEventHash, relayInit } = require('nostr-tools');
|
||||
const config = require('./config');
|
||||
|
||||
// Use values from the config
|
||||
const sk = config.privateKey;
|
||||
const pk = getPublicKey(sk);
|
||||
const stationWebpageUrl = config.stationWebpageUrl;
|
||||
const sslOptions = {
|
||||
key: fs.readFileSync(config.sslOptions.key),
|
||||
cert: fs.readFileSync(config.sslOptions.cert),
|
||||
};
|
||||
const relayUrls = config.relayUrls;
|
||||
|
||||
// Initialize and connect to each relay
|
||||
const relays = relayUrls.map(url => {
|
||||
const relay = relayInit(url);
|
||||
relay.connect().catch(error => {
|
||||
console.error(`Failed to connect to relay ${url}:`, error);
|
||||
});
|
||||
return relay;
|
||||
});
|
||||
|
||||
// Create an HTTPS server to listen for incoming webhooks from AzuraCast
|
||||
const server = https.createServer(sslOptions, (req, res) => {
|
||||
if (req.method === 'POST' && req.url === '/webhook') {
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk.toString();
|
||||
});
|
||||
req.on('end', () => {
|
||||
// Parse the JSON payload from the webhook request (NowPlaying data)
|
||||
const nowPlayingData = JSON.parse(body);
|
||||
|
||||
// Extract relevant information from the NowPlaying data
|
||||
const songTitle = nowPlayingData.now_playing.song.title;
|
||||
const artistName = nowPlayingData.now_playing.song.artist;
|
||||
const stationName = nowPlayingData.station.name;
|
||||
|
||||
// Create a Nostr event with the extracted information and a link to the station webpage
|
||||
const event = {
|
||||
kind: 1, // Custom event kind
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [],
|
||||
content: `Song "${songTitle}" by ${artistName} is now playing on station "${stationName}". Listen here: ${stationWebpageUrl}`,
|
||||
pubkey: pk,
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, sk);
|
||||
|
||||
// Publish the event to each Nostr relay
|
||||
relays.forEach(relay => {
|
||||
const pub = relay.publish(event);
|
||||
pub.on('ok', () => {
|
||||
console.log(`Successfully published event to ${relay.url}`);
|
||||
});
|
||||
pub.on('failed', reason => {
|
||||
console.error(`Failed to publish to ${relay.url}: ${reason}`);
|
||||
});
|
||||
});
|
||||
|
||||
res.end('Event published');
|
||||
});
|
||||
} else {
|
||||
res.statusCode = 404;
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
|
||||
// Start the HTTPS server
|
||||
server.listen(3000, () => {
|
||||
console.log('Server is listening on port 3000');
|
||||
});
|
21
config.js
Normal file
21
config.js
Normal file
@ -0,0 +1,21 @@
|
||||
// config.js
|
||||
module.exports = {
|
||||
// Your pre-existing Nostr private key (hex string)
|
||||
privateKey: 'YOUR_NOSTR_PRIVATE_KEY',
|
||||
|
||||
// The URL of your AzuraCast station's public webpage
|
||||
stationWebpageUrl: 'YOUR_AZURACAST_STATION_WEBPAGE_URL',
|
||||
|
||||
// File paths for your SSL certificate and key (e.g., Let's Encrypt)
|
||||
sslOptions: {
|
||||
key: 'PATH_TO_YOUR_SSL_PRIVATE_KEY',
|
||||
cert: 'PATH_TO_YOUR_SSL_CERTIFICATE',
|
||||
},
|
||||
|
||||
// An array of Nostr relay URLs to which you want to publish events
|
||||
relayUrls: [
|
||||
'NOSTR_RELAY_URL_1',
|
||||
'NOSTR_RELAY_URL_2',
|
||||
// Add more relay URLs as needed
|
||||
],
|
||||
};
|
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "azuracast-nostr-bot",
|
||||
"version": "1.0.0",
|
||||
"description": "AzuraCast Nostr Bot broadcasts AzuraCast's 'Now Playing' information to a set of Nostr relays in real-time.",
|
||||
"main": "anb.js",
|
||||
"scripts": {
|
||||
"start": "node anb.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"nostr-tools": "^1.0.3"
|
||||
},
|
||||
"author": "Patrick Ulrich",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user