forked from AsmSafone/VideoPlayerBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.py
More file actions
251 lines (227 loc) · 9.88 KB
/
Copy pathcontrols.py
File metadata and controls
251 lines (227 loc) · 9.88 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
"""
VideoPlayerBot, Telegram Video Chat Bot
Copyright (c) 2021 Asm Safone <https://github.com/AsmSafone>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
import asyncio
from config import Config
from helpers.log import LOGGER
from pyrogram.types import Message
from pyrogram import Client, filters
from helpers.utils import delete, get_playlist_str, is_admin, mute, restart_playout, skip, pause, resume, unmute, volume, get_buttons, is_admin, seek_file, get_player_string
admin_filter=filters.create(is_admin)
@Client.on_message(filters.command(["playlist", f"playlist@{Config.BOT_USERNAME}"]) & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def c_playlist(client, message):
pl = await get_playlist_str()
if message.chat.type == "private":
await message.reply_text(
pl,
disable_web_page_preview=True,
)
else:
if Config.msg.get('playlist') is not None:
try:
await Config.msg['playlist'].delete()
except:
pass
Config.msg['playlist'] = await message.reply_text(
pl,
disable_web_page_preview=True,
)
await delete(message)
@Client.on_message(filters.command(["skip", f"skip@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def skip_track(_, m: Message):
if not Config.playlist:
k=await m.reply_text("⛔️ **Empty Playlist !**")
await delete(k)
return
if len(m.command) == 1:
await skip()
await delete(m)
else:
try:
items = list(dict.fromkeys(m.command[1:]))
items = [int(x) for x in items if x.isdigit()]
items.sort(reverse=True)
for i in items:
if 2 <= i <= (len(Config.playlist) - 1):
Config.playlist.pop(i)
k=await m.reply_text(f"⏭ **Succesfully Skipped !** \n{i}. **{Config.playlist[i][1]}**")
await delete(k)
else:
k=await m.reply_text(f"⛔️ **Can't Skip First Two Video - {i} !**")
await delete(k)
except (ValueError, TypeError):
k=await m.reply_text("⛔️ **Invalid Input !**")
await delete(k)
pl=await get_playlist_str()
if m.chat.type == "private":
await m.reply_photo(photo=Config.THUMB_LINK, caption=pl, reply_markup=await get_buttons())
elif not Config.LOG_GROUP and m.chat.type == "supergroup":
await m.reply_photo(photo=Config.THUMB_LINK, caption=pl, reply_markup=await get_buttons())
@Client.on_message(filters.command(["pause", f"pause@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def pause_playing(_, m: Message):
if Config.PAUSE:
k=await m.reply_text("⏸ **Already Paused !**")
await delete(k)
return
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
await pause()
k=await m.reply_text("⏸ **Paused Streaming !**")
await delete(k)
@Client.on_message(filters.command(["resume", f"resume@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def resume_playing(_, m: Message):
if not Config.PAUSE:
k=await m.reply_text("▶️ **Already Playing !**")
await delete(k)
return
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
await resume()
k=await m.reply_text("▶️ **Resumed Streaming !**")
await delete(k)
@Client.on_message(filters.command(["volume", f"volume@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def set_vol(_, m: Message):
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
if len(m.command) < 2:
k=await m.reply_text("🤖 **Please Pass Volume (0-200) !**")
await delete(k)
return
await volume(int(m.command[1]))
k=await m.reply_text(f"🔉 **Volume Set To {m.command[1]} !**")
await delete(k)
@Client.on_message(filters.command(["replay", f"replay@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def replay_playout(client, m: Message):
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
await restart_playout()
k=await m.reply_text("🔂 **Replaying Stream !**")
await delete(k)
@Client.on_message(filters.command(["mute", f"mute@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def set_mute(_, m: Message):
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
if Config.MUTED:
k=await m.reply_text("🔇 **Already Muted !**")
await delete(k)
return
k=await mute()
if k:
s=await m.reply_text(f"🔇 **Succesfully Muted !**")
await delete(s)
else:
s=await m.reply_text("🔇 **Already Muted !**")
await delete(s)
@Client.on_message(filters.command(["unmute", f"unmute@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def set_unmute(_, m: Message):
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
if not Config.MUTED:
k=await m.reply_text("🔊 **Already Unmuted !**")
await delete(k)
return
k=await unmute()
if k:
s=await m.reply_text(f"🔊 **Succesfully Unmuted !**")
await delete(s)
else:
s=await m.reply_text("🔊 **Already Unmuted !**")
await delete(s)
@Client.on_message(filters.command(["current", f"current@{Config.BOT_USERNAME}"]) & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def show_current(client, m: Message):
data=Config.DATA.get('FILE_DATA')
if not data.get('dur', 0) or \
data.get('dur') == 0:
title="▶️ <b>Streaming [Live Stream](https://t.me/AsmSafone) !</b>"
else:
if Config.playlist:
title=f"▶️ <b>{Config.playlist[0][1]}</b>"
elif Config.STREAM_LINK:
title=f"▶️ <b>Streaming [Stream Link]({data['file']}) !</b>"
else:
title=f"▶️ <b>Streaming [Startup Stream]({Config.STREAM_URL}) !</b>"
if m.chat.type == "private":
await m.reply_photo(
photo=Config.THUMB_LINK,
caption=title,
reply_markup=await get_buttons()
)
else:
if Config.msg.get('current') is not None:
try:
await Config.msg['current'].delete()
except:
pass
Config.msg['current'] = await m.reply_photo(
photo=Config.THUMB_LINK,
caption=title,
reply_markup=await get_buttons()
)
await delete(m)
@Client.on_message(filters.command(["seek", f"seek@{Config.BOT_USERNAME}"]) & admin_filter & (filters.chat(Config.CHAT_ID) | filters.private | filters.chat(Config.LOG_GROUP)))
async def seek_playout(client, m: Message):
if not Config.CALL_STATUS:
k=await m.reply_text("🤖 **Didn't Joined Video Chat !**")
await delete(k)
return
if not (Config.playlist or Config.STREAM_LINK):
k=await m.reply_text("⚠️ **Startup Stream Can't Be Seeked !**")
await delete(k)
return
data=Config.DATA.get('FILE_DATA')
if not data.get('dur', 0) or \
data.get('dur') == 0:
k=await m.reply_text("⚠️ **This Stream Can't Be Seeked !**")
await delete(k)
return
if ' ' in m.text:
i, time = m.text.split(" ")
try:
time=int(time)
except:
k=await m.reply_text("⛔️ **Invalid Time Specified !**")
await delete(k)
return
k, string=await seek_file(time)
if k == False:
s=await m.reply_text(f"**{string}**")
await delete(s)
return
if not data.get('dur', 0) or \
data.get('dur') == 0:
title="▶️ <b>Streaming [Live Stream](https://t.me/AsmSafone) !</b>"
else:
if Config.playlist:
title=f"▶️ <b>{Config.playlist[0][1]}</b>"
elif Config.STREAM_LINK:
title=f"▶️ <b>Streaming [Stream Link]({data['file']}) !</b>"
else:
title=f"▶️ <b>Streaming [Startup Stream]({Config.STREAM_URL}) !</b>"
s=await m.reply_text(f"{title}", reply_markup=await get_buttons(), disable_web_page_preview=True)
await delete(s)
else:
s=await m.reply_text("❗ **You Should Specify The Time In Second To Seek!** \n\nFor Example: \n• `/seek 10` to foward 10 sec. \n• `/seek -10` to rewind 10 sec.")
await delete(s)