1

I was trying to use pytiktok along with telegram-bot to download a tiktok video when the user send a valid tiktok link while I'm using the updater.start_polling() I get 2022-03-12 19:00:56,313 - apscheduler.scheduler - INFO - Scheduler started logged. and that's preventing the asyncio from the pytiktok from running :

     return asyncio.get_event_loop().run_until_complete(self.async_fetch_auth_params(url, language))
  File "C:\Users\tarek\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 656, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Bot:5154205801:dispatcher'. 

I tried to run the download video command before starting the bot, it worked and :

2022-03-12 19:11:12,436 - pyppeteer.launcher - INFO - Browser listening on: ws://127.0.0.1:51206/devtools/browser/b7569447-764a-44a9-aa46-e865bffde0dd
2022-03-12 19:11:12,814 - pyppeteer.launcher - INFO - terminate chrome process...

was logged, and video was downloaded, then the bot started :

2022-03-12 19:11:14,003 - apscheduler.scheduler - INFO - Scheduler started

so I am trying to make them work together .. any ideas ?

full code :

from TikTokAPI import TikTokAPI

tik = TikTokAPI(language='en', region='IN', cookie=None)
import logging
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, bot
from telegram.ext import *
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)
logger = logging.getLogger(__name__)


def getvid(link):
    try:
        link = link.split("/video/")[1].split("?")[0]
    except:
        return False
    tik.downloadVideoById(link, "new/1.mp4")
    return True

# try to download before bot start .. no problems
getvid("https://www.tiktok.com/@2r_9a/video/7059793616004238593?is_copy_url=1&is_from_webapp=v1")


def msghandler(update: Update, context: CallbackContext) -> None:

    text = str(update.message.text).lower()
    if getvid(str(text)):
        update.message.reply_text("Sending video")
    else:
        update.message.reply_text("Wrong Link")


def start(update: Update, context: CallbackContext) -> None:
    update.message.reply_text('Send me Tiktok link')


def main() -> None:
    updater = Updater("5154205801:AAGHjmTYxCyhEsLhdH9PulGFTrCvIrUCpM4")
    updater.dispatcher.add_handler(CommandHandler('start', start))
    updater.dispatcher.add_handler(MessageHandler(Filters.text, msghandler))

    updater.start_polling()

    updater.idle()


if __name__ == '__main__':
    main()
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Star
  • 11
  • 1

0 Answers0