From d6d17e4487b41bb23a6db34c6dbc660f6f3ca8ae Mon Sep 17 00:00:00 2001 From: David Teather <34144122+davidteather@users.noreply.github.com> Date: Sat, 12 Sep 2020 17:11:29 -0500 Subject: [PATCH 1/3] Added before & after --- TikTokApi/__pycache__/tiktok.cpython-38.pyc | Bin 32565 -> 32986 bytes TikTokApi/tiktok.py | 102 +++++++++----------- tests/test_search_for.py | 6 +- 3 files changed, 51 insertions(+), 57 deletions(-) diff --git a/TikTokApi/__pycache__/tiktok.cpython-38.pyc b/TikTokApi/__pycache__/tiktok.cpython-38.pyc index 5de46af4dea099ef5f7108c7d17bc8527b949401..896c515189ea67f8020d9fdba1d5f8b7545c017d 100644 GIT binary patch delta 9090 zcmd5?3vg7|dA{fF?%mhj)vg{ZBoJ>9%R}a2BLtZDLjp%Ygm?(BS#(xH5?Z0Ni-X`U ziUFsw9pco-CX-fObY4tG1h16+;6 zE$8*%rtDt?f6Y!1F^JW&C*BMK_lzRy0f0F zk@aSMme$QU>+y?)@?~$$G(UF@do9-O%lIw-IX0qa1DQZ~&u%S3wu;$NATHJNs51=cGSuVl(B^BiLu{sz0tyDRK5FD+h+sZo@donvR& zUhNKzv#fc>%ze_g$<0FYZFAu?e{WZ6;|Y=O6M27c;-oY5(Xj7CDkI-F>sd@L4;}cB ziPL!tM?HMwqq1&>qv@Ot=~+M5hh5;@8Bg(`Mzn*VwMko zS6D0?Ot~#z7O&?zcX7AnwV-5fST6jyxpyd-HMwtC&$zI>JT~4DpNwu1eda9SUb7mVel9MMj{g{?FpNS*4}F zZ3XbFbqB<^GC>|9HCg@^&0_Y3Cu!JR2@h9kSuZci2KuL3ejc&d{a(EaXoyGUYtaSr z*U>uyLJ4gZ1R*z+4tt5)(tJr?DQ%du4&%JLCpnPL8;Rq`lPNApeZmJ4kBV{{H_D%G zm?U>ZJhesP=Y1lXKHir~C-a_;E|JdU{UVt-rqCeP$cM`6ecSM;=8oyP@05L(u}0Zj z5jPrXxq79oXDg!Ysobj-4>9(le6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Lk%UAb;Kz%p9}Bb{rpFusfnnxem5v;?Ui~UMP?W(nfq3 z`ykwjB+jD)y7(H$AqlsUz9VRf)!+za0gu;cv@OOk8%t^hhTZ1c80PR$KYbve$J(Qh z#U?#gdUW3$X8Z|M6@Mz<%675`#Ir5FnB>9Y}YVASK*k1)o7A}P?-1Ac!%VoLgi-BtHT>z2Nm%uiQgdcfIN2aNw!5Uy>UjR@*)58%Q$3~%X@FU)_$H)*@j!-F{O`hoXXf) zS$F6W_Lh9%&=mGl`PYZ)bt5Rx9_p`p6NApO3(m6k!-3gtS0tHuP#!$o#BBNC;qSB6 zrQKhLYVGoLp(;cVtdK|CRGgfTQo<@+xmNjs+Y(hr%)J5ZxeU3XP#496+R&Q}sSQOf zG3pAnD$d1?Ir3ml{~g z5DD7riQgjednCS1;t&a9`HJ!h#Ss)K_&&A0K;n-{yhMU>ruZ`w6p7-;WOeZqSt`z9 z+vHyrn-^r!Y_iDQ_`LXJXQ5-M|BIaEP68d8_6uFtKe6j0vz%2Y@J diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 50c986d7..257c27bb 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -64,7 +64,7 @@ def getData(self, b, **kwargs) -> dict: :param proxy: The IP address of a proxy server to request from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) if self.request_delay is not None: time.sleep(self.request_delay) @@ -108,7 +108,7 @@ def getBytes(self, b, **kwargs) -> bytes: :param proxy: The IP address of a proxy server to request from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = {'verifyFp': b.verifyFp, '_signature': b.signature} url = "{}&{}".format(b.url, urlencode(query)) r = requests.get(url, headers={"method": "GET", @@ -122,11 +122,9 @@ def trending(self, count=30, **kwargs) -> dict: """ Gets trending TikToks """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) response = [] - maxCount = 50 - maxCursor = 0 first = True while len(response) < count: @@ -141,7 +139,7 @@ def trending(self, count=30, **kwargs) -> dict: 'type': 5, 'secUid': '', 'maxCursor': maxCursor, - 'minCursor': 0, + 'minCursor': minCursor, 'sourceType': 12, 'appId': 1233, 'region': region, @@ -205,7 +203,7 @@ def discover_type(self, search_term, prefix, count=28, **kwargs) -> list: :param count: The number of posts to return. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) response = [] offsetCount = 0 @@ -256,11 +254,9 @@ def userPosts(self, userID, secUID, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) response = [] - maxCount = 50 - maxCursor = 0 first = True while len(response) < count: @@ -275,7 +271,7 @@ def userPosts(self, userID, secUID, count=30, **kwargs) -> dict: 'type': 1, 'secUid': secUID, 'maxCursor': maxCursor, - 'minCursor': 0, + 'minCursor': minCursor, 'sourceType': 8, 'appId': 1233, 'region': region, @@ -315,12 +311,12 @@ def byUsername(self, username, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) data = self.getUserObject(username, proxy=proxy) return self.userPosts(data['id'], data['secUid'], count=count, proxy=proxy, language=language, region=region) def userPage( - self, userID, secUID, page_size=30, before=0, after=0, **kwargs + self, userID, secUID, page_size=30, **kwargs ) -> dict: """Returns a dictionary listing of one page of TikToks given a user's ID and secUID @@ -335,19 +331,19 @@ def userPage( Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) api_url = ( "https://m.tiktok.com/api/item_list/?{}&count={}&id={}&type=1&secUid={}" "&minCursor={}&maxCursor={}&sourceType=8&appId=1233®ion={}&language={}".format( self.__add_new_params__(), page_size, str(userID), str(secUID), - after, before, region, language + minCursor, maxCursor, region, language ) ) b = browser(api_url, proxy=proxy) return self.getData(b, proxy=proxy) - def getUserPager(self, username, page_size=30, before=0, after=0, **kwargs): + def getUserPager(self, username, page_size=30, **kwargs): """Returns a generator to page through a user's feed :param username: The username of the user. @@ -360,13 +356,13 @@ def getUserPager(self, username, page_size=30, before=0, after=0, **kwargs): Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) data = self.getUserObject(username, proxy=proxy) while True: resp = self.userPage( data['id'], data['secUid'], page_size=page_size, - before=before, after=after, proxy=proxy, language=language, region=region + maxCursor=maxCursor, minCursor=minCursor, proxy=proxy, language=language, region=region ) try: @@ -375,7 +371,7 @@ def getUserPager(self, username, page_size=30, before=0, after=0, **kwargs): # No mo results return - before = resp['maxCursor'] + maxCursor = resp['maxCursor'] yield page @@ -396,10 +392,8 @@ def userLiked(self, userID, secUID, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) response = [] - maxCount = 50 - maxCursor = 0 first = True while len(response) < count: @@ -414,7 +408,7 @@ def userLiked(self, userID, secUID, count=30, **kwargs) -> dict: 'type': 2, 'secUid': secUID, 'maxCursor': maxCursor, - 'minCursor': 0, + 'minCursor': minCursor, 'sourceType': 9, 'appId': 1233, 'region': region, @@ -462,7 +456,7 @@ def userLikedbyUsername(self, username, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) data = self.getUserObject(username, proxy=proxy) return self.userLiked(data['id'], data['secUid'], count=count, proxy=proxy, language=language, region=region) @@ -479,10 +473,8 @@ def bySound(self, id, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) response = [] - maxCount = 50 - maxCursor = 0 while len(response) < count: if count < maxCount: @@ -496,7 +488,7 @@ def bySound(self, id, count=30, **kwargs) -> dict: 'type': 4, 'secUid': '', 'maxCursor': maxCursor, - 'minCursor': 0, + 'minCursor': minCursor, 'shareUid': '', 'lang': language } @@ -526,7 +518,7 @@ def getMusicObject(self, id, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'musicId': id, 'lang': language @@ -549,10 +541,9 @@ def byHashtag(self, hashtag, count=30, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) id = self.getHashtagObject(hashtag)['challengeInfo']['challenge']['id'] response = [] - maxCursor = 0 while len(response) < count: query = { @@ -561,7 +552,7 @@ def byHashtag(self, hashtag, count=30, **kwargs) -> dict: 'type': 3, 'secUid': '', 'maxCursor': maxCursor, - 'minCursor': 0, + 'minCursor': minCursor, 'shareUid': '', 'recType': '', 'priority_region': region, @@ -592,7 +583,7 @@ def getHashtagObject(self, hashtag, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'challengeName': str(hashtag.encode('utf-8'))[2:-1].replace("\\x", "%").upper(), 'language': language @@ -611,14 +602,14 @@ def getRecommendedTikToksByVideoID(self, id, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'count': 24, 'id': id, 'type': 0, 'secUid': '', - 'maxCursor': 0, - 'minCursor': 0, + 'maxCursor': maxCursor, + 'minCursor': minCursor, 'shareUid': '', 'recType': 3, 'lang': language, @@ -637,7 +628,7 @@ def getTikTokById(self, id, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'itemId': id, 'lang': language, @@ -656,7 +647,7 @@ def getTikTokByUrl(self, url, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) if "@" in url and "/video/" in url: post_id = url.split("/video/")[1].split("?")[0] else: @@ -672,7 +663,7 @@ def discoverHashtags(self, **kwargs) -> dict: :param proxy: The IP address of a proxy server. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'noUser': 1, 'userCount': 30, @@ -689,7 +680,7 @@ def discoverMusic(self, **kwargs) -> dict: :param proxy: The IP address of a proxy server. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'noUser': 1, 'userCount': 30, @@ -709,7 +700,7 @@ def getUserObject(self, username, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) return self.getUser(username, **kwargs)['userInfo']['user'] def getUser(self, username, **kwargs) -> dict: @@ -720,7 +711,7 @@ def getUser(self, username, **kwargs) -> dict: Note: Doesn't seem to have an affect. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'uniqueId': username, 'language': language @@ -738,7 +729,7 @@ def getSuggestedUsersbyID(self, userId='6745191554350760966', count=30, **kwargs :param count: The amount of users to return. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'noUser': 0, 'pageId': userId, @@ -766,7 +757,7 @@ def getSuggestedUsersbyIDCrawler( :param language: The language parameter. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) users = [] unusedIDS = [startingId] while len(users) < count: @@ -789,7 +780,7 @@ def getSuggestedHashtagsbyID(self, count=30, userId='6745191554350760966', **kwa :param count: The amount of users to return. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'noUser': 0, 'pageId': userId, @@ -817,7 +808,7 @@ def getSuggestedHashtagsbyIDCrawler( :param language: The language parameter. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) hashtags = [] ids = self.getSuggestedUsersbyIDCrawler( count=count, startingId=startingId, language=language, proxy=proxy) @@ -840,7 +831,7 @@ def getSuggestedMusicbyID(self, count=30, userId='6745191554350760966', **kwargs :param count: The amount of users to return. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) query = { 'noUser': 0, 'pageId': userId, @@ -866,7 +857,7 @@ def getSuggestedMusicIDCrawler(self, count=30, startingId='6745191554350760966', :param language: The language parameter. :param proxy: The IP address of a proxy to make requests from. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) musics = [] ids = self.getSuggestedUsersbyIDCrawler( count=count, startingId=startingId, language=language, proxy=proxy) @@ -888,7 +879,7 @@ def get_Video_By_TikTok(self, data, **kwargs) -> bytes: :param data: A TikTok object :param proxy: The IP address of your proxy. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) try: api_url = data['video']['downloadAddr'] except Exception: @@ -901,7 +892,7 @@ def get_Video_By_DownloadURL(self, download_url, **kwargs) -> bytes: :param download_url: The download url key value in a TikTok object. :param proxy: The IP for your proxy. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) b = browser(download_url, proxy=proxy) return self.getBytes(b, proxy=proxy) @@ -922,7 +913,7 @@ def get_Video_No_Watermark_ID(self, video_id, return_bytes=0, **kwargs) -> bytes :param return_bytes: Set this to 1 if you want bytes, 0 if you want url. :param proxy: The IP address of your proxy. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) video_info = self.getTikTokById(video_id) video_url = video_info["itemInfo"]["itemStruct"]["video"]["downloadAddr"] headers = {"User-Agent": "okhttp", "Range": "bytes=1000-80000"} @@ -950,7 +941,7 @@ def get_Video_No_Watermark_Faster(self, video_url, return_bytes=0, **kwargs) -> :param return_bytes: Set this to 1 if you want bytes, set it to 0 for url. :param proxy: The IP of your proxy. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) video_id = video_url.split("/video/")[1].split("?")[0] return self.get_Video_No_Watermark_ID(video_id, return_bytes, proxy=proxy) @@ -961,7 +952,7 @@ def get_Video_No_Watermark(self, video_url, return_bytes=0, **kwargs) -> bytes: :param return_bytes: Set this to 0 if you want url, 1 if you want bytes. :param proxy: The IP address of your proxy. """ - region, language, proxy = self.__process_kwargs__(kwargs) + region, language, proxy, minCursor, maxCursor, maxCount = self.__process_kwargs__(kwargs) r = requests.get(video_url, headers={"method": "GET", "accept-encoding": "utf-8", "user-agent": self.userAgent @@ -1066,5 +1057,8 @@ def __process_kwargs__(self, kwargs): region = kwargs.get('region', 'US') language = kwargs.get('language', 'en') proxy = kwargs.get('proxy', None) + maxCursor = kwargs.get('before', 0) + minCursor = kwargs.get('after', 0) + maxCount = kwargs.get('maxCount', 50) - return region, language, proxy + return region, language, proxy, minCursor, maxCursor, maxCount diff --git a/tests/test_search_for.py b/tests/test_search_for.py index 57a7b725..61d46d38 100644 --- a/tests/test_search_for.py +++ b/tests/test_search_for.py @@ -2,6 +2,6 @@ def test_search_for(): api = TikTokApi() - assert len(api.search_for_hashtags('a')) >= 0 - assert len(api.search_for_music('a')) >= 0 - assert len(api.search_for_users('a')) >= 0 \ No newline at end of file + assert len(api.search_for_hashtags('a')) == 28 + assert len(api.search_for_music('a')) == 28 + assert len(api.search_for_users('a')) == 28 \ No newline at end of file From 32c8e449bebc735220fd9a3730699f210e2ee4a4 Mon Sep 17 00:00:00 2001 From: David Teather <34144122+davidteather@users.noreply.github.com> Date: Sat, 12 Sep 2020 17:11:45 -0500 Subject: [PATCH 2/3] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 390cf421..661d2b2f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name='TikTokApi', packages=['TikTokApi'], - version='3.4.9', + version='3.5.0', license='MIT', description='The Unofficial TikTok API Wrapper in Python 3.', author='David Teather', From 517ec6c463c04a130c696f98ae6227656182c8ff Mon Sep 17 00:00:00 2001 From: David Teather <34144122+davidteather@users.noreply.github.com> Date: Sat, 12 Sep 2020 17:18:54 -0500 Subject: [PATCH 3/3] Fix cursor call --- TikTokApi/tiktok.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 257c27bb..8eb7ca96 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -362,7 +362,7 @@ def getUserPager(self, username, page_size=30, **kwargs): while True: resp = self.userPage( data['id'], data['secUid'], page_size=page_size, - maxCursor=maxCursor, minCursor=minCursor, proxy=proxy, language=language, region=region + before=maxCursor, after=minCursor, proxy=proxy, language=language, region=region ) try: