diff --git a/TikTokApi/__pycache__/__init__.cpython-36.pyc b/TikTokApi/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index bd3d1356..00000000 Binary files a/TikTokApi/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/__init__.cpython-37.pyc b/TikTokApi/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 0ad9d831..00000000 Binary files a/TikTokApi/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/__init__.cpython-38.pyc b/TikTokApi/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 296a96c5..00000000 Binary files a/TikTokApi/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/acrawler.cpython-37.pyc b/TikTokApi/__pycache__/acrawler.cpython-37.pyc deleted file mode 100644 index 4aa119e9..00000000 Binary files a/TikTokApi/__pycache__/acrawler.cpython-37.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/browser.cpython-36.pyc b/TikTokApi/__pycache__/browser.cpython-36.pyc deleted file mode 100644 index 9bae6bba..00000000 Binary files a/TikTokApi/__pycache__/browser.cpython-36.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/browser.cpython-38.pyc b/TikTokApi/__pycache__/browser.cpython-38.pyc deleted file mode 100644 index acf7c9a2..00000000 Binary files a/TikTokApi/__pycache__/browser.cpython-38.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/stealth.cpython-37.pyc b/TikTokApi/__pycache__/stealth.cpython-37.pyc deleted file mode 100644 index 5659c3d4..00000000 Binary files a/TikTokApi/__pycache__/stealth.cpython-37.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/stealth.cpython-38.pyc b/TikTokApi/__pycache__/stealth.cpython-38.pyc deleted file mode 100644 index b880934c..00000000 Binary files a/TikTokApi/__pycache__/stealth.cpython-38.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/tiktok.cpython-36.pyc b/TikTokApi/__pycache__/tiktok.cpython-36.pyc deleted file mode 100644 index cdb43e5e..00000000 Binary files a/TikTokApi/__pycache__/tiktok.cpython-36.pyc and /dev/null differ diff --git a/TikTokApi/__pycache__/tiktok.cpython-38.pyc b/TikTokApi/__pycache__/tiktok.cpython-38.pyc deleted file mode 100644 index a393dfae..00000000 Binary files a/TikTokApi/__pycache__/tiktok.cpython-38.pyc and /dev/null differ diff --git a/TikTokApi/browser.py b/TikTokApi/browser.py index 77795f70..217fdfd8 100644 --- a/TikTokApi/browser.py +++ b/TikTokApi/browser.py @@ -6,6 +6,7 @@ import atexit import requests import logging +from threading import Thread # Import Detection From Stealth from .stealth import stealth @@ -49,15 +50,20 @@ def __init__(self, url, language='en', proxy=None, find_redirect=False, api_url= } try: - self.loop = asyncio.new_event_loop() + loop = asyncio.new_event_loop() + + t = Thread(target=self.__start_background_loop, args=(loop, )) + t.setDaemon(True) + t.start() if find_redirect: - self.loop.run_until_complete(self.find_redirect()) + fut = asyncio.run_coroutine_threadsafe(self.find_redirect(), loop) elif newParams: - self.loop.run_until_complete(self.newParams()) + fut = asyncio.run_coroutine_threadsafe(self.newParams(), loop) else: - self.loop.run_until_complete(self.start()) + fut = asyncio.run_coroutine_threadsafe(self.start(), loop) + fut.result() except: - self.loop.close() + loop.close() async def newParams(self): self.browser = await pyppeteer.launch(self.options) @@ -110,7 +116,6 @@ async def start(self): string.ascii_lowercase + string.ascii_uppercase + string.digits) for i in range(16)) await self.page.evaluate("() => { " + get_acrawler() + " }") - self.signature = await self.page.evaluate('''() => { var url = "''' + self.url + "&verifyFp=" + self.verifyFp + '''" var token = window.byted_acrawler.sign({url: url}); @@ -125,8 +130,8 @@ async def start(self): }) self.data = await self.page.content() - self.data = json.loads(self.data.replace("", "").replace( - '
', ""))
+            #self.data = json.loads(self.data.replace("
", "").replace( + # '
', ""))
 
         await self.browser.close()
         self.browser.process.communicate()
@@ -184,3 +189,7 @@ def __format_proxy(self, proxy):
 
     def __get_js(self, proxy=None):
         return requests.get("https://sf16-muse-va.ibytedtos.com/obj/rc-web-sdk-gcs/acrawler.js", proxies=self.__format_proxy(proxy)).text
+
+    def __start_background_loop(self, loop):
+        asyncio.set_event_loop(loop)
+        loop.run_forever()