mirror of
https://github.com/imgyh/tiktok.git
synced 2025-10-07 06:51:28 +08:00
支持本地生成X-Bogus
由于使用第三方接口必然会产生网络延迟等问题,故支持本地生成X-Bogus 参考项目https://github.com/B1gM8c/tiktok
This commit is contained in:
parent
d5c424b2a7
commit
5dfb81670d
@ -20,6 +20,8 @@ import requests
|
||||
from TikTokUrls import Urls
|
||||
import urllib.parse
|
||||
import execjs
|
||||
import os
|
||||
import sys
|
||||
|
||||
class Utils(object):
|
||||
def __init__(self):
|
||||
@ -51,6 +53,13 @@ class Utils(object):
|
||||
# 去除前后空格
|
||||
return result
|
||||
|
||||
def resource_path(self,relative_path):
|
||||
if getattr(sys, 'frozen', False): # 是否Bundle Resource
|
||||
base_path = sys._MEIPASS
|
||||
else:
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
return os.path.join(base_path, relative_path)
|
||||
|
||||
def getXbogus(self, url, headers=None):
|
||||
# getXbogus算法开源地址https://github.com/B1gM8c/tiktok
|
||||
urls = Urls()
|
||||
@ -58,7 +67,7 @@ class Utils(object):
|
||||
user_agent = headers.get(
|
||||
'User-Agent') if headers else "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
|
||||
try:
|
||||
xbogus = execjs.compile(open('./X-Bogus.js').read()).call('sign', query, user_agent)
|
||||
xbogus = execjs.compile(open(self.resource_path(os.path.join("X-Bogus.js"))).read()).call('sign', query, user_agent)
|
||||
params = url + "&X-Bogus=" + xbogus
|
||||
except Exception as e:
|
||||
print('[ 错误 ]:X-Bogus算法异常')
|
||||
|
Loading…
x
Reference in New Issue
Block a user