├── .gitattributes ├── screenshot.png ├── .gitignore ├── LICENSE ├── README.md └── ytgr.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thezawad/teletubemp3/HEAD/screenshot.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | api.txt 3 | ok.html 4 | ok 5 | DeshBashi To(Despacito Parody) LuisFonsi-Daddy Yankee Ft VATMAN[[VIDEO BABA PRODUCTIONS]]-5TJqoxsoXc4.mp3 6 | DeshBashi To Despacito Parody Justin Bieber Ft VATMAN Abul Mal Bangla Funny Parody BC-24qlZXaIYVA.mp3 7 | DeshBashi To(Despacito Parody) LuisFonsi-Daddy Yankee Ft VATMAN[[VIDEO BABA PRODUCTIONS]]-5TJqoxsoXc4.mp3 8 | .DS_Store 9 | DeshBashi To(Despacito Parody) LuisFonsi-Daddy Yankee Ft VATMAN[[VIDEO BABA PRODUCTIONS]]-5TJqoxsoXc4.mp3 10 | DeshBashi To(Despacito Parody) LuisFonsi-Daddy Yankee Ft VATMAN[[VIDEO BABA PRODUCTIONS]]-5TJqoxsoXc4.mp3 11 | *.mp3 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Zawad Bin Hafiz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # teletubemp3 - A Telegram Bot 2 | 3 | **teletubemp3 is a Telegram Bot which converts YouTube video(s) to mp3 and send directly to your Telegram.** 4 | 5 | yt despacito 6 | 7 | ### How does it work? 8 | 9 | * It takes your command ( `yt videoname` ) 10 | * Uses `videoname` as a *keyword* to search in **YouTube** 11 | * Takes the first link from YouTube 12 | * Download that video using **youtube_dl** library 13 | * Converts it into mp3 using **youtube_dl** 14 | * Sends it to your chatbox 15 | 16 | ### Installation 17 | ``` 18 | git clone https://github.com/thezawad/teletubemp3.git 19 | cd teletubemp3 20 | pip install telepot 21 | pip install urllib2 22 | pip install requests 23 | pip install bs4 24 | pip install youtube_dl 25 | brew install youtube-dl 26 | brew install ffmpeg 27 | ``` 28 | Now create a file *api.txt* and put your **api-key** 29 | 30 | ### Run 31 | While in the directly, run 32 | 33 | `python ytgr.py` 34 | 35 | You'll see 36 | ``` 37 | [+] Server is Listenining [+] 38 | [=] Type Command from Telegram [=] 39 | ``` 40 | 41 | ### Usage 42 | In your Telegram message box. Text 43 | 44 | `yt videoname` 45 | 46 | The Bot will find out the video from YouTube, converts it and send it to your Telegram. 47 | -------------------------------------------------------------------------------- /ytgr.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import time 3 | import subprocess 4 | import telepot 5 | import os 6 | import urllib2 7 | import re 8 | import json 9 | import requests 10 | from bs4 import BeautifulSoup 11 | from urllib2 import urlopen 12 | import youtube_dl 13 | 14 | def handle(msg): 15 | chat_id = msg['chat']['id'] 16 | command = msg['text'] 17 | 18 | print "Command from client : %s " %command 19 | 20 | #youtube search 21 | if command.startswith('yt'): 22 | param = command[3:] 23 | response = urlopen("https://www.youtube.com/results?search_query="+param) 24 | data = response.read() 25 | response.close() 26 | soup = BeautifulSoup(data,"html.parser") 27 | vid = soup.find(attrs={'class':'yt-uix-tile-link'}) 28 | link = "https://www.youtube.com"+vid['href'] 29 | watchid = vid['href'] 30 | watchid = watchid.replace('/watch?v=','') 31 | title = vid['title'] 32 | print title 33 | print link 34 | bot.sendMessage(chat_id,title+"\n"+link) 35 | 36 | options = { 37 | 'format': 'bestaudio/best', 38 | 'postprocessors': [{ 39 | 'key': 'FFmpegExtractAudio', 40 | 'preferredcodec': 'mp3', 41 | 'preferredquality': '320' 42 | }] 43 | } 44 | filename = title+"-"+watchid+".mp3" 45 | filename = filename.replace(" ","_") 46 | filename = filename.replace("'","") 47 | filename = filename.replace("&","") 48 | filename = filename.replace("__","_") 49 | filename = filename.replace(",","") 50 | filename = filename.replace("(","") 51 | filename = filename.replace(")","") 52 | filename = filename.replace("[","") 53 | filename = filename.replace("]","") 54 | filename = filename.replace("{","") 55 | filename = filename.replace("}","") 56 | with youtube_dl.YoutubeDL(options) as ydl: 57 | ydl.download([link]) 58 | bot.sendAudio(chat_id,audio=open(filename,'rb')) 59 | print "Sent!" 60 | os.remove(filename) 61 | #end youtube search 62 | 63 | 64 | 65 | #api credentials 66 | api = open('api.txt','r') 67 | api_cont = api.read().strip() 68 | bot = telepot.Bot(api_cont) 69 | bot.message_loop(handle) 70 | print '[+] Server is Listenining [+]' 71 | print '[=] Type Command from Telegram [=]' 72 | 73 | while 1: 74 | time.sleep(10) 75 | --------------------------------------------------------------------------------