我想知道某些网站如何获得可以下载的 youtube 视频链接,例如 https://en.savefrom.net/387/ 或其他网站 实际上我想获得一个可下载的 mp3 的 youtube 视频链接,我所能得到的只是没有被下面的代码包裹的 url
function getYouTubeVideo(Request $request)
{
$videoId = $request->query('videoId');
$client = new Client(['http_errors' => false]);
$response = $client->request('GET', 'https://www.youtube.com/watch?v='. $videoId, [
'headers' => [
'Referer' => 'https://www.youtube.com/'
]
]);
// $body = $response->getBody()->getContents();
// Find the script tag that contains ytInitialPlayerResponse variable
$pattern = '/<script nonce=".*?">.*?var ytInitialPlayerResponse = ({.*?});<\/script>/s';
preg_match($pattern, $response->getBody()->getContents(), $matches);
// Extract the value of ytInitialPlayerResponse
$ytInitialPlayerResponse = json_decode($matches[1]);
// dd($ytInitialPlayerResponse);
// Now you can access the properties of ytInitialPlayerResponse
if (isset($ytInitialPlayerResponse->streamingData->adaptiveFormats)) {
$key = $ytInitialPlayerResponse->streamingData->adaptiveFormats;
// Filter the array based on the conditions
$result = array_filter($key, function ($item) {
if (isset($item->audioQuality)) {
if ($item->audioQuality == "AUDIO_QUALITY_MEDIUM" && $item->mimeType == "audio/webm; codecs=\"opus\"") {
return true;
}
}
});
// Output the filtered result
$urlmp3 = [];
$signatureCipher = [];
if (isset(reset($result)->signatureCipher)) {
$song = reset($result)->signatureCipher;
}
if (isset(reset($result)->url)) {
$song = reset($result)->url;
}
$duration = reset($result)->approxDurationMs;
$artist_name = $ytInitialPlayerResponse->videoDetails->author;
$cover = $ytInitialPlayerResponse->videoDetails->thumbnail->thumbnails[0]->url;
$song_title = $ytInitialPlayerResponse->videoDetails->title;
// Return the response as JSON
return response()->json([
'song' => $song,
'duration' => $duration,
'artist_name' => $artist_name,
'cover' => $cover,
'song_title' => $song_title,
]);
} else {
return response()->json([
'message' => 'Not a video',
]);
}
}
但是那些用密码加密的链接就像
s=cMM%3D%3DwYxRgPQP2sS79i%3DBHLQRVW0p8GFbTdLE-H0ivHw9m5VBiAx67RKqfY%3Dwv1fLXd6pZCwK2uQQlfZ9wBUT3AAv9lQoKAhIQRw8JQ0qOA&sp=sig&url=https ://rr5---sn-......
问题很简单,解密这个url的过程是怎样的, 我希望我能解释一下这个问题