mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-22 07:04:59 +01:00
added youtube audio extractor, dice, and direct response for images
This commit is contained in:
44
bot/plugins/youtube_audio_extractor.py
Normal file
44
bot/plugins/youtube_audio_extractor.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from typing import Dict
|
||||
|
||||
from pytube import YouTube
|
||||
|
||||
from .plugin import Plugin
|
||||
|
||||
|
||||
class YouTubeAudioExtractorPlugin(Plugin):
|
||||
"""
|
||||
A plugin to extract audio from a YouTube video
|
||||
"""
|
||||
|
||||
def get_source_name(self) -> str:
|
||||
return "YouTube Audio Extractor"
|
||||
|
||||
def get_spec(self) -> [Dict]:
|
||||
return [{
|
||||
"name": "extract_youtube_audio",
|
||||
"description": "Extract audio from a YouTube video",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"youtube_link": {"type": "string", "description": "YouTube video link to extract audio from"}
|
||||
},
|
||||
"required": ["youtube_link"],
|
||||
},
|
||||
}]
|
||||
|
||||
async def execute(self, function_name, **kwargs) -> Dict:
|
||||
link = kwargs['youtube_link']
|
||||
try:
|
||||
video = YouTube(link)
|
||||
audio = video.streams.filter(only_audio=True, file_extension='mp4').first()
|
||||
output = video.title + '.mp4'
|
||||
audio.download(filename=output)
|
||||
return {
|
||||
'direct_result': {
|
||||
'kind': 'file',
|
||||
'format': 'path',
|
||||
'value': output
|
||||
}
|
||||
}
|
||||
except:
|
||||
return {'result': 'Failed to extract audio'}
|
||||
Reference in New Issue
Block a user