davidteather / TikTok-Api

The Unofficial TikTok API Wrapper In Python
https://davidteather.github.io/TikTok-Api
MIT License
4.58k stars 934 forks source link

Update JSON Structure [HELP] #31

Closed Lem0nTree closed 4 years ago

Lem0nTree commented 4 years ago

Describe the bug

In the previous version of this API i use the following code to create an array with all the urls

The buggy code

for tiktok in trending:
    videoURL = tiktok["itemInfos"]["video"]["urls"]
    videoname = "downloaded/" + str(prevloops) + ".mp4"
    wget.download(videoURL[0], videoname)
    open("downloaded/concat.txt", 'a').write("file " + str(prevloops) + ".mkv" + "\n")
    clip = VideoFileClip(videoname)
    d = ( clip.duration )
    open("downloaded/durata.txt", 'a').write(str(d) + "\n")
    os.system("ffmpeg -loglevel panic -i downloaded/" + str(prevloops) +  ".mp4" + " -c copy -map 0 downloaded/" + str(prevloops) + ".mkv")
    prevloops += 1

Expected behavior

Download the videos from a target hashtag

Screenshots

If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context

Here the error in the console

Traceback (most recent call last):
  File "downloader.py", line 40, in <module>
    videoURL = tiktok["itemInfos"]["video"]["urls"]
KeyError: 'itemInfos'

I think this error is due to the different json structure, I tried to use the new one but didn't succeed

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.54. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

davidteather commented 4 years ago

Unfortunately with the new api to download a video you have to two it in two different "stages"

for tiktok in trending:
    videoURL = tiktok["link"]
    data = get_Video_By_Url(videoURL, return_bytes=1)
    with open("downloads/download.mp4", "rb") as downloadedObject:
        downloadedObject.write(data)