This is a Telegram bot built using python-telegram-bot
to interact with Sonarr and Radarr for managing TV shows and movies. The bot allows users to search for media, check if it's already in Sonarr/Radarr, and add new series or movies as needed. It also features a "night mode" to restrict non-admin users from sending messages during specific hours.
- Media Search: Search for TV shows and movies via the TMDB API.
- Sonarr/Radarr Integration: Add movies or TV series directly to Sonarr or Radarr with a quality profile and root folder path.
- Night Mode: Automatically restricts non-admin messages in the group during night hours (00:00 - 07:00) or can be enabled/disabled manually.
- User Interaction: Welcomes new members and handles media confirmation requests.
- Language Support: Supports different languages for TMDB searches.
- Group Settings: Saves group chat ID and language preferences in an SQLite database.
Before running the bot, ensure that you have the following:
- Python 3.8+
- Telegram bot token from BotFather
- Sonarr and Radarr APIs set up
- TMDB API key from The Movie Database
-
Clone the repository:
git clone https://github.com/your-username/streamnet-tv-bot.git cd streamnet-tv-bot
-
Install the required dependencies:
pip install -r requirements.txt
-
Create a
config.json
file in theconfig/
directory:{ "bot": { "TOKEN": "<your-telegram-bot-token>", "TIMEZONE": "Europe/Berlin", "LOG_LEVEL": "INFO" }, "welcome": { "IMAGE_URL": "<welcome-image-url>", "BUTTON_URL": "<button-url>" }, "tmdb": { "API_KEY": "<your-tmdb-api-key>", "DEFAULT_LANGUAGE": "en" }, "sonarr": { "URL": "<your-sonarr-url>", "API_KEY": "<your-sonarr-api-key>", "QUALITY_PROFILE_NAME": "<sonarr-quality-profile-name>", "ROOT_FOLDER_PATH": "<sonarr-root-folder-path>" }, "radarr": { "URL": "<your-radarr-url>", "API_KEY": "<your-radarr-api-key>", "QUALITY_PROFILE_NAME": "<radarr-quality-profile-name>", "ROOT_FOLDER_PATH": "<radarr-root-folder-path>" } }
-
Initialize the SQLite database (automatically done on first run):
python bot.py
The bot requires a config.json
file in the config/
directory. This file contains the API tokens, URLs, and preferences for the bot.
Example configuration:
{
"bot": {
"TOKEN": "<your-telegram-bot-token>",
"TIMEZONE": "Europe/Berlin",
"LOG_LEVEL": "INFO"
},
"welcome": {
"IMAGE_URL": "<welcome-image-url>",
"BUTTON_URL": "<button-url>"
},
"tmdb": {
"API_KEY": "<your-tmdb-api-key>",
"DEFAULT_LANGUAGE": "en"
},
"sonarr": {
"URL": "<your-sonarr-url>",
"API_KEY": "<your-sonarr-api-key>",
"QUALITY_PROFILE_NAME": "<sonarr-quality-profile-name>",
"ROOT_FOLDER_PATH": "<sonarr-root-folder-path>"
},
"radarr": {
"URL": "<your-radarr-url>",
"API_KEY": "<your-radarr-api-key>",
"QUALITY_PROFILE_NAME": "<radarr-quality-profile-name>",
"ROOT_FOLDER_PATH": "<radarr-root-folder-path>"
}
}
The following commands are available:
/start
: Initializes the bot and welcomes the user./search <title>
: Searches for a movie or TV show using the TMDB API./set_group_id
: Sets the group chat ID./set_language <code>
: Sets the preferred language for TMDB searches./enable_night_mode
: Enables night mode (00:00 - 07:00)./disable_night_mode
: Disables night mode.
- Search: Use
/search <title>
to find a TV show or movie. - Add Series: Once a TV series is found, users can add it to Sonarr by confirming with
yes
. - Add Movie: Once a movie is found, users can add it to Radarr by confirming with
yes
.
python-telegram-bot
: For handling Telegram API.requests
: For making API requests to Sonarr, Radarr, and TMDB.nest_asyncio
: To handle event loops.pytz
: For handling timezone conversions.SQLite3
: For storing group ID and language settings.
Install dependencies via:
pip install -r requirements.txt
To run the bot:
python bot.py
The bot will start polling and waiting for commands on Telegram.
If you wish to contribute to the project, feel free to fork the repository, make your changes, and submit a pull request. Contributions, issues, and feature requests are welcome!
- Fork the repository.
- Create your feature branch (
git checkout -b feature/new-feature
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/new-feature
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.