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 c828f3da..f17d1630 100644 Binary files a/TikTokApi/__pycache__/tiktok.cpython-37.pyc and b/TikTokApi/__pycache__/tiktok.cpython-37.pyc differ 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', diff --git a/tests/__pycache__/test_trending.cpython-37-pytest-5.1.2.pyc b/tests/__pycache__/test_trending.cpython-37-pytest-5.1.2.pyc index cb78008d..f909ad03 100644 Binary files a/tests/__pycache__/test_trending.cpython-37-pytest-5.1.2.pyc and b/tests/__pycache__/test_trending.cpython-37-pytest-5.1.2.pyc differ 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 6e359cc6..6bb767da 100644 Binary files a/tests/__pycache__/test_user.cpython-37-pytest-5.1.2.pyc and b/tests/__pycache__/test_user.cpython-37-pytest-5.1.2.pyc differ diff --git a/tests/test_trending.py b/tests/test_trending.py index f8f17fdb..c86fde54 100644 --- a/tests/test_trending.py +++ b/tests/test_trending.py @@ -1,18 +1,13 @@ from TikTokApi import TikTokapi -def getTrending(results): - api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True) - trending = api.trending(results) - - 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