async def startCall(self): if VIDEO_ON: for chats in VIDEO_ON: await VIDEO_ON[chats].stop() VIDEO_ON.clear() await asyncio.sleep(3) if self._video: for chats in list(CLIENTS): if chats != self._chat: await CLIENTS[chats].stop() del CLIENTS[chats] VIDEO_ON.update({self._chat: self.group_call}) if self._chat not in ACTIVE_CALLS: try: self.group_call.on_network_status_changed( self.on_network_changed) self.group_call.on_playout_ended(self.playout_ended_handler) await self.group_call.join(self._chat) except GroupCallNotFoundError as er: LOGS.info(er) dn, err = await self.make_vc_active() if err: return False, err except Exception as e: LOGS.exception(e) return False, e return True, None
def get_string(key: str) -> Any: lang = language[0] try: return languages[lang][key] except KeyError: try: en_ = languages["en"][key] if not Trs: return en_ tr = Trs.translate(en_, lang_tgt=lang).replace("\ N", "\n") if en_.count("{}") != tr.count("{}"): tr = en_ if languages.get(lang): languages[lang][key] = tr else: languages.update({lang: {key: tr}}) return tr except KeyError: return f"Warning: could not load any string with the key `{key}`" except TypeError: pass except Exception as er: LOGS.exception(er) return languages["en"].get( key) or f"Failed to load language string '{key}'"
async def make_vc_active(self): try: await vcClient( functions.phone.CreateGroupCallRequest( self._chat, title="ЪјД Ultroid Music ЪјХ")) except Exception as e: LOGS.exception(e) return False, e return True, None
async def play_from_queue(self): chat_id = self._chat if chat_id in VIDEO_ON: await self.group_call.stop_video() VIDEO_ON.pop(chat_id) try: song, title, link, thumb, from_user, pos, dur = await get_from_queue( chat_id) try: await self.group_call.start_audio(song) except ParticipantJoinMissingError: await self.vc_joiner() await self.group_call.start_audio(song) if MSGID_CACHE.get(chat_id): await MSGID_CACHE[chat_id].delete() del MSGID_CACHE[chat_id] text = "<strong>ЪјД Now playing #{}: <a href={}>{}</a>\nРЈ░ Duration:</strong> <code>{}</code>\nЪЉц <strong>Requested by:</strong> {}".format( pos, link, title, dur, from_user) try: xx = await vcClient.send_message( self._current_chat, "<strong>ЪјД Now playing #{}: <a href={}>{}</a>\nРЈ░ Duration:</strong> <code>{}</code>\nЪЉц <strong>Requested by:</strong> {}" .format(pos, link, title, dur, from_user), file=thumb, link_preview=False, parse_mode="html", ) except ChatSendMediaForbiddenError: xx = await vcClient.send_message(self._current_chat, text, link_preview=False, parse_mode="html") MSGID_CACHE.update({chat_id: xx}) VC_QUEUE[chat_id].pop(pos) if not VC_QUEUE[chat_id]: VC_QUEUE.pop(chat_id) except (IndexError, KeyError): await self.group_call.stop() del CLIENTS[self._chat] await vcClient.send_message( self._current_chat, f"Рђб Successfully Left Vc : <code>{chat_id}</code> Рђб", parse_mode="html", ) except Exception as er: LOGS.exception(er) await vcClient.send_message( self._current_chat, f"<strong>ERROR:</strong> <code>{format_exc()}</code>", parse_mode="html", )
async def vc_handler(e): VCAUTH = list(key.keys()) if not ((e.out) or (e.sender_id in VC_AUTHS()) or (vc_auth and e.chat_id in VCAUTH)): return elif vc_auth and key.get(e.chat_id): cha, adm = key.get(e.chat_id), key[e.chat_id]["admins"] if adm and not (await admin_check(e)): return try: await func(e) except Exception: LOGS.exception(Exception) await asst.send_message( LOG_CHANNEL, f"VC Error - <code>{UltVer}</code>\n\n<code>{e.text}</code>\n\n<code>{format_exc()}</code>", parse_mode="html", )
async def vc_handler(e): VCAUTH = list(get_vc().keys()) if not ((e.out) or (e.sender_id in from_users) or (vc_auth and e.chat_id in VCAUTH)): return if vc_auth: cha, adm = check_vcauth(e.chat_id) if adm and not (await admin_check(e)): return try: await func(e) except Exception: LOGS.exception(Exception) await asst.send_message( LOG_CHANNEL, f"VC Error - <code>{UltVer}</code>\n\n<code>{e.text}</code>\n\n<code>{format_exc()}</code>", parse_mode="html", )
async def dl_playlist(chat, from_user, link): # untill issue get fix # https://github.com/alexmercerind/youtube-search-python/issues/107 """ vids = Playlist.getVideos(link) try: vid1 = vids["videos"][0] duration = vid1["duration"] or "РЎЙ" title = vid1["title"] song = await get_stream_link(vid1['link']) thumb = f"https://i.ytimg.com/vi/{vid1['id']}/hqdefault.jpg" return song[0], thumb, title, vid1["link"], duration finally: vids = vids["videos"][1:] for z in vids: duration = z["duration"] or "РЎЙ" title = z["title"] thumb = f"https://i.ytimg.com/vi/{z['id']}/hqdefault.jpg" add_to_queue(chat, None, title, z["link"], thumb, from_user, duration) """ links = await get_videos_link(link) try: search = VideosSearch(links[0], limit=1).result() vid1 = search["result"][0] duration = vid1.get("duration") or "РЎЙ" title = vid1["title"] song = await get_stream_link(vid1["link"]) thumb = f"https://i.ytimg.com/vi/{vid1['id']}/hqdefault.jpg" return song, thumb, title, vid1["link"], duration finally: for z in links[1:]: try: search = VideosSearch(z, limit=1).result() vid = search["result"][0] duration = vid.get("duration") or "РЎЙ" title = vid["title"] thumb = f"https://i.ytimg.com/vi/{vid['id']}/hqdefault.jpg" add_to_queue(chat, None, title, vid["link"], thumb, from_user, duration) except Exception as er: LOGS.exception(er)
language = [udB.get_key("language") or "en"] languages = {} strings_folder = path.join(path.dirname(path.realpath(__file__)), "strings") for file in listdir(strings_folder): if file.endswith(".yml"): code = file[:-4] try: languages[code] = safe_load( open(path.join(strings_folder, file), encoding="UTF-8"), ) except Exception as er: LOGS.info(f"Error in {file[:-4]} language file") LOGS.exception(er) def get_string(key: str) -> Any: lang = language[0] try: return languages[lang][key] except KeyError: try: en_ = languages["en"][key] if not Trs: return en_ tr = Trs.translate(en_, lang_tgt=lang).replace("\ N", "\n") if en_.count("{}") != tr.count("{}"): tr = en_ if languages.get(lang):