aboutsummaryrefslogtreecommitdiff
path: root/command/download.php
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--command/download.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/command/download.php b/command/download.php
index 4018a9a..486c7af 100644
--- a/command/download.php
+++ b/command/download.php
@@ -131,5 +131,33 @@ function download($what, $conference, $url, $cache)
function do_download($url, $cache)
{
+ $handle = curl_init($url);
+ curl_setopt_array($handle, [
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_MAXREDIRS => 10,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => false, /* accept all certificates, even self-signed */
+ CURLOPT_SSL_VERIFYHOST => 2, /* verify hostname is in cert */
+ CURLOPT_CONNECTTIMEOUT => 3, /* connect-timeout in seconds */
+ CURLOPT_TIMEOUT => 5, /* transfer timeout im seconds */
+ CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
+ CURLOPT_REFERER => 'https://streaming.media.ccc.de/',
+ CURLOPT_USERAGENT => '@c3voc Streaming-Website Downloader-Cronjob, Contact voc AT c3voc DOT de in case of problems. Might the Winkekatze be with you',
+ ]);
+
+ $return = curl_exec($handle);
+ $info = curl_getinfo($handle);
+ curl_close($handle);
+
+ if($info['http_code'] != 200)
+ return false;
+
+ $tempfile = tempnam(dirname($cache), 'dl-');
+ if(false === file_put_contents($tempfile, $return))
+ return false;
+
+ chmod($tempfile, 0644);
+ rename($tempfile, $cache);
+
return true;
}