5 Commits

7 changed files with 69 additions and 76 deletions

1
.gitignore vendored
View File

@@ -30,6 +30,7 @@ env/
.config/ .config/
config*.yaml config*.yaml
!config.yaml.example !config.yaml.example
.archive/
# Logs # Logs
*.log *.log

View File

@@ -7,7 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [1.2.0] - 2024-07-01 ## [1.2.2] - 2025-02-25
### Added
- Improved stream reconnection verification with log entries
- Enhanced metadata endpoint discovery with multiple URL patterns
- Expanded error handling and logging for metadata fetching
### Changed
- Refactored stream monitoring for better stability
- Updated metadata parsing to handle varied source formats
- General project cleanup and housekeeping
### Fixed
- Stream reconnection edge cases and timeout handling
- JSON metadata parsing reliability
- Various validations
## [1.2.1] - 2025-02-25
### Added
- Improved stream reconnection logic with automatic retry
- Enhanced metadata fetching with better error handling
- Expanded logging for better troubleshooting
### Fixed
- Issue with metadata parsing for certain stream formats
- Stream monitoring stability improvements
- Connection timeout handling
## [1.2.0] - 2025-02-25
### Added ### Added
- New admin commands: - New admin commands:
@@ -26,7 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the BotManager class to support the new terminal commands - Improved the BotManager class to support the new terminal commands
- Updated configuration example to include the new quiet_on_start option - Updated configuration example to include the new quiet_on_start option
## [1.0.1] - 2024-02-24 ## [1.0.1] - 2025-02-24
### Added ### Added
- Configurable logging levels via config.yaml - Configurable logging levels via config.yaml
@@ -64,7 +94,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Other ### Other
- Added version information - Added version information
## [1.0.0] - 2024-02-23 ## [1.0.0] - 2025-02-23
### Added ### Added
- Initial release - Initial release
@@ -75,7 +105,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Multi-bot support - Multi-bot support
- Configuration via YAML files - Configuration via YAML files
[Unreleased]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.2.0...HEAD [Unreleased]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.2.2...HEAD
[1.2.2]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.2.1...v1.2.2
[1.2.1]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.2.0...v1.2.1
[1.2.0]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.0.1...v1.2.0 [1.2.0]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.0.1...v1.2.0
[1.0.1]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.0.0...v1.0.1 [1.0.1]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/compare/v1.0.0...v1.0.1
[1.0.0]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/releases/tag/v1.0.0 [1.0.0]: https://code.cottongin.xyz/cottongin/Icecast-metadata-IRC-announcer/releases/tag/v1.0.0

38
TODO.md
View File

@@ -1,16 +1,26 @@
## TODO ## TODO 🚧
- Better, more clear, logging - ⭐️ Better, more clear, logging
- Add a help command - Notification system for stream admin (and bot admin)
- Add commands to control the stream connection from IRC - Send notification if unexpected change in metadata
- Also to start/stop the service entirely - Loss of network/stream
- Add a version command - Live notifications (alt. for PodPing ish)
- Add a list of commands to the README - Implement `quiet mode`
- ⭐️ Add whitelist feature
- Add commands:
- To check the status of the bot
- To check the status of the stream
- To check the status of the IRC connection
- Version command
- Enable joining multiple channels with a single bot instance - Enable joining multiple channels with a single bot instance
- Add a command to force the bot to reconnect to the stream
- Add a command to check the status of the bot ## Complete! 🎉
- Add a command to check the status of the stream
- Add a command to check the status of the IRC connection - ✅ Move this to a TODO.md file 😊
- Add a command to check the status of the bot - 🟢 Added commands:
- Add a command to check the status of the stream - Add `quiet mode` relevant commands
- Move this to a TODO.md file :) - ✅ Add a help command
- ✅ To control the stream connection from IRC
- ✅ To start/stop the service entirely
- ✅ To quiet/unquiet the metadata announcing
- ✅ Add a list of commands to the README

View File

@@ -1 +1 @@
1.2.0 1.2.2

24
bot.sh
View File

@@ -1,24 +0,0 @@
#!/bin/bash
# Check if any arguments were provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <config.yaml> [additional configs...]"
exit 1
fi
while true; do
# Remove any existing restart flags before starting
rm -f .restart_flag_*
python main.py "$@"
# Check for any restart flags
if ls .restart_flag_* 1> /dev/null 2>&1; then
echo "Restart flag(s) found, restarting bot(s)..."
sleep 1
continue
else
echo "Bot(s) exited without restart flag, stopping..."
break
fi
done

View File

@@ -1,12 +0,0 @@
#!/usr/bin/env python3
import asyncio
from main import run_multiple_bots
CONFIG_FILES = [
'config_station1.yaml',
'config_station2.yaml',
'config_station3.yaml'
]
if __name__ == "__main__":
asyncio.run(run_multiple_bots(CONFIG_FILES))

