-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathjebot.py
199 lines (181 loc) · 6.58 KB
/
jebot.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Copyright (c) 2021 Infinity BOTs <https://t.me/Infinity_BOTs>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
import os
import aiohttp
import asyncio
import json
import sys
import time
from youtubesearchpython import SearchVideos
from pyrogram import filters, Client
from sample_config import Config
from youtube_dl import YoutubeDL
from youtube_dl.utils import (
ContentTooShortError,
DownloadError,
ExtractorError,
GeoRestrictedError,
MaxDownloadsReached,
PostProcessingError,
UnavailableVideoError,
XAttrMetadataError,
)
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery, InlineQuery, InputTextMessageContent
Jebot = Client(
"Song Downloader",
api_id=Config.APP_ID,
api_hash=Config.API_HASH,
bot_token=Config.TG_BOT_TOKEN,
)
#For private messages
#Ignore commands
#No bots also allowed
@Jebot.on_message(filters.edited & filters.group & ~filters.command("help") & ~filters.command("start"))
async def song(client, message):
#tvseriezzz_music #tvseriezzz_music
cap = "@tvseriezzz_music"
url = message.text
rkp = await message.reply("Processing...")
search = SearchVideos(url, offset=1, mode="json", max_results=1)
test = search.result()
p = json.loads(test)
q = p.get("search_result")
try:
url = q[0]["link"]
except BaseException:
return await rkp.edit("Failed to find that song.")
type = "audio"
if type == "audio":
opts = {
"format": "bestaudio",
"addmetadata": True,
"key": "FFmpegMetadata",
"writethumbnail": True,
"prefer_ffmpeg": True,
"geo_bypass": True,
"nocheckcertificate": True,
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "320",
}
],
"outtmpl": "%(id)s.mp3",
"quiet": True,
"logtostderr": False,
}
song = True
try:
await rkp.edit("Downloading...[🎧](https://te.legra.ph/file/c3dce12116a0a8af80c93.jpg)")
with YoutubeDL(opts) as rip:
rip_data = rip.extract_info(url)
except DownloadError as DE:
await rkp.edit(f"`{str(DE)}`")
return
except ContentTooShortError:
await rkp.edit("`The download content was too short.`")
return
except GeoRestrictedError:
await rkp.edit(
"`Video is not available from your geographic location due to geographic restrictions imposed by a website.`"
)
return
except MaxDownloadsReached:
await rkp.edit("`Max-downloads limit has been reached.`")
return
except PostProcessingError:
await rkp.edit("`There was an error during post processing.`")
return
except UnavailableVideoError:
await rkp.edit("`Media is not available in the requested format.`")
return
except XAttrMetadataError as XAME:
await rkp.edit(f"`{XAME.code}: {XAME.msg}\n{XAME.reason}`")
return
except ExtractorError:
await rkp.edit("`There was an error during info extraction.`")
return
except Exception as e:
await rkp.edit(f"{str(type(e)): {str(e)}}")
return
time.time()
if song:
await rkp.edit("Uploading....[🎧](https://te.legra.ph/file/c3dce12116a0a8af80c93.jpg)") #tvseriezzz_music
lol = "./thumb.jpg"
lel = await message.reply_audio(
f"{rip_data['id']}.mp3",
duration=int(rip_data["duration"]),
title=str(rip_data["title"]),
performer=str(rip_data["uploader"]),
thumb=lol,
caption=cap) #tvseriezzz_music
await rkp.delete()
@Jebot.on_message(filters.command("start"))
async def start(client, message):
if message.chat.type == 'private':
await Jebot.send_message(
chat_id=message.chat.id,
text="""<b>Hey There, I'm a Song Downloader Bot. A bot by @tvseriezzz_music.
Hit help button to find out more about how to use me</b>""",
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton(
"Help", callback_data="help"),
InlineKeyboardButton(
"Group", url="https://t.me/tvseriezzz_music")
]]
),
disable_web_page_preview=True,
parse_mode="html",
reply_to_message_id=message.message_id
)
else:
await Jebot.send_message(
chat_id=message.chat.id,
text="""<b>Song Downloader Is Online.\n\n</b>""",
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton(
"Help", callback_data="help")
]]
),
disable_web_page_preview=True,
parse_mode="html",
reply_to_message_id=message.message_id
)
@Jebot.on_message(filters.command("help"))
async def help(client, message):
if message.chat.type == 'private':
await Jebot.send_message(
chat_id=message.chat.id,
text="""<b>Send a song name to download song
@JEBotZ</b>""",
reply_to_message_id=message.message_id
)
else:
await Jebot.send_message(
chat_id=message.chat.id,
text="<b>Song Downloader Help.\n\nSyntax: `guleba`</b>",
reply_to_message_id=message.message_id
)
@Jebot.on_callback_query()
async def button(Jebot, update):
cb_data = update.data
if "help" in cb_data:
await update.message.delete()
await help(Jebot, update.message)
print(
"""
Bot Started!
Join @tvseriezzz_music
"""
)
Jebot.run()