From 79618b9d813f178abeeba948126dd93d9081d3f0 Mon Sep 17 00:00:00 2001 From: davidteather Date: Fri, 4 Oct 2019 23:05:48 -0500 Subject: [PATCH 1/4] V2.1.6 This new version added the get_Video_By_Url method to the API --- README.md | 10 +++ TikTokApi/__pycache__/tiktok.cpython-37.pyc | Bin 7491 -> 8222 bytes TikTokApi/tiktok.py | 88 +++++++++++++++++++- setup.py | 2 +- 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 969a7eee..48494270 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,16 @@ Search by hashtag returns an array of json objects. Example structure [here](htt It has the same JSON object tree as trending. It's [here](https://gist.github.com/davidteather/bc4baef0edb621dd322c8ad128a31ac1) anyways. +##### The get_Video_By_Url Method + +``` +api.getVideoByUrl(video_url, return_bytes=0) +``` + +video_url - The video you want to get url. + +return_bytes - The default value is 0, when it is set to 1 the function instead returns the bytes from the video rather than just the direct url. + ##### The get_trending_hashtags Method ``` diff --git a/TikTokApi/__pycache__/tiktok.cpython-37.pyc b/TikTokApi/__pycache__/tiktok.cpython-37.pyc index c828f3da4b4b9e9526cb9d99b05ae3ed859406d7..16fb77798122c7bc7261e053f6cd30c09944c5d6 100644 GIT binary patch delta 875 zcmY*XOKTKC5bm1ydy`Gf16E}rMn=LWLIf3KB$0rig5+^nm1VOvhJAYnQA{&e--4R6JDEk@(s_}hmc zuD$lwZm-cSV0l26mv9s%ln)^0Poak?Vg`<^ zGk@aanLm*|jLAGkO*Ih9;jpWiEE(46Nc&5mKYI~QM+Cm%GL82pLs){6U&>&sN>N9 zR(YpUY9Nc+e;Xd`3jh2{!oI+O|tLt zc`-MW1Bs-(!viX{QP|#Z2d#fgU_Dwb+K@CMuO~}x-Q785qgufFn&w2Bc*JG;qKIP4Z+9ELlt9mNea++$dK!n$_ZN sIrraY@zczV0m)tYW_*;n4(0fJCYu(|)ljS@!?t=%vF5DBICXmQ7Zd%&umAu6 delta 179 zcmbQ|aM+5^iItSt;t zEGYsh>?s^T5!MvJ6s{C*Ad4+UD1|457sz5y;R|Na6yCU?nw8OYvJ9IuBlF}0w&RTU zn>E`$=EB*ig diff --git a/TikTokApi/tiktok.py b/TikTokApi/tiktok.py index 5d2da372..c4522a2c 100644 --- a/TikTokApi/tiktok.py +++ b/TikTokApi/tiktok.py @@ -1,5 +1,7 @@ class TikTokapi: - + # + # The TikTokapi class initial function + # def __init__(self, browsermobDirectory, headless=False): # Imports print("New class reference, finding valid signature. This might take a minute.") @@ -58,13 +60,20 @@ def __init__(self, browsermobDirectory, headless=False): server.stop() driver.quit() + # # Show the user the trending hashtags - + # def get_trending_hashtags(self): # Returns the trending hashtags from /en/trending return self.hashtag + + # # Allows the user to search by a specific hashtag + # + # hastag - the hashtag you want to search by + # count - the amount of results you want + # def search_by_hashtag(self, hashtag, count=10): import requests from browsermobproxy import Server @@ -189,7 +198,13 @@ def search_by_hashtag(self, hashtag, count=10): else: raise Exception('Unable to locate the hashtag ID') - # Gets trending + + # + # Gets trending results + # + # count - the number of results to display + # verbose - 0 or 1, 1 is intense logging + # def trending(self, count=10, verbose=0): import requests @@ -227,7 +242,13 @@ def trending(self, count=10, verbose=0): else: return response + + # # Gets a user's post + # + # count - the count of results + # verbose - 1 is high logging + # def userPosts(self, id, count=10, verbose=0): import requests while True: @@ -272,3 +293,64 @@ def userPosts(self, id, count=10, verbose=0): else: return response + + + # + # Gets the source url of a given url for a tiktok + # + # video_url - the url of the video + # return_bytes - 0 is just the url, 1 is the actual video bytes + # + def get_Video_By_Url(self, video_url, return_bytes=0): + # Imports + import requests + import time + import json + from selenium import webdriver + from selenium.webdriver.firefox.options import Options + + # Gets the VideoID + videoID = video_url.split("/video/")[1].split("?")[0] + + # Checks if they should determine the return_bytes + if return_bytes == 0: + # Creates FF profile + profile = webdriver.FirefoxProfile() + options = Options() + profile.set_preference("media.volume_scale", "0.0") + if self.headless == True: + options.headless = True + + driver = webdriver.Firefox(firefox_profile=profile, options=options) + + + driver.get("https://www.tiktok.com/node/video/playwm?id=" + videoID) + time.sleep(3) + + + url = driver.current_url + driver.quit() + + return url + else: + # Creates FF profile + profile = webdriver.FirefoxProfile() + options = Options() + profile.set_preference("media.volume_scale", "0.0") + if self.headless == True: + options.headless = True + + driver = webdriver.Firefox(firefox_profile=profile, options=options) + + + driver.get("https://www.tiktok.com/node/video/playwm?id=" + videoID) + time.sleep(3) + + + url = driver.current_url + driver.quit() + + + r = requests.get(url) + + return r.content \ No newline at end of file diff --git a/setup.py b/setup.py index 33c83743..a96fc727 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setuptools.setup( name = 'TikTokApi', packages = ['TikTokApi'], - version = '2.1.4.2', + version = '2.1.6', license='MIT', description = 'The Unoffical TikTok API Wrapper in Python 3.', author = 'David Teather', From f1768e25683cf0e70ce09620c3a5d8eb830af530 Mon Sep 17 00:00:00 2001 From: davidteather Date: Fri, 4 Oct 2019 23:19:39 -0500 Subject: [PATCH 2/4] Updated tests --- tests/test_trending.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_trending.py b/tests/test_trending.py index f8f17fdb..f0425620 100644 --- a/tests/test_trending.py +++ b/tests/test_trending.py @@ -1,18 +1,20 @@ from TikTokApi import TikTokapi def getTrending(results): - api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) - trending = api.trending(results) + + trending = return len(trending) def test_trending(): - assert getTrending(5) == 5 - assert getTrending(10) == 10 - assert getTrending(20) == 20 + api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) + assert len(api.trending(5)) == 5 + assert len(api.trending(10)) == 10 + assert len(api.trending(20)) == 20 def test_extended_trending(): - assert getTrending(50) == 50 - assert getTrending(100) == 100 \ No newline at end of file + api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) + assert len(api.trending(50)) == 50 + assert len(api.trending(100)) == 100 \ No newline at end of file From dd7f33a671ac00542c8a489fac4ec9ced338c797 Mon Sep 17 00:00:00 2001 From: davidteather Date: Fri, 4 Oct 2019 23:22:30 -0500 Subject: [PATCH 3/4] Fixed Tests --- tests/test_trending.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test_trending.py b/tests/test_trending.py index f0425620..b9677e21 100644 --- a/tests/test_trending.py +++ b/tests/test_trending.py @@ -1,12 +1,5 @@ from TikTokApi import TikTokapi -def getTrending(results): - - trending = - - return len(trending) - - def test_trending(): api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) assert len(api.trending(5)) == 5 From 9828ba2d8898457341279704dab7db208a5bf8f5 Mon Sep 17 00:00:00 2001 From: davidteather Date: Fri, 4 Oct 2019 23:42:31 -0500 Subject: [PATCH 4/4] Changed Tests --- TikTokApi/__pycache__/tiktok.cpython-37.pyc | Bin 8222 -> 8294 bytes .../test_trending.cpython-37-pytest-5.1.2.pyc | Bin 2882 -> 3423 bytes .../test_user.cpython-37-pytest-5.1.2.pyc | Bin 1941 -> 1941 bytes tests/test_trending.py | 10 +++++----- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TikTokApi/__pycache__/tiktok.cpython-37.pyc b/TikTokApi/__pycache__/tiktok.cpython-37.pyc index 16fb77798122c7bc7261e053f6cd30c09944c5d6..f17d1630f004ad5e1f41ec3cb12d513dbc7eb46b 100644 GIT binary patch delta 433 zcmbQ|@XUeFiI%v?-WQX!eyA^F*f1(|y27Wip0x@j^NfvnJEnj9$~%a}EJyL>tTYwctK delta 327 zcmaFnFwcR{iI#WI2QNh$0#9O4WqKwQI+ z1tfzRYSsWnZmV@i4mlNJB2%&si-G~yM`;CyM`@`r-rkJ zD}|?*sg}EjdjT)Rw1td7wJZzxQh32E?kxUV9-yqiLIy^L62TgtW{^Dd0^S-PfrX5< zyfwU8Lct6vK&v(RCZCp7W7L`akw<*8zMLpu6^~kcab|j6Vo7OHs_o_>y~U1;()03(bBWSOd7tLqw}q;4$dD0;NOtml{WFxHvzC0Vvu zj+xLG82yMi`8M27795%smi*17aMNr0YiPos9%weS_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^FTmBD18*tddpy E3vH3nH~;_u diff --git a/tests/__pycache__/test_user.cpython-37-pytest-5.1.2.pyc b/tests/__pycache__/test_user.cpython-37-pytest-5.1.2.pyc index 6e359cc61d126d14e7162a35fa975649109485ec..6bb767da651d0710a11f595859be10a34ae4511e 100644 GIT binary patch delta 332 zcmbQrKb4=&iI&Xh9a)XmW<(y zJewynu4UHdVPIg;WVyv$P-y@nj6j45h%m3>ODrx`-p>Md@Eg35S^QHIDIV`PpQ zGRG8bQV~DMII!-t{G!~%5{p|rAfq50LxUnNpge@&o;;H+OGppM*W|jzkyM(QQ<9li sT%SfX(BcT+S{B07zYBkN^Mx diff --git a/tests/test_trending.py b/tests/test_trending.py index b9677e21..c86fde54 100644 --- a/tests/test_trending.py +++ b/tests/test_trending.py @@ -2,12 +2,12 @@ def test_trending(): api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) - assert len(api.trending(5)) == 5 - assert len(api.trending(10)) == 10 - assert len(api.trending(20)) == 20 + assert len(api.trending(5)) >= 5 + assert len(api.trending(10)) >= 10 + assert len(api.trending(20)) >= 20 def test_extended_trending(): api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) - assert len(api.trending(50)) == 50 - assert len(api.trending(100)) == 100 \ No newline at end of file + assert len(api.trending(50)) >= 50 + assert len(api.trending(100)) >= 100 \ No newline at end of file