|
9 | 9 | class VideoException(Exception): |
10 | 10 | pass |
11 | 11 |
|
| 12 | + |
12 | 13 | class TikTokAPI(object): |
13 | 14 |
|
14 | | - def __init__(self, cookie={}, language='en', browser_lang="en-US", timezone="Asia/Kolkata", region='IN'): |
| 15 | + def __init__(self, cookie=None, language='en', browser_lang="en-US", timezone="Asia/Kolkata", region='IN'): |
15 | 16 | self.base_url = "https://t.tiktok.com/api" |
16 | 17 | self.user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0" |
17 | 18 |
|
| 19 | + if cookie is None: |
| 20 | + cookie = {} |
18 | 21 | self.verifyFp = cookie.get("s_v_web_id", "verify_kjf974fd_y7bupmR0_3uRm_43kF_Awde_8K95qt0GcpBk") |
19 | 22 | self.tt_webid = cookie.get("tt_webid", "6913027209393473025") |
20 | 23 |
|
21 | | - |
22 | 24 | self.headers = { |
23 | 25 | 'Host': 't.tiktok.com', |
24 | 26 | 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0', |
@@ -134,7 +136,7 @@ def getVideosByUserName(self, user_name, count=30): |
134 | 136 | for key, val in self.default_params.items(): |
135 | 137 | params[key] = val |
136 | 138 | return self.send_get_request(url, params) |
137 | | - |
| 139 | + |
138 | 140 | def getLikesByUserName(self, user_name, count=30): |
139 | 141 | user_data = self.getUserByName(user_name) |
140 | 142 | user_obj = user_data["userInfo"]["user"] |
@@ -249,7 +251,7 @@ def downloadVideoByIdNoWatermark(self, video_id, save_path): |
249 | 251 | raise VideoException("Video without watermark not available in new videos") |
250 | 252 | video_url_no_wm = "https://api2-16-h2.musical.ly/aweme/v1/play/?video_id={" \ |
251 | 253 | "}&vr_type=0&is_play_url=1&source=PackSourceEnum_PUBLISH&media_type=4" \ |
252 | | - .format(video_data[pos+4:pos+36]) |
| 254 | + .format(video_data[pos + 4:pos + 36]) |
253 | 255 |
|
254 | 256 | video_data_no_wm = get_req_content(video_url_no_wm, params=None, headers=self.headers) |
255 | 257 | with open(save_path, 'wb') as f: |
|
0 commit comments