Skip to content

Commit

Permalink
Try 5 times to get data from youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
waska14 committed Oct 5, 2021
1 parent 67aaab6 commit 00d0105
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Overrides/YoutubeDl/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ public function getData(string $videoUrl): ?array
'--youtube-skip-hls-manifest',
$videoUrl
]));
$output = $this->getProcessOutput($process);
$data = array_filter(preg_split('/[\r\n]/', $output));
for ($i = 0; $i < 5; $i++) {
$output = $this->getProcessOutput($process);
$data = array_filter(preg_split('/[\r\n]/', $output));
if (count($data) < 4 || count($data) > 5) {
sleep(1); // Try again in 5 seconds
} else {
break;
}
}
if (count($data) == 4) {
$data = array_combine(['title', 'id', 'url', 'format'], $data);
} else {
Expand Down

0 comments on commit 00d0105

Please sign in to comment.