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

add method to get music object by api #580

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,23 @@ def get_music_object_full(self, id, **kwargs):
j_raw = self.__extract_tag_contents(r.text)
return json.loads(j_raw)["props"]["pageProps"]["musicInfo"]

def get_music_object_full_by_api(self, id, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you'd prefer an option in the other method, or to keep them separate

"""Discover page, consists of music"""
(
region,
language,
proxy,
maxCount,
did,
) = self.__process_kwargs__(kwargs)
kwargs["custom_did"] = did

api_url = "{}node/share/music/-{}?{}".format(
BASE_URL, id, self.__add_new_params__()
)
res = self.get_data(url=api_url, **kwargs)
return res['musicInfo']

def by_hashtag(self, hashtag, count=30, offset=0, **kwargs) -> dict:
"""Returns a dictionary listing TikToks with a specific hashtag.

Expand Down
12 changes: 12 additions & 0 deletions tests/test_getMusicObjectFullByApi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from TikTokApi import TikTokApi
import os

api = TikTokApi.get_instance(
custom_verifyFp=os.environ.get("verifyFp", None), use_test_endpoints=True
)


def test_get_music_object_full_by_api():
music_id = "6819262113299565318"
res = api.get_music_object_full_by_api(music_id)
assert res['music']['id'] == music_id