summaryrefslogtreecommitdiff
path: root/protected/Cache.php
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-04-04 01:11:47 -0700
committeryo mama <pepper@scannerjammer.com>2015-04-04 01:11:47 -0700
commita736da57f084017ac17e06cd9db19b1fd166e1a6 (patch)
tree55a9e83b31f6bdc176731125de0cc42668daf988 /protected/Cache.php
first
Diffstat (limited to 'protected/Cache.php')
-rwxr-xr-xprotected/Cache.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/protected/Cache.php b/protected/Cache.php
new file mode 100755
index 0000000..9a2d46e
--- /dev/null
+++ b/protected/Cache.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Created by IntelliJ IDEA.
+ * User: root
+ * Date: 8/15/13
+ * Time: 11:17 AM
+ * To change this template use File | Settings | File Templates.
+ */
+
+class Cache {
+
+ public function isCached($id){
+ $cachePath = Settings::$CachePath;
+
+ $result = (file_exists($cachePath. DIRECTORY_SEPARATOR .$id)) ? true : false;
+
+ return $result;
+ }
+
+ public function urlToId($url){
+
+ $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $url);
+ //$clean = strtolower(trim($clean, '-'));
+ $clean = preg_replace("/[\/_|+ -]+/", '_', $clean);
+
+ return $clean;
+ }
+
+ public function CacheHttpVideo($url){
+
+ $id = $this->urlToId($url);
+
+ if(file_exists(Settings::$CachePath . $id . ".part")){
+ return false;
+ }
+
+ $speed = Settings::$CacheDownloadMaxSpeed;
+ $r = "";
+ if($speed){
+ $r = " -r $speed ";
+ }
+
+ $command = Settings::$YoutubeDlCommand . " $r -o '" . Settings::$CachePath . "$id" . "' $url";
+
+ $output = exec($command);
+ echo "$output";
+
+ }
+
+} \ No newline at end of file