Have you ever dreamed put your own channel on your own website?
LittleYoutube is here to help you
Warn:
Youtube doesn't like their content being scraped. Please respect their service by not use this library as a scraping bot or a replacement for their website.
This library is developed to help the community.
- LittleYoutube
- Table of contents
- Getting Started
- Download via composer
- Sample Usage
- Documentation
- Contribution
- License
- Clone/download this repo
- Include
LittleYoutube.php
to your php script
Add LittleYoutube to composer.json configuration file.
$ composer require scarletsfiction/littleyoutube
And update it
$ composer update
<?php
// require 'vendor/autoload.php';
require_once "LittleYoutube.php";
use ScarletsFiction\LittleYoutube;
$video = LittleYoutube::video("https://www.youtube.com/watch?v=xQomv1gqmb4");
echo("Video ID:".$video->data['videoID']."\n");
print_r($video->getVideoImages());
Available options
{
// Must be set to save the decipher logic
"temporaryDirectory"=>realpath("./temp"),
// View the decipher logic as a text
"signatureDebug"=>false || realpath("./signatureDebug.log"),
// Get the detailed info
"processDetail"=>true,
// Optional if the video can't be downloaded on some country
"useRedirector"=>false,
// Will be slow because all url header will be checked
"loadVideoSize"=>false,
// Parse from VideoInfo or VideoPage
"processVideoFrom"=>"VideoInfo" || "VideoPage"
}
$video = LittleYoutube::video("videoURLHere", options);
//Reinit video class $video->init("videoURLHere");
Return video class
$video->getImage();
Return Indexed Array
[ "HighQualityURL", "MediumQualityURL", "DefaultQualityURL" ]
$video->getEmbedLink();
// Usually we will wrap it with iframe
echo('<iframe width="480" height="360" src="'.$video->getEmbedLink().'" frameborder="0" allowfullscreen></iframe>');
$video->parseSubtitle(args, asSRT);
- args: subtitle index or xml string
- asSRT: return as srt format
- note: if you pass subtitle index, ProcessDetails must be enabled/called
[
[0]=>[
[time] => 1.31,
[duration] => 6.609,
[text]=>"in a single lifetime we can take a days"
],
...
]
$video->data;
- You can also call $video->processDetails() to refresh data
Return Associative Array of current video data
{
"videoID"=>"",
//When ProcessDetail was enabled/called
"playerID", "title", "duration", "viewCount", "like", "dislike", "author", "subtitle", "uploaded", "description", "metatag", "channelID",
// Not available when ProcessDetails = false
video=>{
"encoded"=>[
[0] => {
"itag",
"type"=>[
[0] => Media //video
[1] => Format //mp4
[2] => Encoder //avc1.64001F, mp4a.40.2
],
"expire", //timestamp
"quality", //hd720, medium, small
"url",
"size" //When loadVideoSize was enabled
},
...
],
"adaptive"=>[
[0] => {
"itag",
"type"=>[
[0] => Media //video
[1] => Format //mp4
[2] => Encoder //avc1.4d401f
],
"expire", //timestamp
"quality", //1080p, 720p, 192k, 144k
"url",
"size" //When loadVideoSize was enabled
},
...
],
//If it's a live stream, then return m3u8 url only
"stream"
}
}
$channel = LittleYoutube::channel("channelURLHere", options);
//Reinit channel class $channel->init("channelURLHere");
Return channel class
$channel->getChannelRSS();
Return string
https://www.youtube.com/feeds/videos.xml?channel_id=...
$channel->data;
- You can also call $channel->processDetails() to refresh data
Return Associative Array of current channel data
{
//Some data will available when ProcessDetail was enabled/called
"channelID", "userID",
"playlists"=>[
[0]=>{
"playlistID"=>""
"title"=>"",
"length"=>0
},
...
]
"videos"=>[
[0]=>{
"videoID"=>""
"title"=>"",
"viewCount"=>0
},
...
]
}
$playlist = LittleYoutube::playlist("playlistURLHere", options);
//Reinit playlist class $playlist->init("playlistURLHere");
Return playlist class
$playlist->data;
- You can also call $playlist->processDetails() to refresh data
Return string
{
//Some data will available when ProcessDetail was enabled/called
"playlistID", "channelID", "userID",
"userData"=>{
"name", image
},
"videos"=>[
[0]=>{
"title", "videoID"
},
...
]
}
$search = LittleYoutube::search("searchQueryHere", options);
//Reinit search class $search->init("searchQueryHere");
Return search class
$search->data;
- You can also call $search->processDetails() to refresh data
Return string
{
"query",
// Not available when ProcessDetails = false
"video"=>[
[0]=>{
"videoID", "title", "duration", "userID", "userName", "uploaded", "views"
}
],
//When available
"next", "previous"
}
$search->next();
This will add result from the next page to current data
You can also change the settings after initialize LittleYoutube class
$classes->settings[options] = value;
If you want to help in LittleYoutube library, please make it even better and start a pull request into it.
Don't forget to follow me ^.^)/
LittleYoutube is under the MIT license.