-
Notifications
You must be signed in to change notification settings - Fork 361
Expand file tree
/
Copy pathsong.py
More file actions
57 lines (53 loc) · 2.33 KB
/
Copy pathsong.py
File metadata and controls
57 lines (53 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pyrogram import Client, filters
import asyncio
import os
from pytube import YouTube
from pyrogram.types import InlineKeyboardMarkup
from pyrogram.types import InlineKeyboardButton
from youtubesearchpython import VideosSearch
from TamilBots.TamilBots import ignore_blacklisted_users, get_arg
from TamilBots import app, LOGGER
from TamilBots.sql.chat_sql import add_chat_to_db
def yt_search(song):
videosSearch = VideosSearch(song, limit=1)
result = videosSearch.result()
if not result:
return False
else:
video_id = result["result"][0]["id"]
url = f"https://youtu.be/{video_id}"
return url
@app.on_message(filters.create(ignore_blacklisted_users) & filters.command("song"))
async def song(client, message):
chat_id = message.chat.id
user_id = message.from_user["id"]
add_chat_to_db(str(chat_id))
args = get_arg(message) + " " + "song"
if args.startswith(" "):
await message.reply("Enter a song name. Check /help")
return ""
status = await message.reply("🚀 🔎 🔎 𝐒𝐞𝐚𝐫𝐜𝐡𝐢𝐧𝐠 𝐭𝐡𝐞 𝐬𝐨𝐧𝐠... 🎶 𝐏𝐥𝐞𝐚𝐬𝐞 𝐖𝐚𝐢𝐭 ⏳️ 𝐅𝐨𝐫 𝐅𝐞𝐰 𝐒𝐞𝐜𝐨𝐧𝐝𝐬 [🚀](https://telegra.ph/file/67f41ae52a85dfc0551ae.mp4)")
video_link = yt_search(args)
if not video_link:
await status.edit("✖️ 𝐅𝐨𝐮𝐧𝐝 𝐍𝐨𝐭𝐡𝐢𝐧𝐠. 𝐒𝐨𝐫𝐫𝐲.\n\n𝐓𝐫𝐲 𝐀𝐧𝐨𝐭𝐡𝐞𝐫 𝐊𝐞𝐲𝐰𝐨𝐫𝐤 𝐎𝐫 𝐌𝐚𝐲𝐛𝐞 𝐒𝐩𝐞𝐥𝐥 𝐈𝐭 𝐏𝐫𝐨𝐩𝐞𝐫𝐥𝐲.\n\nEg.`/song Faded`")
return ""
yt = YouTube(video_link)
audio = yt.streams.filter(only_audio=True).first()
try:
download = audio.download(filename=f"{str(user_id)}")
except Exception as ex:
await status.edit("Failed to download song 😶")
LOGGER.error(ex)
return ""
rename = os.rename(download, f"{str(user_id)}.mp3")
await app.send_chat_action(message.chat.id, "upload_audio")
await app.send_audio(
chat_id=message.chat.id,
audio=f"{str(user_id)}.mp3",
duration=int(yt.length),
title=str(yt.title),
performer=str(yt.author),
reply_to_message_id=message.message_id,
)
await status.delete()
os.remove(f"{str(user_id)}.mp3")