| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,16 +9,18 @@ | |||
| 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: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + { | ||
| 2 | + "s_v_web_id": "verify_kjf974fd_y7bupmR0_3uRm_43kF_Awde_8K95qt0GcpBk", | ||
| 3 | + "tt_webid": "6913027209393473025" | ||
| 4 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,15 @@ | |||
| 1 | 1 | import argparse | |
| 2 | 2 | from TikTokAPI import TikTokAPI | |
| 3 | + from utils import read_json_from_file | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | def getHashTag(hashTag): | |
| 6 | - api = TikTokAPI() | ||
| 7 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 7 | 8 | return api.getHashTag(hashTag) | |
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | def getVideosByHashTag(hashTag): | |
| 11 | - api = TikTokAPI() | ||
| 12 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 12 | 13 | return api.getVideosByHashTag(hashTag, count=10) | |
| 13 | 14 | ||
| 14 | 15 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,15 @@ | |||
| 1 | 1 | import argparse | |
| 2 | 2 | from TikTokAPI import TikTokAPI | |
| 3 | + from utils import read_json_from_file | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | def getMusic(music_id): | |
| 6 | - api = TikTokAPI() | ||
| 7 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 7 | 8 | return api.getMusic(music_id) | |
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | def getVideosByMusic(music_id): | |
| 11 | - api = TikTokAPI() | ||
| 12 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 12 | 13 | return api.getVideosByMusic(music_id, count=10) | |
| 13 | 14 | ||
| 14 | 15 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | from TikTokAPI import TikTokAPI | |
| 2 | + from utils import read_json_from_file | ||
| 2 | 3 | ||
| 3 | - api = TikTokAPI() | ||
| 4 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 4 | 5 | retval = api.getTrending(count=5) | |
| 5 | 6 | print("Trending Videos") | |
| 6 | 7 | print(retval) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,20 @@ | |||
| 1 | 1 | import argparse | |
| 2 | 2 | from TikTokAPI import TikTokAPI | |
| 3 | + from utils import read_json_from_file | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | def getUser(user_name): | |
| 6 | - api = TikTokAPI() | ||
| 7 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 7 | 8 | return api.getUserByName(user_name) | |
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | def getVideosByUserName(user_name): | |
| 11 | - api = TikTokAPI() | ||
| 12 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 12 | 13 | return api.getVideosByUserName(user_name, count=1) | |
| 13 | 14 | ||
| 14 | 15 | ||
| 15 | 16 | def getLikesByUserName(user_name): | |
| 16 | - api = TikTokAPI() | ||
| 17 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 17 | 18 | return api.getLikesByUserName(user_name, count=1) | |
| 18 | 19 | ||
| 19 | 20 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,19 +1,20 @@ | |||
| 1 | 1 | import argparse | |
| 2 | 2 | from TikTokAPI import TikTokAPI | |
| 3 | + from utils import read_json_from_file | ||
| 3 | 4 | ||
| 4 | 5 | ||
| 5 | 6 | def getVideoById(video_id): | |
| 6 | - api = TikTokAPI() | ||
| 7 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 7 | 8 | return api.getVideoById(video_id) | |
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | 11 | def downloadVideoById(video_id): | |
| 11 | - api = TikTokAPI() | ||
| 12 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 12 | 13 | api.downloadVideoById(video_id, video_id+".mp4") | |
| 13 | 14 | ||
| 14 | 15 | ||
| 15 | 16 | def downloadVideoByIdNoWatermark(video_id): | |
| 16 | - api = TikTokAPI() | ||
| 17 | + api = TikTokAPI(read_json_from_file("cookie.json")) | ||
| 17 | 18 | api.downloadVideoByIdNoWatermark(video_id, video_id+"_no_wm.mp4") | |
| 18 | 19 | ||
| 19 | 20 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + import json | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + def read_json_from_file(filepath): | ||
| 5 | + with open(filepath, 'r', encoding='utf-8') as json_file: | ||
| 6 | + data = json.load(json_file) | ||
| 7 | + if type(data) is str: | ||
| 8 | + return json.loads(data) | ||
| 9 | + return data | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments