11import os
2+ import string
23import random
34import urllib .parse
45from .utils import random_key , build_get_url , get_req_json , get_req_content , get_req_text
@@ -12,15 +13,17 @@ def __init__(self, language='en', browser_lang="en-US", timezone="Asia/Kolkata",
1213 self .user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0"
1314
1415 self .headers = {
15- "User-Agent" : self .user_agent ,
16+ 'Host' : 't.tiktok.com' ,
17+ 'User-Agent' : 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' ,
18+ # 'Cookie': 'tt_webid_v2=6913043173028431361; tt_webid=6913043173028431361; tt_csrf_token=taRJpJNwpA9NmrpdiwSwaysu'
1619 }
1720 self .language = language
1821 self .browser_lang = browser_lang
1922 self .timezone = timezone
2023 self .region = region
2124
2225 if cookie is None :
23- self .verifyFp = random_key ( 16 )
26+ self .verifyFp = "verify_kjfaff24_sOZVAInw_G0Sm_4BtI_BStb_SB6moxzLxFrr"
2427 else :
2528 self .verifyFp = cookie
2629 self .default_params = {
@@ -60,7 +63,7 @@ def __init__(self, language='en', browser_lang="en-US", timezone="Asia/Kolkata",
6063
6164 def send_get_request (self , url , params , extra_headers = None ):
6265 url = build_get_url (url , params )
63- did = str (random .randint ( 10000 , 999999999 ))
66+ did = '' . join (random .choice ( string . digits ) for num in range ( 19 ))
6467 url = build_get_url (url , {self .did_key : did }, append = True )
6568 signature = self .tiktok_browser .fetch_auth_params (url , language = self .language )
6669 url = build_get_url (url , {self .signature_key : signature }, append = True )
@@ -95,9 +98,10 @@ def getTrending(self, count=30):
9598 return self .send_get_request (url , params )
9699
97100 def getUserByName (self , user_name ):
98- url = self . base_url + "/user/detail/"
101+ url = "https://t.tiktok.com/node/share/user/@" + user_name
99102 params = {
100- "uniqueId" : user_name
103+ "uniqueId" : user_name ,
104+ "validUniqueId" : user_name ,
101105 }
102106 for key , val in self .default_params .items ():
103107 params [key ] = val
@@ -164,7 +168,7 @@ def getVideosByHashTag(self, hashTag, count=30):
164168 hashTag = hashTag .replace ("#" , "" )
165169 hashTag_obj = self .getHashTag (hashTag )
166170 hashTag_id = hashTag_obj ["challengeInfo" ]["challenge" ]["id" ]
167- url = "https://m.tiktok.com/share/item/list "
171+ url = self . base_url + "/challenge/item_list/ "
168172 req_default_params = {
169173 "secUid" : "" ,
170174 "type" : "3" ,
@@ -174,8 +178,9 @@ def getVideosByHashTag(self, hashTag, count=30):
174178 "recType" : ""
175179 }
176180 params = {
177- "id " : str (hashTag_id ),
181+ "challengeID " : str (hashTag_id ),
178182 "count" : str (count ),
183+ "cursor" : "0" ,
179184 }
180185 for key , val in req_default_params .items ():
181186 params [key ] = val
@@ -194,7 +199,7 @@ def getMusic(self, music_id):
194199 return self .send_get_request (url , params )
195200
196201 def getVideosByMusic (self , music_id , count = 30 ):
197- url = "https://m.tiktok.com/share/item/list "
202+ url = self . base_url + "/music/item_list/ "
198203 req_default_params = {
199204 "secUid" : "" ,
200205 "type" : "4" ,
@@ -204,8 +209,9 @@ def getVideosByMusic(self, music_id, count=30):
204209 "recType" : ""
205210 }
206211 params = {
207- "id " : str (music_id ),
212+ "musicID " : str (music_id ),
208213 "count" : str (count ),
214+ "cursor" : "0" ,
209215 }
210216 for key , val in req_default_params .items ():
211217 params [key ] = val
0 commit comments