-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
1167 lines (1091 loc) Β· 43.3 KB
/
play.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# AlvinMusicRobot (Telegram bot project)
# Copyright (C) 2021 Inukaasith
# Copyright (C) 2021 TheHamkerCat (Python_ARQ)
# 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 json
import os
from os import path
from typing import Callable
import aiofiles
import aiohttp
import ffmpeg
import requests
import wget
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from pyrogram import Client
from pyrogram import filters
from pyrogram.types import Voice
from pyrogram.errors import UserAlreadyParticipant
from pyrogram.types import InlineKeyboardButton
from pyrogram.types import InlineKeyboardMarkup
from pyrogram.types import Message
from Python_ARQ import ARQ
from youtube_search import YoutubeSearch
from AlvinMusicRobot.config import ARQ_API_KEY
from AlvinMusicRobot.config import BOT_NAME as bn
from AlvinMusicRobot.config import DURATION_LIMIT
from AlvinMusicRobot.config import UPDATES_CH
from AlvinMusicRobot.config import UPDATES_MODE
from AlvinMusicRobot.config import que
from AlvinMusicRobot.function.admins import admins as a
from AlvinMusicRobot.helpers.admins import get_administrators
from AlvinMusicRobot.helpers.channelmusic import get_chat_id
from AlvinMusicRobot.helpers.errors import DurationLimitError
from AlvinMusicRobot.helpers.decorators import errors
from AlvinMusicRobot.helpers.decorators import authorized_users_only
from AlvinMusicRobot.helpers.filters import command
from AlvinMusicRobot.helpers.filters import other_filters
from AlvinMusicRobot.helpers.gets import get_file_name
from AlvinMusicRobot.services.callsmusic import callsmusic
from AlvinMusicRobot.services.callsmusic import client as USER
from AlvinMusicRobot.services.converter.converter import convert
from AlvinMusicRobot.services.downloaders import youtube
from AlvinMusicRobot.services.queues import queues
aiohttpsession = aiohttp.ClientSession()
chat_id = None
arq = ARQ("https://thearq.tech", ARQ_API_KEY, aiohttpsession)
DISABLED_GROUPS = []
useer ="NaN"
def cb_admin_check(func: Callable) -> Callable:
async def decorator(client, cb):
admemes = a.get(cb.message.chat.id)
if cb.from_user.id in admemes:
return await func(client, cb)
else:
await cb.answer("anda tidak diizinkan!", show_alert=True)
return
return decorator
def transcode(filename):
ffmpeg.input(filename).output(
"input.raw",
format="s16le",
acodec="pcm_s16le",
ac=2,
ar="48k"
).overwrite_output().run()
os.remove(filename)
# Convert seconds to mm:ss
def convert_seconds(seconds):
seconds = seconds % (24 * 3600)
seconds %= 3600
minutes = seconds // 60
seconds %= 60
return "%02d:%02d" % (minutes, seconds)
# Convert hh:mm:ss to seconds
def time_to_seconds(time):
stringt = str(time)
return sum(int(x) * 60 ** i for i, x in enumerate(reversed(stringt.split(":"))))
# Change image size
def changeImageSize(maxWidth, maxHeight, image):
widthRatio = maxWidth / image.size[0]
heightRatio = maxHeight / image.size[1]
newWidth = int(widthRatio * image.size[0])
newHeight = int(heightRatio * image.size[1])
newImage = image.resize((newWidth, newHeight))
return newImage
async def generate_cover(requested_by, title, views, duration, thumbnail):
async with aiohttp.ClientSession() as session:
async with session.get(thumbnail) as resp:
if resp.status == 200:
f = await aiofiles.open("background.png", mode="wb")
await f.write(await resp.read())
await f.close()
image1 = Image.open("./background.png")
image2 = Image.open("./etc/foreground.png")
image3 = changeImageSize(1280, 720, image1)
image4 = changeImageSize(1280, 720, image2)
image5 = image3.convert("RGBA")
image6 = image4.convert("RGBA")
Image.alpha_composite(image5, image6).save("temp.png")
img = Image.open("temp.png")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("etc/font.otf", 32)
draw.text((205, 550), f"Title: {title}", (51, 215, 255), font=font)
draw.text((205, 590), f"Duration: {duration}", (255, 255, 255), font=font)
draw.text((205, 630), f"Views: {views}", (255, 255, 255), font=font)
draw.text(
(205, 670),
f"Added By: {requested_by}",
(255, 255, 255),
font=font,
)
img.save("final.png")
os.remove("temp.png")
os.remove("background.png")
@Client.on_message(filters.command("playlist") & filters.group & ~filters.edited)
async def playlist(client, message):
global que
if message.chat.id in DISABLED_GROUPS:
return
queue = que.get(message.chat.id)
if not queue:
await message.reply_text("Player is idle")
temp = []
for t in queue:
temp.append(t)
now_playing = temp[0][0]
by = temp[0][1].mention(style="md")
msg = "**Now Playing** in {}".format(message.chat.title)
msg += "\n- " + now_playing
msg += "\n- Req by " + by
temp.pop(0)
if temp:
msg += "\n\n"
msg += "**Queue**"
for song in temp:
name = song[0]
usr = song[1].mention(style="md")
msg += f"\n- {name}"
msg += f"\n- Req by {usr}\n"
await message.reply_text(msg)
# ============================= Settings =========================================
def updated_stats(chat, queue, vol=100):
if chat.id in callsmusic.active_chats:
# if chat.id in active_chats:
stats = "Settings of **{}**".format(chat.title)
if len(que) > 0:
stats += "\n\n"
stats += "Volume : {}%\n".format(vol)
stats += "lagu di queue : `{}`\n".format(len(que))
stats += "diputar sekarang : **{}**\n".format(queue[0][0])
stats += "Request oleh : {}".format(queue[0][1].mention)
else:
stats = None
return stats
def r_ply(type_):
if type_ == "play":
pass
else:
pass
mar = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("βΉ", "leave"),
InlineKeyboardButton("βΈ", "puse"),
InlineKeyboardButton("βΆοΈ", "resume"),
InlineKeyboardButton("β", "skip"),
],
[
InlineKeyboardButton("Playlist π", "playlist"),
],
[InlineKeyboardButton("β Close", "cls")],
]
)
return mar
@Client.on_message(filters.command("current") & filters.group & ~filters.edited)
async def ee(client, message):
if message.chat.id in DISABLED_GROUPS:
return
queue = que.get(message.chat.id)
stats = updated_stats(message.chat, queue)
if stats:
await message.reply(stats)
else:
await message.reply("tidak ada VC yang berjalan di obrolan")
@Client.on_message(filters.command("player") & filters.group & ~filters.edited)
@authorized_users_only
async def settings(client, message):
if message.chat.id in DISABLED_GROUPS:
await message.reply("pemutar musik dinonaktif")
return
playing = None
chat_id = get_chat_id(message.chat)
if chat_id in callsmusic.active_chats:
playing = True
queue = que.get(chat_id)
stats = updated_stats(message.chat, queue)
if stats:
if playing:
await message.reply(stats, reply_markup=r_ply("pause"))
else:
await message.reply(stats, reply_markup=r_ply("play"))
else:
await message.reply("tidak ada VC yang berjalan di obrolan")
@Client.on_message(
filters.command("musicplayer") & ~filters.edited & ~filters.bot & ~filters.private
)
@authorized_users_only
async def hfmm(_, message):
global DISABLED_GROUPS
try:
user_id = message.from_user.id
except:
return
if len(message.command) != 2:
await message.reply_text(
"saya hanya mengerti `/musicplayer on` and /musicplayer `off only`"
)
return
status = message.text.split(None, 1)[1]
message.chat.id
if status == "ON" or status == "on" or status == "On":
lel = await message.reply("`memuat...`")
if not message.chat.id in DISABLED_GROUPS:
await lel.edit("pemutar musik berhasil diaktifkan untuk pengguna daam obrolan")
return
DISABLED_GROUPS.remove(message.chat.id)
await lel.edit(
f"pemutar musik berhasil dinonaktif untuk pengguna dalam obrolan {message.chat.id}"
)
elif status == "OFF" or status == "off" or status == "Off":
lel = await message.reply("`memuat...`")
if message.chat.id in DISABLED_GROUPS:
await lel.edit("pemutar musik berhasil dinonaktif untuk pengguna dalam obrolan")
return
DISABLED_GROUPS.append(message.chat.id)
await lel.edit(
f"Pemutar Musik Berhasil Dinonaktifkan Untuk Pengguna Dalam Obrolan{message.chat.id}"
)
else:
await message.reply_text(
"saya hanya mengerti `/musicplayer on` and /musicplayer `off only`"
)
@Client.on_callback_query(filters.regex(pattern=r"^(playlist)$"))
async def p_cb(b, cb):
global que
que.get(cb.message.chat.id)
type_ = cb.matches[0].group(1)
cb.message.chat.id
cb.message.chat
cb.message.reply_markup.inline_keyboard[1][0].callback_data
if type_ == "playlist":
queue = que.get(cb.message.chat.id)
if not queue:
await cb.message.edit("Player is idle")
temp = []
for t in queue:
temp.append(t)
now_playing = temp[0][0]
by = temp[0][1].mention(style="md")
msg = "<b>Now Playing</b> in {}".format(cb.message.chat.title)
msg += "\n- " + now_playing
msg += "\n- Req by " + by
temp.pop(0)
if temp:
msg += "\n\n"
msg += "**Queue**"
for song in temp:
name = song[0]
usr = song[1].mention(style="md")
msg += f"\n- {name}"
msg += f"\n- Req by {usr}\n"
await cb.message.edit(msg)
@Client.on_callback_query(
filters.regex(pattern=r"^(play|pause|skip|leave|puse|resume|menu|cls)$")
)
@cb_admin_check
async def m_cb(b, cb):
global que
if (
cb.message.chat.title.startswith("Channel Music: ")
and chat.title[14:].isnumeric()
):
chet_id = int(chat.title[13:])
else:
chet_id = cb.message.chat.id
qeue = que.get(chet_id)
type_ = cb.matches[0].group(1)
cb.message.chat.id
m_chat = cb.message.chat
the_data = cb.message.reply_markup.inline_keyboard[1][0].callback_data
if type_ == "pause":
if (chet_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chet_id] == "paused"
):
await cb.answer("Chat tidak terhubung!", show_alert=True)
else:
callsmusic.pause(chet_id)
await cb.answer("Musik dijeda!")
await cb.message.edit(
updated_stats(m_chat, qeue), reply_markup=r_ply("play")
)
elif type_ == "play":
if (chet_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chet_id] == "playing"
):
await cb.answer("Chat tidak terhubung!", show_alert=True)
else:
callsmusic.resume(chet_id)
await cb.answer("Musik diputar!")
await cb.message.edit(
updated_stats(m_chat, qeue), reply_markup=r_ply("pause")
)
elif type_ == "playlist":
queue = que.get(cb.message.chat.id)
if not queue:
await cb.message.edit("Player is idle")
temp = []
for t in queue:
temp.append(t)
now_playing = temp[0][0]
by = temp[0][1].mention(style="md")
msg = "**Now Playing** in {}".format(cb.message.chat.title)
msg += "\n- " + now_playing
msg += "\n- Req by " + by
temp.pop(0)
if temp:
msg += "\n\n"
msg += "**Queue**"
for song in temp:
name = song[0]
usr = song[1].mention(style="md")
msg += f"\n- {name}"
msg += f"\n- Req by {usr}\n"
await cb.message.edit(msg)
elif type_ == "resume":
if (chet_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chet_id] == "playing"
):
await cb.answer("Chat tidak terhubung atau sedang memutar", show_alert=True)
else:
callsmusic.resume(chet_id)
await cb.answer("Musik diputar!")
elif type_ == "puse":
if (chet_id not in callsmusic.active_chats) or (
callsmusic.active_chats[chet_id] == "paused"
):
await cb.answer("Chat tidak terhubun atau musik dijeda", show_alert=True)
else:
callsmusic.pause(chet_id)
await cb.answer("Musik dijeda!")
elif type_ == "cls":
await cb.answer("mengeluarkan menu")
await cb.message.delete()
elif type_ == "menu":
stats = updated_stats(cb.message.chat, qeue)
await cb.answer("Menu opened")
marr = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("βΉ", "leave"),
InlineKeyboardButton("βΈ", "puse"),
InlineKeyboardButton("βΆοΈ", "resume"),
InlineKeyboardButton("β", "skip"),
],
[
InlineKeyboardButton("Playlist π", "playlist"),
],
[InlineKeyboardButton("β Close", "cls")],
]
)
await cb.message.edit(stats, reply_markup=marr)
elif type_ == "skip":
if qeue:
qeue.pop(0)
if chet_id not in callsmusic.active_chats:
await cb.answer("Chat tidak terhubung!", show_alert=True)
else:
queues.task_done(chet_id)
if queues.is_empty(chet_id):
callsmusic.stop(chet_id)
await cb.message.edit("- tidak ada lagi daftar putar..\n- Leaving VC!")
else:
await callsmusic.set_stream(
chet_id, queues.get(chet_id)["file"]
)
await cb.answer.reply_text("β
<b>Skipped</b>")
await cb.message.edit((m_chat, qeue), reply_markup=r_ply(the_data))
await cb.message.reply_text(
f"- Skipped track\n- Now Playing **{qeue[0][0]}**"
)
else:
if chet_id in callsmusic.active_chats:
try:
queues.clear(chet_id)
except QueueEmpty:
pass
await callsmusic.stop(chet_id)
await cb.message.edit("Successfully Left the Chat!")
else:
await cb.answer("Chat is not connected!", show_alert=True)
@Client.on_message(command("play") & other_filters)
async def play(_, message: Message):
global que
global useer
if message.chat.id in DISABLED_GROUPS:
return
lel = await message.reply("π <b>Processing</b>")
administrators = await get_administrators(message.chat)
chid = message.chat.id
try:
user = await USER.get_me()
except:
user.first_name = "helper"
usar = user
wew = usar.id
try:
# chatdetails = await USER.get_chat(chid)
await _.get_chat_member(chid, wew)
except:
for administrator in administrators:
if administrator == message.from_user.id:
if message.chat.title.startswith("Channel Music: "):
await lel.edit(
"<b>ingat untuk menambahkan helper di channel</b>",
)
pass
try:
invitelink = await _.export_chat_invite_link(chid)
except:
await lel.edit(
"<b>Tambahkan saya sebagai admin grup Anda terlebih dahulu</b>",
)
return
try:
await USER.join_chat(invitelink)
await USER.send_message(
message.chat.id, "Saya bergabung dengan grup ini untuk memutar musik di VC"
)
await lel.edit(
"<b>helper userbot bergabung dengan obrolan Anda</b>",
)
except UserAlreadyParticipant:
pass
except Exception:
# print(e)
await lel.edit(
f"<b>π΄ Flood Wait Error π΄ \npengguna {user.first_name} tidak dapat bergabung dengan grup Anda karena permintaan yang banyak untuk bot pengguna! Pastikan pengguna tidak dibanned dalam grup."
f"\n\ntau tambahkan @{ASSISTANT_NAME} secara manual ke Grup Anda dan coba lagi</b>",
)
try:
await USER.get_chat(chid)
# lmoa = await client.get_chat_member(chid,wew)
except:
await lel.edit(
f"<i> {user.first_name} Userbot tidak ada dalam obrolan ini, Minta admin untuk mengirim / memutar perintah untuk pertama kalinya atau menambahkan asisten secara manual</i>"
)
return
text_links=None
await lel.edit("π <b>Finding</b>")
if message.reply_to_message:
if message.reply_to_message.audio:
pass
entities = []
toxt = message.reply_to_message.text \
or message.reply_to_message.caption
if message.reply_to_message.entities:
entities = message.reply_to_message.entities + entities
elif message.reply_to_message.caption_entities:
entities = message.reply_to_message.entities + entities
urls = [entity for entity in entities if entity.type == 'url']
text_links = [
entity for entity in entities if entity.type == 'text_link'
]
else:
urls=None
if text_links:
urls = True
user_id = message.from_user.id
user_name = message.from_user.first_name
rpk = "[" + user_name + "](tg://user?id=" + str(user_id) + ")"
audio = (
(message.reply_to_message.audio or message.reply_to_message.voice)
if message.reply_to_message
else None
)
if audio:
if round(audio.duration / 60) > DURATION_LIMIT:
await lel.edit(
f"β Video lebih lama {DURATION_LIMIT} menit tidak diizinkan untuk bermain!"
)
return
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("π Playlist", callback_data="playlist"),
InlineKeyboardButton("Menu β― ", callback_data="menu"),
],
[InlineKeyboardButton(text="β Close", callback_data="cls")],
]
)
file_name = get_file_name(audio)
title = file_name
thumb_name = "https://telegra.ph/file/d19b68d228e2dc46eb8f5.jpg"
thumbnail = thumb_name
duration = round(audio.duration / 60)
views = "Locally added"
requested_by = message.from_user.first_name
await generate_cover(requested_by, title, views, duration, thumbnail)
file_path = await convert(
(await message.reply_to_message.download(file_name))
if not path.isfile(path.join("downloads", file_name))
else file_name
)
elif urls:
query = toxt
await lel.edit("π΅ <b>Processing</b>")
ydl_opts = {"format": "bestaudio/best"}
try:
results = YoutubeSearch(query, max_results=1).to_dict()
url = f"https://youtube.com{results[0]['url_suffix']}"
# print(results)
title = results[0]["title"][:40]
thumbnail = results[0]["thumbnails"][0]
thumb_name = f"thumb{title}.jpg"
thumb = requests.get(thumbnail, allow_redirects=True)
open(thumb_name, "wb").write(thumb.content)
duration = results[0]["duration"]
results[0]["url_suffix"]
views = results[0]["views"]
except Exception as e:
await lel.edit(
"Song tidak ditemukan.Coba lagu lain atau mungkin mengejanya dengan benar."
)
print(str(e))
return
try:
secmul, dur, dur_arr = 1, 0, duration.split(':')
for i in range(len(dur_arr)-1, -1, -1):
dur += (int(dur_arr[i]) * secmul)
secmul *= 60
if (dur / 60) > DURATION_LIMIT:
await lel.edit(f"β Video lebih lama {DURATION_LIMIT} menit tidak diizinkan untuk bermain!")
return
except:
pass
dlurl=url
dlurl=dlurl.replace("youtube","youtubepp")
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("π Playlist", callback_data="playlist"),
InlineKeyboardButton("Menu β― ", callback_data="menu"),
],
[
InlineKeyboardButton(text="π¬ YouTube", url=f"{url}"),
InlineKeyboardButton(text="Download π₯", url=f"{dlurl}"),
],
[InlineKeyboardButton(text="β Close", callback_data="cls")],
]
)
requested_by = message.from_user.first_name
await generate_cover(requested_by, title, views, duration, thumbnail)
file_path = await convert(youtube.download(url))
else:
query = ""
for i in message.command[1:]:
query += " " + str(i)
print(query)
await lel.edit("π΅ **Processing**")
ydl_opts = {"format": "bestaudio/best"}
try:
results = YoutubeSearch(query, max_results=5).to_dict()
except:
await lel.edit("berikan saya sesuatu untuk memutar")
# Looks like hell. Aren't it?? FUCK OFF
try:
toxxt = "**pilih lagu yang ingin anda putar**\n\n"
j = 0
useer=user_name
emojilist = ["1οΈβ£","2οΈβ£","3οΈβ£","4οΈβ£","5οΈβ£",]
while j < 5:
toxxt += f"{emojilist[j]} <b>Title - [{results[j]['title']}](https://youtube.com{results[j]['url_suffix']})</b>\n"
toxxt += f" β <b>Duration</b> - {results[j]['duration']}\n"
toxxt += f" β <b>Views</b> - {results[j]['views']}\n"
toxxt += f" β <b>Channel</b> - {results[j]['channel']}\n\n"
j += 1
koyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("1οΈβ£", callback_data=f'plll 0|{query}|{user_id}'),
InlineKeyboardButton("2οΈβ£", callback_data=f'plll 1|{query}|{user_id}'),
InlineKeyboardButton("3οΈβ£", callback_data=f'plll 2|{query}|{user_id}'),
],
[
InlineKeyboardButton("4οΈβ£", callback_data=f'plll 3|{query}|{user_id}'),
InlineKeyboardButton("5οΈβ£", callback_data=f'plll 4|{query}|{user_id}'),
],
[InlineKeyboardButton(text="β", callback_data="cls")],
]
)
await lel.edit(toxxt,reply_markup=koyboard,disable_web_page_preview=True)
# WHY PEOPLE ALWAYS LOVE PORN ?? (A point to think)
return
# Returning to pornhub
except:
await lel.edit("Tidak ada hasil yang cukup untuk dipilih.. Mulai pemutar langsung..")
# print(results)
try:
url = f"https://youtube.com{results[0]['url_suffix']}"
title = results[0]["title"][:40]
thumbnail = results[0]["thumbnails"][0]
thumb_name = f"thumb{title}.jpg"
thumb = requests.get(thumbnail, allow_redirects=True)
open(thumb_name, "wb").write(thumb.content)
duration = results[0]["duration"]
results[0]["url_suffix"]
views = results[0]["views"]
except Exception as e:
await lel.edit(
"Song tidak ditemukan.Coba lagu lain atau mungkin mengejanya dengan benar."
)
print(str(e))
return
try:
secmul, dur, dur_arr = 1, 0, duration.split(':')
for i in range(len(dur_arr)-1, -1, -1):
dur += (int(dur_arr[i]) * secmul)
secmul *= 60
if (dur / 60) > DURATION_LIMIT:
await lel.edit(f"β Video lebih lama dari {DURATION_LIMIT} menit tidak diizinkan untuk bermain!")
return
except:
pass
dlurl=url
dlurl=dlurl.replace("youtube","youtubepp")
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("π Playlist", callback_data="playlist"),
InlineKeyboardButton("Menu β― ", callback_data="menu"),
],
[
InlineKeyboardButton(text="π¬ YouTube", url=f"{url}"),
InlineKeyboardButton(text="Download π₯", url=f"{dlurl}"),
],
[InlineKeyboardButton(text="β Close", callback_data="cls")],
]
)
requested_by = message.from_user.first_name
await generate_cover(requested_by, title, views, duration, thumbnail)
file_path = await convert(youtube.download(url))
chat_id = get_chat_id(message.chat)
if chat_id in callsmusic.active_chats:
position = await queues.put(chat_id, file=file_path)
qeue = que.get(chat_id)
s_name = title
r_by = message.from_user
loc = file_path
appendable = [s_name, r_by, loc]
qeue.append(appendable)
await message.reply_photo(
photo="final.png",
caption=f"#β£ lagu request anda <b>queued</b> di posisi {position}!",
reply_markup=keyboard,
)
os.remove("final.png")
return await lel.delete()
else:
chat_id = get_chat_id(message.chat)
que[chat_id] = []
qeue = que.get(chat_id)
s_name = title
r_by = message.from_user
loc = file_path
appendable = [s_name, r_by, loc]
qeue.append(appendable)
try:
await callsmusic.set_stream(chat_id, file_path)
except:
message.reply("Group Call tidak terhubung atau saya tidak dapat bergabung")
return
await message.reply_photo(
photo="final.png",
reply_markup=keyboard,
caption="βΆοΈ <b>Playing</b> lagu yang di request oleh {} via Youtube Music π".format(
message.from_user.mention()
),
)
os.remove("final.png")
return await lel.delete()
@Client.on_message(filters.command("ytplay") & filters.group & ~filters.edited)
async def ytplay(_, message: Message):
global que
if message.chat.id in DISABLED_GROUPS:
return
lel = await message.reply("π <b>Processing</b>")
administrators = await get_administrators(message.chat)
chid = message.chat.id
try:
user = await USER.get_me()
except:
user.first_name = "helper"
usar = user
wew = usar.id
try:
# chatdetails = await USER.get_chat(chid)
await _.get_chat_member(chid, wew)
except:
for administrator in administrators:
if administrator == message.from_user.id:
if message.chat.title.startswith("Channel Music: "):
await lel.edit(
"<b>ingat untuk menambahkan helper kedalam channel</b>",
)
pass
try:
invitelink = await _.export_chat_invite_link(chid)
except:
await lel.edit(
"<b>Tambahkan saya sebagai admin grup Anda terlebih dahulu</b>",
)
return
try:
await USER.join_chat(invitelink)
await USER.send_message(
message.chat.id, "Saya bergabung dengan grup ini untuk memutar musik di VC"
)
await lel.edit(
"<b>helper userbot bergabung dengan obrolan Anda</b>",
)
except UserAlreadyParticipant:
pass
except Exception:
# print(e)
await lel.edit(
f"<b>π΄ Flood Wait Error π΄ \npengguna {user.first_name} tidak dapat bergabung dengan grup Anda karena permintaan yang banyak untuk bot pengguna! Pastikan pengguna tidak dibanned dalam grup."
f"\n\nAtau tambahkan @{ASSISTANT_NAME} secara manual ke Grup Anda dan coba lagi</b>",
)
try:
await USER.get_chat(chid)
# lmoa = await client.get_chat_member(chid,wew)
except:
await lel.edit(
f"<i> {user.first_name} Userbot tidak ada dalam obrolan ini, Minta admin untuk mengirim /play perintah untuk pertama kalinya atau menambahkan asisten secara manual</i>"
)
return
await lel.edit("π <b>Finding</b>")
user_id = message.from_user.id
user_name = message.from_user.first_name
query = ""
for i in message.command[1:]:
query += " " + str(i)
print(query)
await lel.edit("π΅ <b>Processing</b>")
ydl_opts = {"format": "bestaudio/best"}
try:
results = YoutubeSearch(query, max_results=1).to_dict()
url = f"https://youtube.com{results[0]['url_suffix']}"
# print(results)
title = results[0]["title"][:40]
thumbnail = results[0]["thumbnails"][0]
thumb_name = f"thumb{title}.jpg"
thumb = requests.get(thumbnail, allow_redirects=True)
open(thumb_name, "wb").write(thumb.content)
duration = results[0]["duration"]
results[0]["url_suffix"]
views = results[0]["views"]
except Exception as e:
await lel.edit(
"lagu tidak ditemukan.Coba lagu lain atau mungkin mengejanya dengan benar."
)
print(str(e))
return
try:
secmul, dur, dur_arr = 1, 0, duration.split(':')
for i in range(len(dur_arr)-1, -1, -1):
dur += (int(dur_arr[i]) * secmul)
secmul *= 60
if (dur / 60) > DURATION_LIMIT:
await lel.edit(f"β Video lebih lama dari {DURATION_LIMIT} menit tidak diizinkan untuk bermain!")
return
except:
pass
dlurl=url
dlurl=dlurl.replace("youtube","youtubepp")
keyboard = InlineKeyboardMarkup(
[
[
InlineKeyboardButton("π Playlist", callback_data="playlist"),
InlineKeyboardButton("Menu β― ", callback_data="menu"),
],
[
InlineKeyboardButton(text="π¬ YouTube", url=f"{url}"),
InlineKeyboardButton(text="Download π₯", url=f"{dlurl}"),
],
[InlineKeyboardButton(text="β Close", callback_data="cls")],
]
)
requested_by = message.from_user.first_name
await generate_cover(requested_by, title, views, duration, thumbnail)
file_path = await convert(youtube.download(url))
chat_id = get_chat_id(message.chat)
if chat_id in callsmusic.active_chats:
position = await queues.put(chat_id, file=file_path)
qeue = que.get(chat_id)
s_name = title
r_by = message.from_user
loc = file_path
appendable = [s_name, r_by, loc]
qeue.append(appendable)
await message.reply_photo(
photo="final.png",
caption=f"#β£ lagu yang anda request <b>queued</b> di posisi {position}!",
reply_markup=keyboard,
)
os.remove("final.png")
return await lel.delete()
else:
chat_id = get_chat_id(message.chat)
que[chat_id] = []
qeue = que.get(chat_id)
s_name = title
r_by = message.from_user
loc = file_path
appendable = [s_name, r_by, loc]
qeue.append(appendable)
try:
await callsmusic.set_stream(chat_id, file_path)
except:
message.reply("Group Call tidak terhubung karena saya tidak dapat bergabung")
return
await message.reply_photo(
photo="final.png",
reply_markup=keyboard,
caption="βΆοΈ <b>Playing</b> lagu yang di request oleh {} via Youtube Music π".format(
message.from_user.mention()
),
)
os.remove("final.png")
return await lel.delete()
@Client.on_message(filters.command("splay") & filters.group & ~filters.edited)
async def jiosaavn(client: Client, message_: Message):
global que
if message_.chat.id in DISABLED_GROUPS:
return
lel = await message_.reply("π <b>Processing</b>")
administrators = await get_administrators(message_.chat)
chid = message_.chat.id
try:
user = await USER.get_me()
except:
user.first_name = "AlvinMusicRobot"
usar = user
wew = usar.id
try:
# chatdetails = await USER.get_chat(chid)
await client.get_chat_member(chid, wew)
except:
for administrator in administrators:
if administrator == message_.from_user.id:
if message_.chat.title.startswith("Channel Music: "):
await lel.edit(
"<b>ingat untuk menambahkan helper ke channel anda</b>",
)
pass
try:
invitelink = await client.export_chat_invite_link(chid)
except:
await lel.edit(
"<b>Tambahkan saya sebagai admin grup Anda terlebih dahulu</b>",
)
return
try:
await USER.join_chat(invitelink)
await USER.send_message(
message_.chat.id, "Saya bergabung dengan grup ini untuk memutar musik di VC"
)
await lel.edit(
"<b>helper userbot bergabung ke obrolan anda</b>",
)
except UserAlreadyParticipant:
pass
except Exception:
# print(e)
await lel.edit(
f"<b>π΄ Flood Wait Error π΄ \npengguna {user.first_name} tidak dapat bergabung dengan grup Anda karena permintaan yang banyak untuk bot pengguna! Pastikan pengguna tidak dibanned dalam grup."
f"\n\nAtau tambahkan @{ASSISTANT_NAME} secara manual ke Grup Anda dan coba lagi</b>",
)
try:
await USER.get_chat(chid)
# lmoa = await client.get_chat_member(chid,wew)
except:
await lel.edit(
"<i> helper Userbot tidak ada dalam obrolan ini, Minta admin untuk mengirim /play perintah untuk pertama kalinya atau menambahkan asisten secara manua</i>"
)
return
requested_by = message_.from_user.first_name
chat_id = message_.chat.id
text = message_.text.split(" ", 1)
query = text[1]
res = lel
await res.edit(f"mencari π untuk `{query}` di jio saavn")
try:
songs = await arq.saavn(query)
if not songs.ok:
await message_.reply_text(songs.result)
return
sname = songs.result[0].song
slink = songs.result[0].media_url
ssingers = songs.result[0].singers
sthumb = songs.result[0].image
sduration = int(songs.result[0].duration)
except Exception as e:
await res.edit("Found Literally Nothing!, You Should Work On Your English.")
print(str(e))
return
try:
duuration= round(sduration / 60)
if duuration > DURATION_LIMIT:
await cb.message.edit(f"Musik lebih lama dari {DURATION_LIMIT}menit tidak diperbolehkan bermain")