Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.1.6 #11

Merged
merged 4 commits into from
Oct 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
Binary file modified TikTokApi/__pycache__/tiktok.cpython-37.pyc
Binary file not shown.
88 changes: 85 additions & 3 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
@@ -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.")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Binary file modified tests/__pycache__/test_trending.cpython-37-pytest-5.1.2.pyc
Binary file not shown.
Binary file modified tests/__pycache__/test_user.cpython-37-pytest-5.1.2.pyc
Binary file not shown.
19 changes: 7 additions & 12 deletions tests/test_trending.py
Original file line number Diff line number Diff line change
@@ -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
api = TikTokapi("browsermob-proxy/bin/browsermob-proxy", headless=True)
assert len(api.trending(50)) >= 50
assert len(api.trending(100)) >= 100