-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path4-download-plst-with-cache.php
38 lines (28 loc) · 1.1 KB
/
4-download-plst-with-cache.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
<?php
require_once '../vendor/autoload.php';
require_once '../src/Ytdl.php';
require_once '../src/Options.php';
use Flatgreen\Ytdl\Options;
use Flatgreen\Ytdl\Ytdl;
// 'cache and 'data' directories must exist and have write permissions
// download a playlist
$webpage_url = 'https://soundcloud.com/lg2-3/sets/amiral-prose-monthly-radio';
$ytdl_options = new Options();
// Write video metadata to a .info.json file
$ytdl_options->addOptions(['--write-info-json']);
$ytdl = new Ytdl($ytdl_options);
$ytdl->setCache(['directory' => 'cache']);
// extract all the playlist
$info_dict = $ytdl->extractInfos($webpage_url);
// download the items 1 and 3 - use the cache system
// $yt_pl_1 with only the item 1 informations
$yt_pl_1 = $ytdl->download($webpage_url, 'data', $info_dict['entries'][0]);
$yt_pl_3 = $ytdl->download($webpage_url, 'data', $info_dict['entries'][2]);
$errors = $ytdl->getErrors();
if (count($errors) !== 0){
echo "<pre>" . implode(' ', $errors) . "</pre>";
} else {
header('Content-Type: application/json');
$json_string = json_encode($info_dict, JSON_PRETTY_PRINT);
echo $json_string;
}