Skip to content

Commit

Permalink
Merge pull request #236 from davidteather/nightly
Browse files Browse the repository at this point in the history
V3.4.6
  • Loading branch information
davidteather authored Aug 24, 2020
2 parents c2108b5 + 8b94367 commit 42e9de6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dist/*
*.egg-info
.pytest_cache/*
test.mp4
test.txt
test.txt
.pytest_cache/*
Binary file added TikTokApi/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified TikTokApi/__pycache__/browser.cpython-37.pyc
Binary file not shown.
Binary file added TikTokApi/__pycache__/get_acrawler.cpython-37.pyc
Binary file not shown.
Binary file added TikTokApi/__pycache__/stealth.cpython-37.pyc
Binary file not shown.
Binary file modified TikTokApi/__pycache__/tiktok.cpython-37.pyc
Binary file not shown.
42 changes: 28 additions & 14 deletions TikTokApi/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import random
import time
import string
import atexit
import requests
import logging
from threading import Thread
Expand All @@ -13,6 +12,11 @@

from .get_acrawler import get_acrawler

async_support = False
def set_async():
global async_support
async_support = True

class browser:
def __init__(self, url, language='en', proxy=None, find_redirect=False, api_url=None, debug=False, newParams=False):
self.url = url
Expand Down Expand Up @@ -48,12 +52,10 @@ def __init__(self, url, language='en', proxy=None, find_redirect=False, api_url=
'handleSIGTERM': False,
'handleSIGHUP': False
}

try:
if async_support:
loop = asyncio.new_event_loop()

t = Thread(target=self.__start_background_loop, args=(loop, ))
t.setDaemon(True)
t = Thread(target=self.__start_background_loop, args=(loop, ), daemon=True)
t.start()
if find_redirect:
fut = asyncio.run_coroutine_threadsafe(self.find_redirect(), loop)
Expand All @@ -62,10 +64,24 @@ def __init__(self, url, language='en', proxy=None, find_redirect=False, api_url=
else:
fut = asyncio.run_coroutine_threadsafe(self.start(), loop)
fut.result()
except:
loop.close()
else:
try:
self.loop = asyncio.new_event_loop()
if find_redirect:
self.loop.run_until_complete(self.find_redirect())
elif newParams:
self.loop.run_until_complete(self.newParams())
else:
self.loop.run_until_complete(self.start())
except:
self.loop.close()

async def newParams(self):
def __start_background_loop(self, loop):
asyncio.set_event_loop(loop)
loop.run_forever()


async def newParams(self) -> None:
self.browser = await pyppeteer.launch(self.options)
self.page = await self.browser.newPage()
await self.page.goto("about:blank")
Expand All @@ -87,6 +103,8 @@ async def newParams(self):
await self.browser.close()
self.browser.process.communicate()

return 0

async def start(self):
self.browser = await pyppeteer.launch(self.options)
self.page = await self.browser.newPage()
Expand Down Expand Up @@ -188,8 +206,4 @@ def __format_proxy(self, proxy):
return None

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()
return requests.get("https://sf16-muse-va.ibytedtos.com/obj/rc-web-sdk-gcs/acrawler.js", proxies=self.__format_proxy(proxy)).text
2 changes: 1 addition & 1 deletion TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio

import pyppeteer
import random
import requests
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setuptools.setup(
name = 'TikTokApi',
packages = ['TikTokApi'],
version = '3.4.5',
version = '3.4.6',
license='MIT',
description = 'The Unofficial TikTok API Wrapper in Python 3.',
author = 'David Teather',
Expand Down

0 comments on commit 42e9de6

Please sign in to comment.