bankera1990
Registered
Здравейте интересува ме как мога да взема субтитри от клип в вбокса като .srt с помощта на php скрипт
<?php
$url = "http://vbox7.com/play:b74ece70fa";
$vid = end(explode(":",$url));
$ext = base64_encode("http://www.vbox7.com/etc/ext.do?key=".$vid);
echo '<a href="http://www.infosphere.org/tools/subtitles/?subs='.$ext.'&domain=vbox7.com&v='.$vid.'">Download</a>';
?>
<?php
// Author: proba
// web-tourist.net
ob_start();
echo "<form method='POST'>";
echo "URL: <input type='text' name='url'> <input type='submit' name='submit' value='Download'>";
echo "</form>";
if (isset($_POST['submit']))
{
$url = htmlspecialchars($_POST['url']);
$urlex = explode(":",$url);
if (preg_match("/vbox7.com/i",$urlex[1]) and preg_match("/play/i",$urlex[1]) and strlen($urlex[2]) == 10)
{
$extdo = "http://www.vbox7.com/etc/ext.do?key=".$urlex[2];
$extdo_open = file_get_contents($extdo);
if (!preg_match("/errorInfo/i",$extdo_open))
{
$flv_get1 = explode("flv_addr=",$extdo_open);
$flv_get2 = explode("&",$flv_get1[1]);
$flv_file = $flv_get2[0];
$img_get1 = explode("jpg_addr=",$extdo_open);
$img_get2 = explode("&",$img_get1[1]);
$img_file = "http://".$img_get2[0];
echo "<form method='POST' name='step2'>";
echo "<img src='$img_file' /><br />";
echo "<input type='hidden' name='extdo' value='".base64_encode($extdo)."' />";
echo "<input type='hidden' name='vid' value='$urlex[2]' />";
echo "<input type='hidden' name='url' value='$url' />";
echo "<input type='hidden' name='flvurl' value='$flv_file' />";
echo "<input type='hidden' name='submit' value='Download' />";
echo "<input type='submit' name='flvdown' value='Download Video' /> ";
echo "<input type='submit' name='subsdown' value='Download Subtitles' />";
echo "</form>";
if (isset($_POST['flvdown']))
{
header("Location: http://".$_POST['flvurl']);
}
if (isset($_POST['subsdown']))
{
header("Location: http://www.infosphere.org/tools/subtitles/?subs=".$_POST['extdo']."&domain=vbox7.com&v=".$_POST['vid']);
}
}
else
{
echo "Видео клипът не е намерен.";
}
}
else
{
echo "Невалиден URL.";
}
}
?>
Weezy каза:Първият код е добре, но вторият нещо ти дава еврори.
<?php
/*
Version: 0.1
Author: Milen Ivanov / criobot<at>gmail<dot>com
*/
define("VBOX7_TITLE", 1);
define("VBOX7_SUBTITLES", 2);
class vbox7{
public $url = null;
public $code = null;
public $title = null;
public $thumbnail = null;
public $flvUrl = null;
public $subtitles = null;
public $subtitlesExtension = 'srt';
public function __construct($url, $flags = VBOX7_FLVURL){
if(preg_match("/.*play:([a-fA-F0-9]{8})/",$url, $match)){
$this->url = $match[0];
$this->code = $match[1];
if( ($FLAGS & VBOX7_TITLE) == true ){
$src = file_get_contents($this->url);
if(preg_match("/<title>(.*) \/ VBOX7<\/title>/", $src, $found)){
$this->title = $found[1];
}
}
$src = file_get_contents("http://www.vbox7.com/etc/ext.do?key=".$this->code."&antiCacheStamp=1234");
if(preg_match("/&flv_addr=(.*?)&jpg_addr=(.*?)&subsEnabled=(?:true&subsData=)?(.*?)&related=[0-1]$/", $src, $parts)){
$this->flvUrl = "http://".$parts[1];
$this->thumbnail = "http://".$parts[2];
if(($flags & VBOX7_SUBTITLES) == true){
if($parts[3]){
if($subs == 'srt'){
$subs = new SRTFile(json_decode($parts[3]));
}else{
$subs = new SUBFile(json_decode($parts[3]));
$this->subtitlesExtension = 'sub';
}
$this->subtitles = $subs->parse();
}
}
}
}else{
throw new Exception("Невалиден линк");
}
}
}
/**
* SRT File Class
* 1\r\n
* 00:00:04,680 --> 00:00:08,500\r\n
* Кой даде идеята?\r\n
* - Ти.\r\n
* \r\n
*
*/
class SRTFile{
private $source = null;
public function __construct($src){
if($src)
$this->source = $src;
}
public function parse(){
$number = 1;
$return = "";
for($i=0; $i<sizeof($this->source);$i++){
$return .= ($i+1) . "\r\n";
$return .= $this->formatTime($this->source[$i]->f) . " --> " . $this->formatTime($this->source[$i]->t) . "\r\n";
$return .= str_replace("<br>", "\r\n", $this->source[$i]->s . "\r\n");
$return .= "\r\n";
}
return $return;
}
private function leadingNull($number){
if($number < 10) return "0".$number;
return $number;
}
private function formatTime($seconds){
$hours = $this->leadingNull((int)($seconds/360));
$minutes =$this->leadingNull((int)($seconds/60));
$seconds = $this->leadingNull($seconds - (((int)($seconds/360))*360 + ((int)($seconds/60))*60));
return $hours.":".$minutes.":".$seconds.",000";
}
}
/**
* SUB File Class
* {from*fps}{to*fps}Content(nl as |)\r\n
*
*/
class SUBFile{
private $source = NULL;
public function __construct($src){
if($src)
$this->source = $src;
}
public function parse($fps = 30){
//Свалих 2-3 клипа от vbox7 и всичките бяха с FPS 30.0 така, че го оставям така по подразбиране.
$return = "";
for($i=0; $i<sizeof($this->source);$i++){
$return .= "{". $fps * $this->source[$i]->f ."}{" . $fps * $this->source[$i]->t . "}" . $this->newLineFix($this->source[$i]->s) . "\r\n";
}
return $return;
}
public function newLineFix($string){
$nl = array("\r\n", "\r", "\n", "<br>");
return str_replace($nl, "|", $string);
}
}
$x = new vbox7("http://vbox7.com/play:87ae93cf", VBOX7_SUBTITLES);
echo $x->subtitles;
if(isset($_POST['link'])){
$link = $_POST['link'];
$format = $_POST['type'];
if(preg_match("/[?:http:\/\/](?:www\.)?(vbox7.com|zazz.bg)\/play:[0-9a-fA-F]{8}.*?/i", $link)){
if($_POST['download'] == 'subs'){
$clip = new vbox7($link, $format==0? "srt": "sub");
if($clip->subtitles){
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$clip->code.'.'.$clip->subtitlesExtension.'"');
echo $clip->subtitles;
}else{
echo 'No subtitles found.';
}
}else{
$clip = new vbox7($link);
if($clip->flvUrl){
header('Location: '.$clip->flvUrl);
}else{
echo 'Error gettin\' FLV\'s URL';
}
}
}else{
echo 'Invalid link';
}
}else{
header("Location: index.html");
}
?>
<?php
/*
Version: 0.1.2
Author: Milen Ivanov / criobot<at>gmail<dot>com
CHANGES:
v.0.1.2
- Updated subtitles support (vbox7 added url encoding to the json subs /how lame/).
v.0.1.1
- Updated subtitles support (SUB newline fix, also etc-link update).
v.0.1
- Init;
*/
class vbox7 {
public $url = null;
public $code = null;
public $title = null;
public $thumbnail = null;
public $flvUrl = null;
public $subtitles = null;
public $subtitlesExtension = 'srt';
public function __construct($url, $subs = 'srt'){
if(preg_match("/.*play:([a-fA-F0-9]{8})/",$url, $match)){
$this->url = $match[0];
$this->code = $match[1];
$src = file_get_contents($this->url);
if(preg_match("/<title>(.*) \/ VBOX7<\/title>/", $src, $found)){
$this->title = $found[1];
}
$src = file_get_contents("http://www.vbox7.com/etc/ext.do?key=".$this->code."&antiCacheStamp=1234");
if(preg_match("/&flv_addr=(.*?)&jpg_addr=(.*?)&subsEnabled=(?:true&subsData=)?(.*?)&related=[0-1]$/", $src, $parts)){
$this->flvUrl = "http://".$parts[1];
$this->thumbnail = "http://".$parts[2];
if($parts[3]){
if($subs == 'sub'){
$subs = new SUBFile(json_decode(urldecode($parts[3])));
$this->subtitlesExtension = 'sub';
}else{
$subs = new SRTFile(json_decode(urldecode($parts[3])));
}
$this->subtitles = $subs->parse();
}
}
} else {
throw new Exception("Невалиден линк");
}
}
}
/**
* SRT File Class
* 1\r\n
* 00:00:04,680 --> 00:00:08,500\r\n
* Кой даде идеята?\r\n
* - Ти.\r\n
* \r\n
*
*/
class SRTFile{
private $source = null;
public function __construct($src){
if($src)
$this->source = $src;
}
public function parse(){
$number = 1;
$return = "";
for($i=0; $i<sizeof($this->source);$i++){
$return .= ($i+1) . "\r\n";
$return .= $this->formatTime($this->source[$i]->f) . " --> " . $this->formatTime($this->source[$i]->t) . "\r\n";
$return .= str_replace("<br>", "\r\n", $this->source[$i]->s . "\r\n");
$return .= "\r\n";
}
return $return;
}
private function leadingNull($number){
if($number < 10) return "0".$number;
return $number;
}
private function formatTime($seconds){
$hours = $this->leadingNull((int)($seconds/360));
$minutes =$this->leadingNull((int)($seconds/60));
$seconds = $this->leadingNull($seconds - (((int)($seconds/360))*360 + ((int)($seconds/60))*60));
return $hours.":".$minutes.":".$seconds.",000";
}
}
/**
* SUB File Class
* {from*fps}{to*fps}Content(nl as |)\r\n
*
*/
class SUBFile{
private $source = NULL;
public function __construct($src){
if($src)
$this->source = $src;
}
public function parse($fps = 30){
//Свалих 2-3 клипа от vbox7 и всичките бяха с FPS 30.0 така, че го оставям така по подразбиране.
$return = "";
for($i=0; $i<sizeof($this->source);$i++){
$return .= "{". $fps * $this->source[$i]->f ."}{" . $fps * $this->source[$i]->t . "}" . $this->newLineFix($this->source[$i]->s) . "\r\n";
}
return $return;
}
public function newLineFix($string){
$nl = array("\r\n", "\r", "\n", "<br>");
return str_replace($nl, "|", $string);
}
}
if(isSet($_POST['link'])){
$link = $_POST['link'];
$format = $_POST['type'];
if(preg_match("/[?:http:\/\/](?:www\.)?(vbox7.com|zazz.bg)\/play:[0-9a-fA-F]{8}.*?/i", $link)){
if($_POST['download'] == 'subs'){
$clip = new vbox7($link, $format==0? "srt": "sub");
if($clip->subtitles){
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="'.$clip->code.'.'.$clip->subtitlesExtension.'"');
echo $clip->subtitles;
}else{
echo 'No subtitles found.';
}
}else{
$clip = new vbox7($link);
if($clip->flvUrl){
header('Location: '.$clip->flvUrl);
}else{
echo 'Error gettin\' FLV\'s URL';
}
}
}else{
echo 'Invalid link';
}
} else {
echo '<form action="?" method="post">
<p>
<label for="address" id="l_address">Пълен адрес на клипа:</label>
<input type="submit" value="Извлечи" id="b_extract" />
<input type="text" name="link" id="address" value=""/>
</p>
</form>
';
}
?>
//elseif(isset($_POST['srtgraber'])){
//$srt = $r['v_url'];
//$url_srt = str_replace("http://vbox7.com/play:", "", $srt);
//$vid = end(explode(":",$url_srt));
//$ext = base64_encode("http://www.vbox7.com/etc/ext.do?key=".$vid);
//$srtvideo = "http://www.infosphere.org/tools/subtitles/?subs=".$ext."&domain=vbox7.com&v=".$vid."";
//$newfile = $_SERVER['DOCUMENT_ROOT'] . '/subtitle/'.$r['id'].'.srt';
//copy($srtvideo, $newfile);
//$srtgraber = mysql_query("UPDATE videos SET subs = '1', subsurl = '".$site_link."/subtitle/".$r['id'].".srt', subuser = '".$_SESSION['username']."' WHERE id = '".$r['id']."'");
//$oks = '<div class="b">Файла е успешно качен! <a href="index.php?p=play&id='.$r['id'].'"><b>» Потвърди</b></a></div><br />';
//}