Skip to content

Commit

Permalink
Refactor YoutubeDL
Browse files Browse the repository at this point in the history
  • Loading branch information
waska14 committed Jan 24, 2023
1 parent b12e6be commit 517d665
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Overrides/YoutubeDl/YoutubeDl.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public function getData(string $videoUrl): ?array
if (Arr::has($query, 'list')) {
$params = array_merge($params, ['--playlist-items', Arr::get($query, 'index') ?: 1]);
}
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
$process = $this->processBuilder->build($this->binPath, $this->pythonPath, array_merge($params, [
'-f',
'b',
Expand Down Expand Up @@ -152,7 +153,8 @@ public function getVideoAndSubtitles(string $videoUrl, string $subtitleFormat =
if (Arr::has($query, 'list')) {
$params = array_merge($params, ['--playlist-items', Arr::get($query, 'index') ?: 1]);
}
} catch (\Throwable $e) {}
} catch (\Throwable $e) {
}
$process = $this->processBuilder->build($this->binPath, $this->pythonPath, array_merge($params, [
'-f',
'b',
Expand Down Expand Up @@ -182,7 +184,13 @@ public function getVideoAndSubtitles(string $videoUrl, string $subtitleFormat =
$subtitles = str_replace($rnd, '\'', $subtitles);

$data['subtitles'] = collect(json_decode($subtitles, true))->map(function (array $subtitle) use ($subtitleFormat) {
return collect($subtitle)->filter(fn ($formatData) => $formatData['ext'] === $subtitleFormat)->first();
return collect($subtitle)
->filter(function ($formatData) use ($subtitleFormat) {
return is_array($formatData) && Str::lower(Arr::get($formatData, 'ext')) == Str::lower($subtitleFormat);
})
->first();
})->filter(function ($item) {
return is_array($item) && Arr::has($item, ['url', 'name']);
})->map(function (array $item) {
return Arr::only($item, ['url', 'name']);
})->all();
Expand Down

0 comments on commit 517d665

Please sign in to comment.