Skip to content

Commit

Permalink
Add videos?part=captions
Browse files Browse the repository at this point in the history
To solve [Benjamin_Loison/youtube_push_notifications/issues/26](https://codeberg.org/Benjamin_Loison/youtube_push_notifications/issues/26).
  • Loading branch information
Benjamin-Loison committed Oct 25, 2024
1 parent c21362f commit 252f378
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

function getContextFromOpts($opts)
{
if (GOOGLE_ABUSE_EXEMPTION !== '') {
if (GOOGLE_ABUSE_EXEMPTION !== '') {
// Can maybe leverage an approach like [issues/321](https://github.com/Benjamin-Loison/YouTube-operational-API/issues/321).
$cookieToAdd = 'GOOGLE_ABUSE_EXEMPTION=' . GOOGLE_ABUSE_EXEMPTION;
// Can't we simplify the following code?
if (array_key_exists('http', $opts)) {
Expand Down
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function feature($feature)
'isMemberOnly',
'mostReplayed',
'qualities',
'captions',
'chapters',
'isOriginal',
'isRestricted',
Expand Down
14 changes: 14 additions & 0 deletions videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
'isMemberOnly',
'mostReplayed',
'qualities',
'captions',
'location',
'chapters',
'isOriginal',
Expand Down Expand Up @@ -346,6 +347,19 @@ function getItem($id)
$item['qualities'] = $qualities;
}

if ($options['captions']) {
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id", scriptVariable: 'ytInitialPlayerResponse', forceLanguage: true);
$captions = [];
foreach ($json['captions']['playerCaptionsTracklistRenderer']['captionTracks'] as $caption) {
array_push($captions, [
'name' => $caption['name']['simpleText'],
'languageCode' => $caption['languageCode'],
'kind' => $caption['kind'],
]);
}
$item['captions'] = $captions;
}

if ($options['location']) {
$json = getJSONFromHTML("https://www.youtube.com/watch?v=$id");
$location = $json['contents']['twoColumnWatchNextResults']['results']['results']['contents'][0]['videoPrimaryInfoRenderer']['superTitleLink']['runs'][0]['text'];
Expand Down

0 comments on commit 252f378

Please sign in to comment.