summaryrefslogtreecommitdiff
path: root/classes/urlhelper.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/urlhelper.php')
-rw-r--r--classes/urlhelper.php33
1 files changed, 30 insertions, 3 deletions
diff --git a/classes/urlhelper.php b/classes/urlhelper.php
index 55d5d1e6a..edfb2ad73 100644
--- a/classes/urlhelper.php
+++ b/classes/urlhelper.php
@@ -271,10 +271,15 @@ class UrlHelper {
// holy shit closures in php
// download & upload are *expected* sizes respectively, could be zero
- curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) {
- Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
+ curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use(&$max_size, $url) {
+ //Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
- return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it
+ if ($downloaded > $max_size) {
+ Debug::log("curl: reached max size of $max_size bytes requesting $url, aborting.", Debug::LOG_VERBOSE);
+ return 1;
+ }
+
+ return 0;
});
}
@@ -482,4 +487,26 @@ class UrlHelper {
}
}
+ public static function url_to_youtube_vid($url) {
+ $url = str_replace("youtube.com", "youtube-nocookie.com", $url);
+
+ $regexps = [
+ "/\/\/www\.youtube-nocookie\.com\/v\/([\w-]+)/",
+ "/\/\/www\.youtube-nocookie\.com\/embed\/([\w-]+)/",
+ "/\/\/www\.youtube-nocookie\.com\/watch?v=([\w-]+)/",
+ "/\/\/youtu.be\/([\w-]+)/",
+ ];
+
+ foreach ($regexps as $re) {
+ $matches = [];
+
+ if (preg_match($re, $url, $matches)) {
+ return $matches[1];
+ }
+ }
+
+ return false;
+ }
+
+
}