forked from socialAPIS/YoutubeDownloader
/
FetchPlayer.php
66 lines (49 loc) · 2.29 KB
/
FetchPlayer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once '../vendor/autoload.php';
$yt = new \YoutubeDownloader\YoutubeDownloader();
//If you save your id or key from last session
//you can use it hier
//$yt->registerIdKey("id", "key");
//device registration function
//you can grab from here the device id/key
//and save it somewhere for later use
$registrationResponse = $yt->registerDevice();
//if you want to save the user agent
//for next use you can do it by this
//$yt->getUserAgent()->toArray();
//here you need to initialize the DeviceModel
//and just pass it here
//$yt->setUserAgent($user_agent);
$playerResponse = $yt->playerRequest->fetch_player_info('6eqp7RMi04U'); // here we pass the video id
$echoString = "Video Id: " . $playerResponse->getVideoInfo()->getVideoId() . "\n";
$echoString .= "Video Tittle: " . $playerResponse->getVideoInfo()->getTittle() . "\n";
$echoString .= "Video duration: " . $playerResponse->getVideoInfo()->getDuration() . "\n";
$echoString .= "Uploaded on Channel: " . $playerResponse->getVideoInfo()->getChannel() . "\n";
$echoString .= "Video Description: " . $playerResponse->getVideoInfo()->getDescription() . "\n\n";
/**
* @var $videos video[]
*/
$videos = $playerResponse->getPlayerVideos()->getVideos(); //it can happen that you have audio in video
/**
* @var $audios audio[]
*/
$audios = $playerResponse->getPlayerVideos()->getAudios(); //it can happen that you have video in audio
$echoString .= "============== Videos ==============\n";
foreach ($videos as $video) {
$echoString .= "Video URL: " . $video->getVideoUrl() . "\n";
$echoString .= "Video format: " . $video->getFormat() . "\n";
$echoString .= "Video Size Format: " . $video->getSizeFormat() . "\n";
$echoString .= "Video Size: " . $video->getSize() . "\n\n";
}
$echoString .= "====================================\n\n";
$echoString .= "============== Audios ==============\n";
foreach ($audios as $video) {
$echoString .= "Audio URL: " . $video->getAudioUrl() . "\n";
$echoString .= "Audio format: " . $video->getFormat() . "\n";
$echoString .= "Audio Size Format: " . $video->getSizeFormat() . "\n\n";
}
$echoString .= "====================================\n";
//comment this if you run this in a browser
echo $echoString;
//uncomment this if you run this in a browser
//echo str_replace("\n", "</br>", $echoString);