Skip to content

Commit

Permalink
Add ability to retrieve whether or not a video is a YouTube original,…
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Dec 2, 2022
1 parent a07596c commit f892223
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function feature($feature)
['playlists/list', 'statistics&id=PLAYLIST_ID'],
['playlistItems/list', 'snippet&playlistId=PLAYLIST_ID(&pageToken=PAGE_TOKEN)'],
['search/list', 'id,snippet&q=QUERY&channelId=CHANNEL_ID&eventType=upcoming&hashTag=HASH_TAG&type=video&order=viewCount,relevance(&pageToken=PAGE_TOKEN)'],
['videos/list', 'id,status,contentDetails,music,short,impressions,containsMusic,isPaidPromotion,isPremium,isMemberOnly,mostReplayed,qualities,chapters&id=VIDEO_ID&clipId=CLIP_ID&SAPISIDHASH=YOUR_SAPISIDHASH']];
['videos/list', 'id,status,contentDetails,music,short,impressions,containsMusic,isPaidPromotion,isPremium,isMemberOnly,mostReplayed,qualities,chapters,isOriginal&id=VIDEO_ID&clipId=CLIP_ID&SAPISIDHASH=YOUR_SAPISIDHASH']];

?>

Expand Down
12 changes: 11 additions & 1 deletion videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

include_once 'common.php';

$realOptions = ['id', 'status', 'contentDetails', 'music', 'short', 'impressions', 'containsMusic', 'isPaidPromotion', 'isPremium', 'isMemberOnly', 'mostReplayed', 'qualities', 'location', 'chapters']; // could load index.php from that
$realOptions = ['id', 'status', 'contentDetails', 'music', 'short', 'impressions', 'containsMusic', 'isPaidPromotion', 'isPremium', 'isMemberOnly', 'mostReplayed', 'qualities', 'location', 'chapters', 'isOriginal']; // could load index.php from that

// really necessary ?
foreach ($realOptions as $realOption) {
Expand Down Expand Up @@ -224,6 +224,16 @@ function getItem($id)
$item['chapters'] = $chapters;
}

if ($options['isOriginal']) {
$json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id);
$isOriginal = doesPathExist($json, 'contents/twoColumnWatchNextResults/results/results/contents/1/videoSecondaryInfoRenderer/metadataRowContainer/metadataRowContainerRenderer/rows/2/metadataRowRenderer/contents/0/simpleText');
if (!$isOriginal) {
$html = getRemote('https://www.youtube.com/watch?v=' . $id);
$isOriginal = str_contains($html, 'xtags=acont%3Doriginal');
}
$item['isOriginal'] = $isOriginal;
}

return $item;
}

Expand Down

4 comments on commit f892223

@Benjamin-Loison
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old commit: 7acd581

@chengdihan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be better. But we still need to check the false positive rate and false negative rate.

@chengdihan
Copy link

@chengdihan chengdihan commented on f892223 Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we save the second call on line 231

$html = getRemote('https://www.youtube.com/watch?v=' . $id);

By retrieving the html from the previous call on line 228

$json = getJSONFromHTML('https://www.youtube.com/watch?v=' . $id);

@Benjamin-Loison
Copy link
Owner Author

@Benjamin-Loison Benjamin-Loison commented on f892223 Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Don't hesitate to accept my StackOverflow answer if it solves your problem.

Please sign in to comment.