erste verion
This commit is contained in:
commit
0eaf8f0947
|
@ -0,0 +1,10 @@
|
|||
FROM debian:9.2
|
||||
|
||||
MAINTAINER christopher@chris-latza.de
|
||||
|
||||
RUN apt-get update && apt-get install -y php-cli
|
||||
RUN mkdir /data
|
||||
ADD getPreview.php /data/getPreview.php
|
||||
WORKDIR /data
|
||||
|
||||
ENTRYPOINT ["php", "/data/getPreview.php"]
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
$globalData['ClientID'] = "";
|
||||
$globalData['Channel'] = "";
|
||||
$globalData['Folder'] = "./images/";
|
||||
|
||||
if (isset($argv[1]))
|
||||
$globalData['ClientID'] = @$argv[1];
|
||||
|
||||
if (isset($argv[2]))
|
||||
$globalData['Channel'] = @$argv[2];
|
||||
|
||||
$globalData['sslContext'] = stream_context_create(array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false)));
|
||||
|
||||
function getTokens($channelName)
|
||||
{
|
||||
global $globalData;
|
||||
|
||||
$url = "https://api.twitch.tv/api/channels/".$channelName."/access_token?client_id=".$globalData['ClientID'];
|
||||
|
||||
$json = json_decode(file_get_contents($url));
|
||||
$json->token = json_decode($json->token);
|
||||
return $json;
|
||||
}
|
||||
|
||||
function getStreamInfo($channelName)
|
||||
{
|
||||
global $globalData;
|
||||
|
||||
$url = "https://api.twitch.tv/kraken/streams/".$channelName."?client_id=".$globalData['ClientID'];
|
||||
$json = json_decode(file_get_contents($url, false, $globalData['sslContext']));
|
||||
return $json;
|
||||
}
|
||||
|
||||
function getPreviewURL($infos, $sizeX, $sizeY)
|
||||
{
|
||||
$url = @$infos->stream->preview->template;
|
||||
$url = str_replace("{width}", $sizeX, $url);
|
||||
$url = str_replace("{height}", $sizeY, $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
function getFileCountInFolder()
|
||||
{
|
||||
global $globalData;
|
||||
|
||||
if (!file_exists($globalData['Folder']))
|
||||
mkdir($globalData['Folder'] , 0777, true);
|
||||
|
||||
$files = array();
|
||||
|
||||
if ($handle = opendir($globalData['Folder'])) {
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
if ($entry != "." && $entry != "..")
|
||||
{
|
||||
array_push($files, $entry);
|
||||
}
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
return count($files);
|
||||
}
|
||||
|
||||
function getFileExtention($uri)
|
||||
{
|
||||
$parts = explode(".", $uri);
|
||||
return $parts[(count($parts)-1)];
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
$streamInfo = getStreamInfo($globalData['Channel']);
|
||||
$previewURL = getPreviewURL($streamInfo, "1920", "1080");
|
||||
|
||||
if($previewURL == "")
|
||||
{
|
||||
print_r($globalData);
|
||||
print_r($argv);
|
||||
print_r($streamInfo);
|
||||
echo "URL == ".$previewURL."\n";
|
||||
die("fatal error");
|
||||
}
|
||||
|
||||
|
||||
$imageFileName = $globalData['Folder'].(getFileCountInFolder() + 1).".".getFileExtention($previewURL);
|
||||
|
||||
echo "Copy preview url '".$previewURL."' to '".$imageFileName."' ...";
|
||||
file_put_contents($imageFileName, file_get_contents($previewURL, false, $globalData['sslContext']));
|
||||
echo "done\n";
|
||||
|
||||
sleep(300);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue