Skip to content

Commit c7c6767

Browse files
committed
prettifying
1 parent d74f578 commit c7c6767

File tree

7 files changed

+116
-169
lines changed

7 files changed

+116
-169
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TikTok API
2+
3+
TikTok has no public API. This library is aimed at getting the public data available at [www.tiktok.com](https://www.tiktok.com).
4+
5+
## Instlling
6+
```python
7+
pip install TikPy
8+
```
9+
## Quick Start
10+
```python
11+
12+
```

TikPy/API.py

+102-98
Original file line numberDiff line numberDiff line change
@@ -5,107 +5,111 @@
55
import os
66
import time
77

8-
def get_jsoned(url):
9-
"""
10-
11-
:param url:
12-
:return: json file containing the matadata
13-
"""
14-
art = Article(url)
15-
art.download()
16-
art.parse()
17-
soup = BeautifulSoup(art.html)
18-
for div in soup.findAll('script'):
19-
if "window.__INIT_PROPS__" in div.text:
20-
text = div.text[24:]
21-
text = text.replace('\n', '')
22-
return json.loads(text)
23-
24-
def get_user_info(name, from_video):
25-
"""
26-
:param name of user:
27-
:return: user Data
28-
"""
29-
jsoned = ''
30-
if from_video:
31-
start_index = name.find('/video/')
32-
print(name[:start_index])
33-
jsoned = get_jsoned(name[:start_index])
34-
else:
35-
jsoned = get_jsoned(name)
36-
try:
37-
return jsoned['/@:uniqueId']['userData']
38-
except Exception as E:
39-
return {}
40-
41-
42-
def get_user_videos(name):
43-
url = 'https://www.tiktok.com/@' + name
44-
jsoned = get_jsoned(url)
45-
return jsoned['/@:uniqueId']['itemList']
46-
47-
48-
def get_trending_hashtags():
49-
url = 'https://www.tiktok.com/trending'
50-
jsoned = get_jsoned(url)
51-
return jsoned['/trending']['challengeList']
52-
53-
54-
def get_trending_posts():
55-
url = 'https://www.tiktok.com/trending'
56-
jsoned = get_jsoned(url)
57-
return jsoned['/trending']['itemList']
58-
59-
60-
def get_video_info(url):
61-
jsoned = get_jsoned(url)
62-
try:
63-
temp = jsoned['/@:uniqueId/video/:id']['videoData']
64-
temp['url'] = url
65-
return temp
66-
except Exception as identifier:
67-
print(identifier)
68-
return {}
69-
70-
71-
def get_hash_recommend_list(name):
72-
url = 'https://www.tiktok.com/tag/' + name
73-
jsoned = get_jsoned(url)
74-
return jsoned['/tag/:name']['recommendList']
75-
76-
77-
def get_hash_videos(name):
78-
url = 'https://www.tiktok.com/tag/' + name
79-
jsoned = get_jsoned(url)
80-
return jsoned['/tag/:name']['itemList']
81-
82-
83-
def get_videos_from_music(music_id, name):
84-
url = 'https://www.tiktok.com/music/'+name.replace(' ', '-') + music_id
85-
jsoned = get_jsoned(url)
86-
return jsoned['/music/*-:id']['itemList']
87-
88-
89-
def get_music_recommend_list(music_id, name):
90-
url = 'https://www.tiktok.com/music' + name.replace(' ', '-') + music_id
91-
jsoned = get_jsoned(url)
92-
return jsoned['/music/*-:id']['recommendList']
93-
94-
95-
def download_video(url, post_name=None):
96-
r = requests.get(url, stream=True)
97-
if post_name:
98-
with open(post_name, 'wb') as f:
8+
class API():
9+
def __init__(self):
10+
pass
11+
12+
def get_jsoned(self, url):
13+
"""
14+
15+
:param url:
16+
:return: json file containing the matadata
17+
"""
18+
art = Article(url)
19+
art.download()
20+
art.parse()
21+
soup = BeautifulSoup(art.html, features="lxml")
22+
for div in soup.findAll('script'):
23+
if "window.__INIT_PROPS__" in div.text:
24+
text = div.text[24:]
25+
text = text.replace('\n', '')
26+
return json.loads(text)
27+
28+
def get_user_info(self, name, from_video):
29+
"""
30+
:param name of user:
31+
:return: user Data
32+
"""
33+
jsoned = ''
34+
if from_video:
35+
start_index = name.find('/video/')
36+
print(name[:start_index])
37+
jsoned = get_jsoned(name[:start_index])
38+
else:
39+
jsoned = get_jsoned(name)
40+
try:
41+
return jsoned['/@:uniqueId']['userData']
42+
except Exception as E:
43+
return {}
44+
45+
46+
def get_user_videos(self, name):
47+
url = 'https://www.tiktok.com/@' + name
48+
jsoned = get_jsoned(url)
49+
return jsoned['/@:uniqueId']['itemList']
50+
51+
52+
def get_trending_hashtags(self):
53+
url = 'https://www.tiktok.com/trending'
54+
jsoned = get_jsoned(url)
55+
return jsoned['/trending']['challengeList']
56+
57+
58+
def get_trending_posts(self):
59+
url = 'https://www.tiktok.com/trending'
60+
jsoned = get_jsoned(url)
61+
return jsoned['/trending']['itemList']
62+
63+
64+
def get_video_info(self, url):
65+
jsoned = get_jsoned(url)
66+
try:
67+
temp = jsoned['/@:uniqueId/video/:id']['videoData']
68+
temp['url'] = url
69+
return temp
70+
except Exception as identifier:
71+
print(identifier)
72+
return {}
73+
74+
75+
def get_hash_recommend_list(self, name):
76+
url = 'https://www.tiktok.com/tag/' + name
77+
jsoned = get_jsoned(url)
78+
return jsoned['/tag/:name']['recommendList']
79+
80+
81+
def get_hash_videos(self, name):
82+
url = 'https://www.tiktok.com/tag/' + name
83+
jsoned = get_jsoned(url)
84+
return jsoned['/tag/:name']['itemList']
85+
86+
87+
def get_videos_from_music(self, music_id, name):
88+
url = 'https://www.tiktok.com/music/'+name.replace(' ', '-') + music_id
89+
jsoned = get_jsoned(url)
90+
return jsoned['/music/*-:id']['itemList']
91+
92+
93+
def get_music_recommend_list(self, music_id, name):
94+
url = 'https://www.tiktok.com/music' + name.replace(' ', '-') + music_id
95+
jsoned = get_jsoned(url)
96+
return jsoned['/music/*-:id']['recommendList']
97+
98+
99+
def download_video(self, url, post_name=None):
100+
r = requests.get(url, stream=True)
101+
if post_name:
102+
with open(post_name, 'wb') as f:
103+
for chunk in r.iter_content(chunk_size=1024 * 1024):
104+
if chunk:
105+
f.write(chunk)
106+
else:
107+
return None
108+
else:
99109
for chunk in r.iter_content(chunk_size=1024 * 1024):
100110
if chunk:
101-
f.write(chunk)
111+
return chunk
102112
else:
103113
return None
104-
else:
105-
for chunk in r.iter_content(chunk_size=1024 * 1024):
106-
if chunk:
107-
return chunk
108-
else:
109-
return None
110114

111115

33 Bytes
Binary file not shown.

TikPy/new_API.py

-23
This file was deleted.

Untitled.ipynb

-46
This file was deleted.

dist/TikPy-0.3.tar.gz

2.18 KB
Binary file not shown.

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'TikPy', # How you named your package folder (MyLib)
44
packages = ['TikPy'], # Chose the same as "name"
5-
version = '0.2', # Start with a small number and increase it with every change you make
5+
version = '0.3', # Start with a small number and increase it with every change you make
66
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
77
description = 'Tiktok API. ', # Give a short description about your library
88
author = 'Vishwesh Kumar', # Type in your name
99
author_email = '[email protected]', # Type in your E-Mail
1010
url = 'https://github.com/precog-recr/TikPy', # Provide either the link to your github or to your website
11-
download_url = 'https://github.com/precog-recr/TikPy/archive/V_02.tar.gz', # I explain this later on
11+
download_url = 'https://github.com/precog-recr/TikPy/archive/v_03.tar.gz', # I explain this later on
1212
keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'], # Keywords that define your package best
1313
install_requires=[ # I get to this in a second
1414
'bs4',

0 commit comments

Comments
 (0)