Created
May 12, 2016 19:17
-
-
Save kddlb/78b018f02f8245384295742e2128ea32 to your computer and use it in GitHub Desktop.
YUO’s titler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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