Пример #1
0
/**
 * ### Gets the full path to the filecache directory
 *
 * @return string
 */
function filecachedir()
{
    return realpath(cachedir() . 'file/') . '/';
}
Пример #2
0
 public function produce_cache_filename()
 {
     //
     // Get the client IP address.
     //
     if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $this->warnx("Proxy configuration error: X-Forwarded-For header not found");
         return;
     }
     $client_ip = trim($_SERVER['HTTP_X_FORWARDED_FOR']);
     if (preg_match('/^[0-9a-f:.]+$/', $client_ip) === 0) {
         $this->warnx("Proxy error: invalid X-Forwarded-For header value: [{$client_ip}]");
         return;
     }
     //
     // Parse the URL and make sure it belongs to a YouTube video.
     //
     $url = parse_url($this->original_url);
     if (!is_array($url) || !is_string($url['query'])) {
         $this->warnx("Invalid URL");
         return;
     }
     parse_str($url['query'], $p);
     if (!is_array($p)) {
         $this->warnx("Invalid query string: [{$url['query']}]");
         return;
     }
     foreach (array('sver', 'itag', 'id') as $n) {
         if (!is_string($p[$n]) || strlen($p[$n]) === 0) {
             $this->warnx("Query parameter [{$n}] not found or empty");
             return;
         }
     }
     if (isset($p['begin'])) {
         //
         // The user is not downloading the whole video, but seeking within it.
         // TODO How to deal with this?
         //      Maybe nginx's FLV module could help.
         //
         $this->warnx("Uncachable: begin is set: [{$p['begin']}]");
     } else {
         if ($p['sver'] != '3') {
             //
             // Stream Version?
             //
             // All requests seem to have this field set to the number 3.
             // If this ever changes, we should look at the new requests to make
             // sure that they are still compatible with this script.
             //
             $this->warnx("Uncachable: sver is not 3: [{$p['sver']}]");
         } else {
             //
             // All values in $p are provided by the user.
             // Do not use them directly in 'fopen()'.
             //
             $this->cache_filename = cachedir($this) . '/' . 'id=' . safe_filename($p['id']) . '.itag=' . safe_filename($p['itag']);
             $this->log_filename = "{$this->cache_filename}." . time() . ".{$client_ip}.log";
             $this->temp_cache_filename = "{$this->cache_filename}." . uniqid(mt_rand() . '_', TRUE) . ".{$client_ip}.tmp";
         }
     }
 }