Skip to content

Commit

Permalink
removed getVideoInfo method
Browse files Browse the repository at this point in the history
  • Loading branch information
Athlon1600 committed Oct 31, 2023
1 parent bb1a631 commit ffc8a88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 72 deletions.
3 changes: 3 additions & 0 deletions src/DownloadOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function getAudioFormats()
});
}

/**
* @return StreamFormat[]
*/
public function getCombinedFormats()
{
return Utils::arrayFilterReset($this->getAllFormats(), function ($format) {
Expand Down
28 changes: 0 additions & 28 deletions src/Responses/GetVideoInfo.php

This file was deleted.

63 changes: 19 additions & 44 deletions src/YouTubeDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,38 @@
use YouTube\Exception\YouTubeException;
use YouTube\Models\VideoDetails;
use YouTube\Models\YouTubeConfigData;
use YouTube\Responses\GetVideoInfo;
use YouTube\Responses\PlayerApiResponse;
use YouTube\Responses\VideoPlayerJs;
use YouTube\Responses\WatchVideoPage;
use YouTube\Utils\Utils;

class YouTubeDownloader
{
protected $client;
protected Browser $client;

function __construct()
{
$this->client = new Browser();
}

public function getBrowser()
public function getBrowser(): Browser
{
return $this->client;
}

/**
* @param $query
* @param string $query
* @return array
*/
public function getSearchSuggestions($query)
public function getSearchSuggestions(string $query): array
{
$query = rawurlencode($query);

$response = $this->client->get('http://suggestqueries.google.com/complete/search?client=firefox&ds=yt&q=' . $query);
$response = $this->client->get('http://suggestqueries.google.com/complete/search', [
'client' => 'firefox',
'ds' => 'yt',
'q' => $query
]);
$json = json_decode($response->body, true);

if (is_array($json) && count($json) >= 2) {
Expand All @@ -45,24 +48,7 @@ public function getSearchSuggestions($query)
return [];
}

// No longer working...
public function getVideoInfo($video_id)
{
$video_id = Utils::extractVideoId($video_id);

$response = $this->client->get("https://www.youtube.com/get_video_info?" . http_build_query([
'html5' => 1,
'video_id' => $video_id,
'eurl' => 'https://youtube.googleapis.com/v/' . $video_id,
'el' => 'embedded', // or detailpage. default: embedded, will fail if video is not embeddable
'c' => 'TVHTML5',
'cver' => '6.20180913'
]));

return new GetVideoInfo($response);
}

public function getPage($url)
public function getPage(string $url): WatchVideoPage
{
$video_id = Utils::extractVideoId($url);

Expand All @@ -78,24 +64,8 @@ public function getPage($url)
return new WatchVideoPage($response);
}

/**
* To parse the links for the video we need two things:
* contents of `player_response` JSON object that appears on video pages
* contents of player.js script file that's included inside video pages
*
* @param array $player_response
* @param VideoPlayerJs $player
* @return array
*/
public function parseLinksFromPlayerResponse($player_response, VideoPlayerJs $player)
protected function getPlayerApiResponse(string $video_id, YouTubeConfigData $configData): PlayerApiResponse
{
return [];
}

protected function getPlayerApiResponse($video_id, YouTubeConfigData $configData)
{
// $api_key = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8';

// exact params matter, because otherwise "slow" download links will be returned
$response = $this->client->post("https://www.youtube.com/youtubei/v1/player?key=" . $configData->getApiKey(), json_encode([
"context" => [
Expand Down Expand Up @@ -124,13 +94,17 @@ protected function getPlayerApiResponse($video_id, YouTubeConfigData $configData
}

/**
* @param $video_id
* @param array $options
*
* TOOD: rename to DownloadResult??
*
* @param string $video_id
* @param $options
* @return DownloadOptions
* @throws TooManyRequestsException
* @throws VideoNotFoundException
* @throws YouTubeException
*/
public function getDownloadLinks($video_id, $options = array())
public function getDownloadLinks(string $video_id, $options = null): DownloadOptions
{
$page = $this->getPage($video_id);

Expand All @@ -144,6 +118,7 @@ public function getDownloadLinks($video_id, $options = array())
throw new VideoNotFoundException();
}

// a giant JSON object holding useful data
$youtube_config_data = $page->getYouTubeConfigData();

// the most reliable way of fetching all download links no matter what
Expand Down

0 comments on commit ffc8a88

Please sign in to comment.