Skip to content

Commit

Permalink
Refactor getData method
Browse files Browse the repository at this point in the history
  • Loading branch information
waska14 committed Jan 24, 2023
1 parent dae19dc commit b12e6be
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Overrides/YoutubeDl/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ public function getData(string $videoUrl): ?array
$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
sleep(1); // Try again
} else {
if ($i == 4) {
return null;
}
break;
}
}
Expand All @@ -115,10 +118,6 @@ public function getData(string $videoUrl): ?array
} else {
$data = array_combine(['warning', 'title', 'id', 'url', 'format'], $data);
}
$data = array_combine([
'title', 'id', 'url', 'format'
], array_filter(preg_split('/[\r\n]/', $output)));
$url = $data['url'];

$data['format'] = Str::afterLast(Str::beforeLast($data['format'], ' '), ' ');
list($data['width'], $data['height']) = explode('x', $data['format']);
Expand Down

0 comments on commit b12e6be

Please sign in to comment.