Skip to content

Commit

Permalink
upgrading pytgcalls (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kshubham506 authored Jul 21, 2021
1 parent d2ff0fe commit 6eb3b23
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
26 changes: 10 additions & 16 deletions callmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pyrogram.errors.exceptions import BotMethodInvalid
from pyrogram.errors.exceptions.bad_request_400 import ChannelInvalid, ChannelPrivate, InviteHashExpired, PeerIdInvalid, UserAlreadyParticipant
from pyrogram.errors.exceptions.flood_420 import FloodWait
from pytgcalls import GroupCall
from pytgcalls import GroupCallFactory
import time
import os
from asyncio import QueueEmpty
Expand Down Expand Up @@ -35,11 +35,12 @@ def __call__(cls, *args, **kwargs):

class GoupCallInstance(object):
def __init__(self, chat_id, mongo_doc, client=None):
self.client = client
self.client = user_app
self.bot_client = client
self.mongo_doc = mongo_doc
self.chat_id = chat_id
self.pytgcalls = GroupCall(self.client)
self.pytgcalls = GroupCallFactory(
self.client, GroupCallFactory.MTPROTO_CLIENT_TYPE.PYROGRAM).get_file_group_call()
self.active = False
self.status = None
self.songs = []
Expand All @@ -53,9 +54,9 @@ def __init__(self, chat_id, mongo_doc, client=None):
f"{self.chat_id}=>{msg}", send)

@self.pytgcalls.on_playout_ended
async def on_stream_end(gc: GroupCall, *args) -> None:
async def on_stream_end(context, *args) -> None:
try:
chat_id = gc.full_chat.id
chat_id = context.full_chat.id
logInfo(
f"Playout ended, skipping to next song, current file which ended : {args}")
self.currentRepeatCount = self.currentRepeatCount + 1
Expand All @@ -69,10 +70,10 @@ async def on_stream_end(gc: GroupCall, *args) -> None:
logException(f"Error in on_stream_end: {ex}", True)

@self.pytgcalls.on_network_status_changed
async def on_network_changed(gc: GroupCall, is_connected: bool):
async def on_network_changed(context, is_connected: bool):
try:
logInfo(f"changing status to : {is_connected}")
chat_id = gc.full_chat.id
chat_id = context.full_chat.id
if is_connected is True:
self.active = True
self.status = "playing"
Expand All @@ -82,17 +83,8 @@ async def on_network_changed(gc: GroupCall, is_connected: bool):
except Exception as ex:
logException(f"Error in on_network_changed : {ex}", True)

async def changeClient(self, client):
try:
self.logInfo(f"Changed client : {client}")
self.client = client
self.pytgcalls.client = client
except Exception as ex:
logException(f"Changing client error : {ex}")

async def changeFile(self, fileName, songInfo, requester, oldFileName=None):
try:
self.logInfo(f"Changed file to : {fileName}")
self.currentRepeatCount = 0
self.playingFile = fileName
self.pytgcalls.input_filename = fileName
Expand All @@ -105,8 +97,10 @@ async def changeFile(self, fileName, songInfo, requester, oldFileName=None):
if MongoDBClient.client is not None:
MongoDBClient.add_song_playbacks(
songInfo, requester, self.mongo_doc['_id'])
self.logInfo(f"Changed file to : {fileName}")
except Exception as ex:
logException(f"Error in changeFile : {ex}", True)
raise Exception(ex)

def is_connected(self):
return self.pytgcalls.is_connected
Expand Down
3 changes: 2 additions & 1 deletion modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import callmanager
from helpers.decorators import chat_allowed, admin_check, delayDelete
from helpers.decorators import chat_allowed, admin_check, database_check, delayDelete
from helpers.fromatMessages import getMessage
from utils.Logger import *
from utils.Config import Config
Expand All @@ -11,6 +11,7 @@


@Client.on_message(filters.command(['info', 'info@vcplayerbot']) & ~filters.edited & ~filters.bot)
@database_check
@chat_allowed
@admin_check
async def info(client, message, current_client):
Expand Down
3 changes: 1 addition & 2 deletions modules/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async def play(client, message, current_client):
song_info['title'], song_info['thumbnails'][-1], cover_file_name)

# download and process the song
sent_msg = await sent_msg.edit(f"**__ ⏱ Beep... Bop... Processing __**")
sent_msg = await sent_msg.edit(f"**__ ⏱ Beep... Bop... Processing [May Take 30-40 sec]__**")
filename = await DownloaderService.download_and_transcode_song(f"{song_info['link']}")
if filename is None:
m = await sent_msg.edit(f"**__✖️ Critical Error while post procesing, Try again! __**")
Expand All @@ -131,7 +131,6 @@ async def play(client, message, current_client):
# direct play
await pytgcalls_instance.changeFile(
filename, song_info, requested_by)
await pytgcalls_instance.changeClient(callmanager.user_app)

response = await pytgcalls_instance.start_playback(filename, song_info, requested_by)
if response is not True:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ pillow
aiofiles
aiohttp
schedule
pytgcalls
pytgcalls[pyrogram]
1 change: 1 addition & 0 deletions unknown_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
2021-06-04 22:43:58.516391 [400 GROUPCALL_INVALID] phone.LeaveGroupCall
2021-06-04 22:52:56.657251 [403 GROUPCALL_FORBIDDEN] phone.EditGroupCallTitle
2021-06-04 22:53:37.388114 [400 GROUPCALL_INVALID] phone.LeaveGroupCall
2021-07-22 00:52:39.094831 [403 GROUPCALL_FORBIDDEN] phone.LeaveGroupCall

0 comments on commit 6eb3b23

Please sign in to comment.