mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-30 18:42:55 +00:00
[TikTokBridge] Retry failed OEmbed requests
If an OEmbed request fails, retry a few times, waiting a bit in between each retry. This should fix the problem for the most part, since I think the problem was related to some sort of rate limit (it isn't mentioned in the docs, but it seems to only happen when sending large quantities of sequential requests).
This commit is contained in:
parent
eda6d9baf5
commit
9052455a11
@ -21,6 +21,8 @@ class TikTokBridge extends BridgeAbstract
|
||||
'context' => 'By user', 'username' => '@tiktok'
|
||||
]
|
||||
];
|
||||
const OEMBED_RETRY_COUNT = 20;
|
||||
const OEMBED_RETRY_DELAY = 0.1;
|
||||
|
||||
const CACHE_TIMEOUT = 900; // 15 minutes
|
||||
|
||||
@ -42,7 +44,19 @@ class TikTokBridge extends BridgeAbstract
|
||||
$parsedUrl = parse_url($href);
|
||||
$url = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/' . ltrim($parsedUrl['path'], '/');
|
||||
|
||||
$videoEmbedResponse = getContents('https://www.tiktok.com/oembed?url=' . $url);
|
||||
// Sometimes the API fails to return data for a second, so try a few times
|
||||
$attempts = 0;
|
||||
do {
|
||||
try {
|
||||
// Fetch the video embed data from the OEmbed API
|
||||
$videoEmbedResponse = getContents('https://www.tiktok.com/oembed?url=' . $url);
|
||||
} catch (Exception $e) {
|
||||
$attempts++;
|
||||
sleep($OEMBED_RETRY_DELAY);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
} while($attempts < $OEMBED_RETRY_COUNT);
|
||||
$videoEmbedData = json_decode($videoEmbedResponse);
|
||||
|
||||
$title = $videoEmbedData->title;
|
||||
|
Loading…
Reference in New Issue
Block a user