Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/video/helpers/stream.php
Строк: 92
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VHelper_video_stream
{
    public static function 
url($access, $video_id, $ext, $server_id, $premium = false, $hd = false)
    {
        if (!
$access) {
            return 
FALSE;
        }
        
        
$hd                = ($hd) ? '_hd' : '';
        
$multi_server    = VF::cfg_item('module.video.multi_server');
        if (
$multi_server == '1' && $server_id != '0') {
            
VHelper::load('module.video.server');
            
$server = VHelper_video_server::get($server_id);
            if (
$server) {
                if (
$server['streaming_method'] == 'progressive') {
                    return 
$server['url'].'/'.$ext.'/'.$video_id.$hd.'.'.$ext;
                } elseif (
$server['streaming_method'] == 'pseudostreaming') {
                    if (
$server['lighttpd_secdownload'] == '1') {
                        return 
self::secure_streaming(
                            
$server['streaming_server'],
                            
$server['lighttpd_url'],
                            
$server['lighttpd_prefix'],
                            
$video_id,
                            
$ext,
                            
$server['lighttpd_key'],
                            
$hd
                        
);
                    } else {
                        return 
$server['lighttpd_url'].'/media/videos/'.$ext.'/'.$video_id.$hd.'.'.$ext;
                    }
                } elseif (
$server['streaming_method'] == 'rtmp') {
                    
$file    = ($ext == 'mp4') ? 'mp4/'.$video_id.$hd.'.mp4' : 'flv/'.$video_id;
                    return array(
                        
'stream'    => $server['rtmp_stream'],
                        
'file'         => $file
                    
);
                } else {
                    return 
FALSE;
                }
            } else {
                return 
FALSE;
            }
        }
        
        
$vcfg    = ($premium === TRUE) ? VF::cfg('module.premium') : VF::cfg('module.video');
        if (
$vcfg['streaming_method'] == 'progressive') {
            return 
MEDIA_URL.'/videos/'.$ext.'/'.$video_id.$hd.'.'.$ext;
        } elseif (
$vcfg['streaming_method'] == 'pseudostreaming') {
            if (
$vcfg['streaming_secure'] == '1') {
                return 
self::secure_streaming(
                    
$vcfg['streaming_server'],
                    
$vcfg['streaming_url'],
                    
$vcfg['streaming_prefix'],
                    
$video_id,
                    
$ext,
                    
$vcfg['streaming_key'],
                    
$hd
                
);
            } else {
                return 
$vcfg['streaming_url'].'/media/videos/'.$ext.'/'.$video_id.$hd.'.'.$ext;
            }
        } elseif (
$vcfg['streaming_method'] == 'rtmp') {
            
$file    = ($ext == 'mp4') ? 'mp4/'.$video_id.$hd.'.mp4' : 'flv/'.$video_id;
            return array(
                
'stream'    => $vcfg['rtmp_stream'],
                
'file'         => $file
            
);
        }
        
        return 
FALSE;
    }
    
    public static function 
url_mobile($access, $video_id, $server_id, $premium=FALSE)
    {
        if (!
$access) {
            return 
FALSE;
        }
        
        
$multi_server    = VF::cfg_item('module.video.multi_server');
        if (
$multi_server == '1' && $server_id != '0') {
            
VHelper::load('module.video.server');
            
$server = VHelper_video_server::get($server_id);
            if (
$server) {
                if (
$server['streaming_method'] == 'progressive') {
                    return 
$server['url'].'/mobile/'.$video_id.'.mp4';
                } elseif (
$server['streaming_method'] == 'pseudostreaming') {
                    if (
$server['lighttpd_secdownload'] == '1') {
                        return 
self::secure_streaming(
                            
$server['streaming_server'],
                            
$server['lighttpd_url'],
                            
$server['lighttpd_prefix'],
                            
$video_id,
                            
'mobile',
                            
$server['lighttpd_key']
                        );
                    } else {
                        return 
$server['lighttpd_url'].'/media/videos/mobile/'.$video_id.'.mp4';
                    }
                } elseif (
$server['streaming_method'] == 'rtmp') {
                    return 
$server['url'].'/mobile/'.$video_id.'.mp4';
                } else {
                    return 
FALSE;
                }
            } else {
                return 
FALSE;
            }
        }
        
        
$vcfg    = ($premium === TRUE) ? VF::cfg('module.premium') : VF::cfg('module.video');
        if (
$vcfg['streaming_method'] == 'progressive') {
            return 
MEDIA_URL.'/videos/mobile/'.$video_id.'.mp4';
        } elseif (
$vcfg['streaming_method'] == 'pseudostreaming') {
            if (
$vcfg['streaming_secure'] == '1') {
                return 
self::secure_streaming(
                    
$vcfg['streaming_server'],
                    
$vcfg['streaming_url'],
                    
$vcfg['streaming_prefix'],
                    
$video_id,
                    
'mobile',
                    
$vcfg['streaming_key']
                );                
            } else {
                return 
$vcfg['streaming_url'].'/media/videos/mobile/'.$video_id.'.mp4';
            }        
        } elseif (
$vcfg['streaming_method'] == 'rtmp') {
            return 
MEDIA_URL.'/videos/mobile/'.$video_id.'.mp4';
        }
        
        return 
FALSE;
    }
    
    private static function 
secure_streaming($type, $url, $prefix, $video_id, $ext, $key, $hd = '')
    {
        if (
$type == 'lighttpd') {
            return 
self::secure_lighttpd($url.$prefix, $video_id, $ext, $key, $hd);
        } elseif (
$type == 'apache') {
            return 
self::secure_apache($url, $video_id, $ext, $key, $hd);
        } elseif (
$type == 'nginx') {
            return 
self::secure_nginx($url, $video_id, $ext, $key, $hd);
        } else {
        }
    }
    
    public static function 
secure_lighttpd($url, $video_id, $ext, $key, $hd)
    {
        
$file    = ($ext == 'mobile') ? '/mobile/'.$video_id.'.mp4' : '/'.$ext.'/'.$video_id.$hd.'.'.$ext;
        
$hex    = sprintf("%08x", time());
       
        return 
$url.md5($key.$file.$hex).'/'.$hex.$file;       
    }
    
    public static function 
secure_apache($url, $video_id, $ext, $key, $hd)
    {
        
$file   = ($ext == 'mobile') ? '/'.$video_id.'.mp4' : '/'.$video_id.$hd.'.'.$ext;
        
$path   = ($ext == 'mobile') ? '/media/videos/mobile/' : '/media/videos/'.$ext.'/';
        
$expire = dechex(time() + 7200);
        
$ip     = VServer::ip(FALSE);

        
$token  = md5($key . $file . $expire .$ip);

        return 
$url.$path.$token.'/'.$expire.$file;    
    }
    
    public static function 
secure_nginx($url, $video_id, $ext, $key, $hd)
    {
          
$file   = ($ext == 'mobile') ? '/mobile/'.$video_id.'.mp4' : '/'.$ext.'/'.$video_id.$hd.'.'.$ext;
          
$file   = '/media/videos'.$file;
          
$expire = time() + 7200;
          
$ip        = VServer::ip(FALSE);

          
$md5    = base64_encode(md5($key . $file . $expire . $ip, true));
          
$md5    = strtr($md5, '+/', '-_');
          
$md5    = str_replace('=', '', $md5);

        
$arg    = '?st='.$md5.'&e='.$expire;
        if (
$ext != 'mobile') {
            
$arg    = urlencode($arg);
        }

          return 
$url.$file.$arg;
    }    
}
Онлайн: 2
Реклама