Jump to content
Addic73d

Script PHP - GetTrailersFromYoutube

Recommended Posts

Posted (edited)

getTrailersFromYoutube.php


<?php
session_start();
function veziArray($array) {

echo '<pre>';
print_r($array);
echo '</pre>';

}

function xmlstr($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}


$trailereNoi = array('Kung Fu Panda 2', 'John Carter', 'Zookeeper', 'Animals United', 'Magic Trip', 'Crazy, Stupid, Love.', 'Amigo', 'Higher Ground', 'Contagion', 'The Devil\'s Double', 'Friends with Benefits', 'Harry Potter and the Deathly Hallows - Part 2', 'The Pirates! Band of Misfits', 'Hugo', 'Winnie the Pooh');

foreach($trailereNoi as $nume) {
$sursa = file('http://www.youtube.com/results?search_query='.urlencode($nume).'official+trailer+2011+[HD]+&aq=f');
$i = 380;
while($i <= 420) {
$link = $sursa[$i];
$getLink = xmlstr($link, ' <a href="', '"');
$completeLink = 'http://www.youtube.com'.$getLink;

if(strlen($completeLink) == 42) {

// echo "<a href=$completeLink>$nume</a><br />";
echo '<a href="trailer.php?film='.urlencode($nume).'&link='.$getLink.'">'.$nume.'</a><br />';

}


$i++;
}
}

?>

trailer.php


<?php
function veziArray($array) {

echo '<pre>';
print_r($array);
echo '</pre>';

}

function xmlstr($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}

if(isset($_GET['link'])) {
$link = $_GET['link'];
$trailerPage = file_get_contents('http://www.youtube.com'.$link);
$trailer = xmlstr($trailerPage, '<embed type="application/x-shockwave-flash"', 'bgcolor="#000000">');
echo '<embed type="application/x-shockwave-flash"'.$trailer.'bgcolor="#000000">';


}

?>

L-am testet pe localhost si merge foarte bine, cu optiunea ca getTrailersFromYoutube.php se incarca mai greu datorita faptului ca nu am stat sa filtrez continutul in care s-a facut search.

Ideea e ca, in momentul in care verific script-ul din exteriorul localhost-ului, sau il pun pe host in locul trailerului imi apare "Am intampinat o eroare, incercati mai tarziu".

Ceva idei??

Edited by Addic73d

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...