Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,23 @@ Check out the [official API reference](https://platform.openai.com/docs/api-refe
| `SHOW_PLUGINS_USED` | Whether to show which plugins were used for a response | `false` |

#### Available plugins
| Name | Description | Required environment variable(s) | Dependency |
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|---------------------|
| `weather` | Daily weather and 7-day forecast for any location (powered by [Open-Meteo](https://open-meteo.com)) | - | |
| `wolfram` | WolframAlpha queries (powered by [WolframAlpha](https://www.wolframalpha.com)) | `WOLFRAM_APP_ID` | `wolframalpha` |
| `ddg_web_search` | Web search (powered by [DuckDuckGo](https://duckduckgo.com)) | - | `duckduckgo_search` |
| `ddg_image_search` | Search image or GIF (powered by [DuckDuckGo](https://duckduckgo.com)) | - | `duckduckgo_search` |
| `crypto` | Live cryptocurrencies rate (powered by [CoinCap](https://coincap.io)) - by [@stumpyfr](https://github.com/stumpyfr) | - | |
| `spotify` | Spotify top tracks/artists, currently playing song and content search (powered by [Spotify](https://spotify.com)). Requires one-time authorization. | `SPOTIFY_CLIENT_ID`, `SPOTIFY_CLIENT_SECRET`, `SPOTIFY_REDIRECT_URI` | `spotipy` |
| `worldtimeapi` | Get latest world time (powered by [WorldTimeAPI](https://worldtimeapi.org/)) - by [@noriellecruz](https://github.com/noriellecruz) | `WORLDTIME_DEFAULT_TIMEZONE` | |
| `dice` | Send a dice in the chat! | - | |
| `youtube_audio_extractor` | Extract audio from YouTube videos | - | `pytube` |
| `deepl_translate` | Translate text to any language (powered by [DeepL](https://deepl.com)) - by [@LedyBacer](https://github.com/LedyBacer) | `DEEPL_API_KEY` | |
| `gtts_text_to_speech` | Text to speech (powered by Google Translate APIs) | - | `gtts` |
| `whois` | Query the whois domain database - by [@jnaskali](https://github.com/jnaskali) | - | `whois` |
| `webshot` | Screenshot a website from a given url or domain name - by [@noriellecruz](https://github.com/noriellecruz) | - | |
| `auto_tts` | Text to speech using OpenAI APIs - by [@Jipok](https://github.com/Jipok) | - | |
| Name | Description | Required environment variable(s) | Dependency |
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|---------------------|
| `weather` | Daily weather and 7-day forecast for any location (powered by [Open-Meteo](https://open-meteo.com)) | - | |
| `wolfram` | WolframAlpha queries (powered by [WolframAlpha](https://www.wolframalpha.com)) | `WOLFRAM_APP_ID` | `wolframalpha` |
| `ddg_web_search` | Web search (powered by [DuckDuckGo](https://duckduckgo.com)) | - | `duckduckgo_search` |
| `ddg_image_search` | Search image or GIF (powered by [DuckDuckGo](https://duckduckgo.com)) | - | `duckduckgo_search` |
| `crypto` | Live cryptocurrencies rate (powered by [CoinCap](https://coincap.io)) - by [@stumpyfr](https://github.com/stumpyfr) | - | |
| `spotify` | Spotify top tracks/artists, currently playing song and content search (powered by [Spotify](https://spotify.com)). Requires one-time authorization. | `SPOTIFY_CLIENT_ID`, `SPOTIFY_CLIENT_SECRET`, `SPOTIFY_REDIRECT_URI` | `spotipy` |
| `worldtimeapi` | Get latest world time (powered by [WorldTimeAPI](https://worldtimeapi.org/)) - by [@noriellecruz](https://github.com/noriellecruz) | `WORLDTIME_DEFAULT_TIMEZONE` | |
| `dice` | Send a dice in the chat! | - | |
| `youtube_audio_extractor` | Extract audio from YouTube videos | - | `pytube` |
| `ytdlp_audio_extractor` | Extract audio from YouTube videos with [yt-dlp](https://github.com/yt-dlp/yt-dlp) | - | `yt-dlp` |
| `deepl_translate` | Translate text to any language (powered by [DeepL](https://deepl.com)) - by [@LedyBacer](https://github.com/LedyBacer) | `DEEPL_API_KEY` | |
| `gtts_text_to_speech` | Text to speech (powered by Google Translate APIs) | - | `gtts` |
| `whois` | Query the whois domain database - by [@jnaskali](https://github.com/jnaskali) | - | `whois` |
| `webshot` | Screenshot a website from a given url or domain name - by [@noriellecruz](https://github.com/noriellecruz) | - | |
| `auto_tts` | Text to speech using OpenAI APIs - by [@Jipok](https://github.com/Jipok) | - | |

#### Environment variables
| Variable | Description | Default value |
Expand Down
2 changes: 2 additions & 0 deletions bot/plugin_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from bot.plugins.yt_dlp_extractor import YTDLPExtractorPlugin
from plugins.gtts_text_to_speech import GTTSTextToSpeech
from plugins.auto_tts import AutoTextToSpeech
from plugins.dice import DicePlugin
Expand Down Expand Up @@ -33,6 +34,7 @@ def __init__(self, config):
'spotify': SpotifyPlugin,
'worldtimeapi': WorldTimeApiPlugin,
'youtube_audio_extractor': YouTubeAudioExtractorPlugin,
'ytdlp_audio_extractor': YTDLPExtractorPlugin,
'dice': DicePlugin,
'deepl_translate': DeeplTranslatePlugin,
'gtts_text_to_speech': GTTSTextToSpeech,
Expand Down
45 changes: 45 additions & 0 deletions bot/plugins/yt_dlp_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging
import os
import time

import yt_dlp
from typing import Dict

from bot.plugins.youtube_audio_extractor import YouTubeAudioExtractorPlugin


class YTDLPExtractorPlugin(YouTubeAudioExtractorPlugin):
@staticmethod
def _delete_old_files():
current_time = time.time()
for file in os.listdir('tmp'):
file_path = os.path.join('tmp', file)
file_age = (current_time - os.path.getatime(file_path))
if file_age > 60 * 60:
os.remove(file_path)

async def execute(self, function_name, helper, **kwargs) -> Dict:
try:

link = kwargs['youtube_link']
ret = yt_dlp.YoutubeDL(params={
'quiet': True,
'no_color': True,
'format': 'bestaudio',
'socket_timeout': 30,
'ignore_no_formats_error': True,
'outtmpl': 'tmp/%(title)s.%(ext)s',
})
video = ret.extract_info(link)
file_path = video['requested_downloads'][0]['filepath']
self._delete_old_files()
return {
'direct_result': {
'kind': 'file',
'format': 'path',
'value': file_path
}
}
except Exception as e:
logging.warning(f'Failed to extract audio from YouTube video: {str(e)}')
return {'result': 'Failed to extract audio'}
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pytube~=15.0.0
gtts~=2.5.4
whois~=0.9.27
Pillow~=11.0.0
yt-dlp>=2025.3.27