Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
YUO’s titler
<?php
if ($argc > 1) {
date_default_timezone_set("UTC");
function udate($format, $utimestamp = null) {
if (is_null($utimestamp)) {
$utimestamp = microtime(true);
}
$timestamp = floor($utimestamp);
$milliseconds = round(($utimestamp - $timestamp) * 1000000);
return date(preg_replace('`(?<!\\\\)u`', sprintf("%06u", $milliseconds), $format), $timestamp);
}
switch ($argv[1]) {
case "-y":
$id = $argv[2];
$url = "https://www.googleapis.com/youtube/v3/videos?part=snippet," .
"contentDetails&id=$id" .
"&key=<YOUR_GOOGLE_API_KEY>";
$apiRaw = file_get_contents($url);
$youTube = json_decode($apiRaw);
$item = $youTube->items[0];
$duration = new DateInterval($item->contentDetails->duration);
$date = new DateTime($item->snippet->publishedAt);
$durf = (intval($duration->format('%h')) != 0) ? $duration->format('%H:%I:%S') : $duration->format('%I:%S');
$ou = "\x02{$item->snippet->title}\x02 (\x1D{$durf}\x1D) published by " . "\x02{$item->snippet->channelTitle}\x02 on \x02{$date->format('F j, Y \a\t G:i:s')}\x02\n";
echo $ou;
break;
case "-s":
$id = $argv[2];
$url = "http://api.soundcloud.com/resolve?url=$id&client_id=<YOUR_SOUNDCLOUD_CLIENT_ID>";
$apiRaw = file_get_contents($url);
$soundCloud = json_decode($apiRaw);
$durf = udate("H:i:s", $soundCloud->duration / 1000);
$date = new DateTime($soundCloud->created_at);
$ou = "\x02{$soundCloud->title}\x02 (\x1D{$durf}\x1D) published by " . "\x02{$soundCloud->user->username}\x02 on \x02{$date->format('F j, Y \a\t G:i:s')}\x02\n";
echo $ou;
break;
default:
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment