RobertGrubb / tiktok-php

TikTok scraper in PHP
MIT License
63 stars 21 forks source link

tiktok embed videos expire #12

Closed AdrianoRamalho21 closed 4 years ago

AdrianoRamalho21 commented 4 years ago

TikTok embed videos are expiring from time to time, unkown actually. As thumbnails urls expire too, but these have a unix timestamp in it's url, "expires=1594886400..." but the embed videos doesnt have one...

Is there any way to know the expire time for the embed videos? "$video->video->playAddr;"

Thank you in advance ;)

AdrianoRamalho21 commented 4 years ago

Resolution: Seems like the embed url of the videos have a hexdecimal timestamp in it lol

https://v19.tiktokcdn.com/f71ee876ac65cfb993da8cd25f07551d/5f10bbec/video/tos/useast2a/tos-useast2a-ve-0068c001/aea73c290289451eb0d9bf2317a4e735/?a=1233&br=3372&bt=1686&cr=0&cs=0&dr=0&ds=3&er=&l=2020071614430701018903608136098C3B&lr=tiktok_m&mime_type=video_mp4&qs=0&rc=amtrb2pncmg8djMzOTczM0ApZ2Q6PGVnaDs5NzM0aDVkNGdzLm1gaDNxcjNfLS1jMTZzc2A2LV5jYF4xMTA0NV9hYTQ6Yw%3D%3D&vl=&vr=

The seconde parameter of the URL, '5f10bbec', is a hexdecimal timestamp, all I have to do is convert it to unix timestamp, save it and compare it with the "now" timestamp and update it :)

RobertGrubb commented 4 years ago

Glad you figured this out.

If you feel there is a need for this in the package at all, feel free to provide a PR of some sort and we can get it merged in.

AdrianoRamalho21 commented 4 years ago

It all really depends on what you wanna do with it on your application, and your DB structure etc.

When I get like, 10 videos from a user, all those videos come with an updated embed video url as well as an updated thumbnail url. The thing is, embed video urls expire in 6 hours and thumbnails urls expire in 2 days...

I just have to save the expire timestamp (video_url_expire_date or thumbnail_url_expire_date) alongside with the video information, and than I run a command every now and then to scan all those expire_dates, if its outdated, I scrap that specific video and update the video_url, thumbnail_url and the new_expire_date...

As you can see, I dont think it can be a "feature" in the package, because when you scrap for videos, specific or through a user, you always get those with updated urls ;)

RobertGrubb commented 4 years ago

Totally, I guess I meant more of if you need a method to easily get the decoded expiration date.