28
main.py
View File

@@ -11,7 +11,6 @@ import argparse
import yaml import yaml
from pathlib import Path from pathlib import Path
from typing import List, Optional from typing import List, Optional
import sys
import inspect import inspect
import socket import socket
import tempfile import tempfile
@@ -59,17 +58,6 @@ def silent_client_init(self, *args, bot_name: str = None, config: dict = None, *
original_init = Client.__init__ original_init = Client.__init__
Client.__init__ = silent_client_init Client.__init__ = silent_client_init
import asyncio
import aiohttp
import time
import argparse
import yaml
from pathlib import Path
from typing import List, Optional
import sys
import inspect
import socket
import tempfile
class RestartManager: class RestartManager:
"""Manages restart requests for the bot. """Manages restart requests for the bot.
@@ -492,8 +480,6 @@ class IcecastBot:
first_line = handler.__doc__.strip().split('\n')[0] first_line = handler.__doc__.strip().split('\n')[0]
# Format it using the template and add (admin only) if needed # Format it using the template and add (admin only) if needed
desc = first_line.split(':', 1)[1].strip() desc = first_line.split(':', 1)[1].strip()
if pattern in self.admin_commands:
desc = f"{desc} (admin only)"
help_text = self.help_specific_format.format( help_text = self.help_specific_format.format(
prefix=self.cmd_prefix, prefix=self.cmd_prefix,
cmd=pattern, cmd=pattern,
@@ -559,7 +545,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('restart')) @self.bot.on_message(create_command_pattern('restart'))
@self.admin_required @self.admin_required
async def restart_bot(message): async def restart_bot(message):
"""!restart: Restart the bot (admin only) """!restart: Restart the bot
Gracefully shuts down the bot and signals the bot.sh script Gracefully shuts down the bot and signals the bot.sh script
to restart it. This ensures a clean restart. to restart it. This ensures a clean restart.
@@ -581,7 +567,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('quit')) @self.bot.on_message(create_command_pattern('quit'))
@self.admin_required @self.admin_required
async def quit_bot(message): async def quit_bot(message):
"""!quit: Shutdown the bot (admin only) """!quit: Shutdown the bot
Gracefully shuts down the bot and exits without restarting. Gracefully shuts down the bot and exits without restarting.
@@ -600,7 +586,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('reconnect')) @self.bot.on_message(create_command_pattern('reconnect'))
@self.admin_required @self.admin_required
async def reconnect_stream(message): async def reconnect_stream(message):
"""!reconnect: Reconnect to the stream (admin only) """!reconnect: Reconnect to the stream
Attempts to reconnect to the stream and verifies the connection. Attempts to reconnect to the stream and verifies the connection.
Reports success or failure back to the channel. Reports success or failure back to the channel.
@@ -616,7 +602,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('stop')) @self.bot.on_message(create_command_pattern('stop'))
@self.admin_required @self.admin_required
async def stop_monitoring(message): async def stop_monitoring(message):
"""!stop: Stop stream monitoring (admin only) """!stop: Stop stream monitoring
Stops monitoring the stream for metadata changes. Stops monitoring the stream for metadata changes.
The bot remains connected to IRC. The bot remains connected to IRC.
@@ -632,7 +618,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('start')) @self.bot.on_message(create_command_pattern('start'))
@self.admin_required @self.admin_required
async def start_monitoring(message): async def start_monitoring(message):
"""!start: Start stream monitoring (admin only) """!start: Start stream monitoring
Starts monitoring the stream for metadata changes. Starts monitoring the stream for metadata changes.
Will announce new songs in the channel. Will announce new songs in the channel.
@@ -648,7 +634,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('quiet')) @self.bot.on_message(create_command_pattern('quiet'))
@self.admin_required @self.admin_required
async def quiet_bot(message): async def quiet_bot(message):
"""!quiet: Disable song announcements (admin only) """!quiet: Disable song announcements
Continues monitoring the stream for metadata changes, Continues monitoring the stream for metadata changes,
but stops announcing songs in the channel. but stops announcing songs in the channel.
@@ -665,7 +651,7 @@ class IcecastBot:
@self.bot.on_message(create_command_pattern('unquiet')) @self.bot.on_message(create_command_pattern('unquiet'))
@self.admin_required @self.admin_required
async def unquiet_bot(message): async def unquiet_bot(message):
"""!unquiet: Enable song announcements (admin only) """!unquiet: Enable song announcements
Resumes announcing songs in the channel. Resumes announcing songs in the channel.
The bot must already be monitoring the stream. The bot must already be monitoring the stream.