Skip to content

Instantly share code, notes, and snippets.

@janyksteenbeek
Created January 2, 2017 20:35
Show Gist options
  • Save janyksteenbeek/f90d8df64e684b4cbb7fa27436df0ae8 to your computer and use it in GitHub Desktop.
Save janyksteenbeek/f90d8df64e684b4cbb7fa27436df0ae8 to your computer and use it in GitHub Desktop.
Auto-format a free-form YT copyright infringement notice
<?php
/**
* Stolen video title matcher
* @author Janyk Steenbeek <janyk.steenbeek@alveum.net>
* @license All rights reserved
* @url https://www.alveum.net
*/
$stolenPlaylistId = 'UUPu7aiZRcOSgKso6cNjZSag';
$key = 'YOUTUBE_API_KEY';
$originalPlaylistIds = ['UUBS1vxH489OL-oN7P3HUsPw', 'UUzWgtYoa3X7p8zJk5pEr6ww', 'UUC1I7aXYXUI0NVt7nWSaMiA', 'UUkhBnxfBU4r47c6CtDNWIfg'];
$stolenVideos = json_decode(file_get_contents("https://content.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={$stolenPlaylistId}&key={$key}&maxResults=50"))->items;
$originalVideos = [];
foreach($originalPlaylistIds as $playlist) {
$videos = json_decode(file_get_contents("https://content.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId={$playlist}&key={$key}&maxResults=50"))->items;
foreach($videos as $video) {
$originalVideos[] = ['id' => $video->snippet->resourceId->videoId, 'title' => $video->snippet->title];
}
}
foreach($stolenVideos as $video) {
echo "URL of allegedly infringing video to be removed:".PHP_EOL;
echo 'www.youtube.com/watch?v=' . $video->snippet->resourceId->videoId . PHP_EOL;
echo 'Video Title: ' . $video->snippet->title.PHP_EOL;
echo 'Our client\'s YouTube ENTIRE YouTube video was reuploaded by another user'.PHP_EOL;
$url = returnOriginalVideoUrl($originalVideos, $video);
echo 'The URL of the original video: ' . ($url ? $url : '[REPLACE_VIDEO_URL]') .PHP_EOL.PHP_EOL;
}
function returnOriginalVideoUrl($originals, $stolen) {
foreach($originals as $originalVideo) {
if(strtolower(trim($stolen->snippet->title)) == strtolower(trim($originalVideo['title']))) {
return 'www.youtube.com/watch?v=' . $originalVideo['id'];
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment