2025-02-23 00:55:11 -08:00
# Icecast-metadata-IRC-announcer
2025-02-24 14:26:48 -08:00
[](https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/releases)
2025-02-24 11:17:23 -08:00
2025-02-23 00:55:11 -08:00
A simple asynchronous Python bot that monitors an Icecast stream and announces track changes to an IRC channel. Supports running multiple instances with different configurations.
2025-02-23 01:06:37 -08:00
Note: This is a work in progress. It has only been tested on **Python 3.12.6** .
2025-02-23 00:55:11 -08:00
## Features
- Monitors Icecast stream metadata and announces track changes
- Configurable via YAML files and command line arguments
- Supports running multiple bot instances simultaneously
- Pattern-based song title filtering
2025-02-24 11:08:25 -08:00
- Configurable logging levels and output
- Smart URL resolution for metadata fetching
- Automatic reconnection and error recovery with status reporting
- Admin commands with permission system
2025-02-23 00:55:11 -08:00
## Dependencies
- [asif ](https://github.com/minus7/asif )
- [aiohttp ](https://github.com/aio-libs/aiohttp )
- [pyyaml ](https://github.com/yaml/pyyaml )
## Installation
1. Clone the repository
2. Install dependencies:
```bash
2025-02-23 01:07:42 -08:00
pip install -r requirements.txt
2025-02-23 00:55:11 -08:00
```
## Configuration
Create a YAML config file (default: `config.yaml` ):
```yaml
irc:
host: "irc.example.net"
port: 6667
nick: "MusicBot"
user: "musicbot"
realname: "Music Announcer Bot"
channel: "#music "
stream:
url: "https://stream.example.com"
endpoint: "stream"
health_check_interval: 300
announce:
format: "\x02Now playing:\x02 {song}"
ignore_patterns:
- "Unknown"
- "Unable to fetch metadata"
2025-02-24 11:08:25 -08:00
- "Error fetching metadata"
commands:
prefix: "!" # Command prefix (e.g. !np, !help)
require_nick_prefix: false # If true, commands must be prefixed with "botname: " or "botname, "
allow_private_commands: false # If true, allows commands in private messages
admin:
users: # List of users who can use admin commands (use "*" for anyone)
- "*"
logging:
level: "INFO" # Logging level: DEBUG, INFO, WARNING, ERROR, or CRITICAL
2025-02-23 00:55:11 -08:00
```
## Usage
2025-02-24 11:08:25 -08:00
### Running with Automatic Restart Support
The recommended way to run the bot is using the provided `bot.sh` script, which handles automatic restarts when using the `!restart` command:
```bash
# Make the script executable
chmod +x bot.sh
# Run a single bot
./bot.sh config.yaml
# Run multiple bots
./bot.sh config1.yaml config2.yaml config3.yaml
```
### Manual Running
You can also run the bot directly with Python:
#### Single Bot Mode
2025-02-23 00:55:11 -08:00
Run with config file:
```bash
python main.py --config myconfig.yaml
```
Override config with command line arguments:
```bash
python main.py --config myconfig.yaml --irc-nick CustomNick --irc-channel "#mychannel "
```
Available command line arguments:
- `--config` : Path to config file
- `--irc-host` : IRC server hostname
- `--irc-port` : IRC server port
- `--irc-nick` : IRC nickname
- `--irc-channel` : IRC channel to join
- `--stream-url` : Icecast base URL
- `--stream-endpoint` : Stream endpoint
2025-02-24 11:08:25 -08:00
- `--cmd-prefix` : Command prefix character(s)
2025-02-23 00:55:11 -08:00
2025-02-24 11:08:25 -08:00
#### Multiple Bot Mode
2025-02-23 00:55:11 -08:00
Run multiple instances with different configs:
```bash
python main.py config1.yaml config2.yaml config3.yaml
```
## IRC Commands
2025-02-24 11:08:25 -08:00
Regular commands:
2025-02-23 00:55:11 -08:00
- `!np` : Shows the currently playing track
2025-02-24 11:08:25 -08:00
- `!help` : Shows available commands
Admin commands:
- `!start` : Start stream monitoring
- `!stop` : Stop stream monitoring
- `!reconnect` : Reconnect to stream (with status feedback)
- `!restart` : Restart the bot (requires using bot.sh)
- `!quit` : Shutdown the bot
2025-02-23 00:55:11 -08:00
## Logging
2025-02-24 11:08:25 -08:00
The bot supports different logging levels configurable in the config.yaml:
- DEBUG: Detailed information for troubleshooting
- INFO: General operational messages (default)
- WARNING: Warning messages and potential issues
- ERROR: Error messages only
- CRITICAL: Critical failures only
Logs include:
- Stream health status
- Command processing
- Connection status
- Error details
The bot also maintains an ERROR.log file for critical issues.
2025-02-23 00:55:11 -08:00
## Error Handling
- Automatically reconnects on connection drops
- Retries stream monitoring on errors
2025-02-24 11:08:25 -08:00
- Smart metadata URL resolution
- Connection status verification and reporting
2025-02-23 00:55:11 -08:00
- Health checks every 5 minutes (configurable)
## License
This project is licensed under the MIT License. See the LICENSE file for details.