Foros del Web » Programando para Internet » PHP »

Como autopostear videos de Youtube

Estas en el tema de Como autopostear videos de Youtube en el foro de PHP en Foros del Web. Buenas a todos, Antes que nada felicitar a todos los que haceis posible esta gran comunidad, la cual leo desde hace bastante tiempo aunque nunca ...
  #1 (permalink)  
Antiguo 03/11/2012, 15:14
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 5 meses
Puntos: 0
Pregunta Como autopostear videos de Youtube

Buenas a todos,
Antes que nada felicitar a todos los que haceis posible esta gran comunidad, la cual leo desde hace bastante tiempo aunque nunca hubiese participado.

Tengo una duda, me gustaría saber como sería posible autopostear videos de Youtube..
Me explico, necesito realizar un sistema el cual postee los nuevos videos de una cuenta de youtube (Una cuenta donde subo un video al dia).. con lo cual lo unico que debe hacer es copiar y pegar el nuevo enlace y mostrarlo en forma de noticia..

¿Alguien sabe si existe algún script que haga tal función?
¿Como podría hacerlo?


Gracias!
  #2 (permalink)  
Antiguo 03/11/2012, 15:30
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Como autopostear videos de Youtube

¿Youtube no provee de RSS?

Podrías usar cualquier lector de feeds RSS para hacer eso, sin necesidad de crear ningún sistema.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 03/11/2012, 15:36
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Como autopostear videos de Youtube

Cita:
Iniciado por pateketrueke Ver Mensaje
¿Youtube no provee de RSS?

Podrías usar cualquier lector de feeds RSS para hacer eso, sin necesidad de crear ningún sistema.
Que cierto compañero!! muchisimas gracias!! No sabia que Youtube tenia RSS .. que tonto.

http://gdata.youtube.com/feeds/base/users/MICANAL/uploads

que me recomiendas para autopostear los videos Joomla, wordpress..?
Sabes si Tumblr tiene lector de rss?

Gracias por tu ayuda.
  #4 (permalink)  
Antiguo 03/11/2012, 15:42
 
Fecha de Ingreso: julio-2010
Mensajes: 127
Antigüedad: 13 años, 9 meses
Puntos: 2
Respuesta: Como autopostear videos de Youtube

Puedes hacer tu propio sistema... encontre esto en internet es un sistema espero que te sirva:

Cita:
<?php
/* Todo esto se puede poner en un require :D */
class RssReader {
var $url;
var $data;

function RssReader ($url){
$this->url;
$this->data = implode ("", file ($url));
}

function get_items (){
preg_match_all ("/<item .*>.*<\/item>/xsmUi", $this->data, $matches);
$items = array ();
foreach ($matches[0] as $match){
$items[] = new RssItem ($match);
}
return $items;
}
}

class RssItem {
var $title, $url, $description;

function RssItem ($xml){
$this->populate ($xml);
}

function populate ($xml){
preg_match ("/<title> (.*) <\/title>/xsmUi", $xml, $matches);
$this->title = $matches[1];
preg_match ("/<link> (.*) <\/link>/xsmUi", $xml, $matches);
$this->url = $matches[1];
preg_match ("/<description> (.*) <\/description>/xsmUi", $xml, $matches);
$this->description = $matches[1];
}

function get_title (){
return iconv('UTF-8', 'ISO-8859-1', $this->title);
}

function get_url (){
return iconv('UTF-8', 'ISO-8859-1', $this->url);
}

function get_description (){
return iconv('UTF-8', 'ISO-8859-1', $this->description);
}
}


//Ejemplo de como usarlo
$rss = new RssReader ("http://gdata.youtube.com/feeds/base/users/MICANAL/uploads");

foreach ($rss->get_items () as $item){
printf ('<a href="%s">%s</a><br />%s<br /><br />',
html_entity_decode($item->get_url ()),
html_entity_decode($item->get_description ()),
html_entity_decode($item->get_title ()));
}
?>
__________________
Mi ultima web.
  #5 (permalink)  
Antiguo 04/11/2012, 09:18
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Como autopostear videos de Youtube

Cita:
Iniciado por rodojpm Ver Mensaje
Puedes hacer tu propio sistema... encontre esto en internet es un sistema espero que te sirva:
Para youtube no me funciona...
Encontré este otro codigo para Youtube pero solo me muestra los titulos de los videos...
Me gustaría que se mostrara los titulos con un enlace y una miniatura pero no se hacerlo...

Dejo el codigo :

Código:
<?php 

/* 
Created by Global Syndication's RSS Parser 
[url]http://www.globalsyndication.com/rss-parser[/url] 
*/ 



$file = "http://gdata.youtube.com/feeds/api/users/MICANAL/uploads"; 

$rss_channel = array(); 
$currently_writing = ""; 
$main = ""; 
$item_counter = 0; 


function startElement($parser, $name, $attrs) 
{    global $rss_channel, $currently_writing, $main; 
    switch($name) 
    {    case "RSS": 
        case "RDF:RDF": 
        case "ITEMS": 
            $currently_writing = "";    break; 
        case "CHANNEL":    $main = "CHANNEL";    break; 
          case "PLAYER": 
            $main = "PLAYER"; 
            $rss_channel["PLAYER"] = array(); 
            break; 
        case "ENTRY":    $main = "ENTRYS";    break; 
        default:    $currently_writing = $name;        break; 
      } 
} 

function endElement($parser, $name) 
{    global $rss_channel, $currently_writing, $item_counter; 
    $currently_writing = ""; 
    if($name == "ENTRY") 
    {    $item_counter++;} 
} 

function characterData($parser, $data) 
{    global $rss_channel, $currently_writing, $main, $item_counter; 
    if($currently_writing != "") 
    {    switch($main) 
        {    case "CHANNEL": 
                if(isset($rss_channel[$currently_writing])) 
                {    $rss_channel[$currently_writing] .= $data;} 
                else 
                {    $rss_channel[$currently_writing] = $data;} 
                break; 
            case "PLAYER": 
                if(isset($rss_channel[$main][$currently_writing])) 
                {    $rss_channel[$main][$currently_writing] .= $data;} 
                else 
                {    $rss_channel[$main][$currently_writing] = $data;} 
                break; 
            case "ENTRYS": 
                if(isset($rss_channel[$main][$item_counter][$currently_writing])) 
                {    $rss_channel[$main][$item_counter][$currently_writing] .= $data;} 
                else 
                {    $rss_channel[$main][$item_counter][$currently_writing] = $data;} 
                break; 
        } 
    } 
} 

$xml_parser = xml_parser_create(); 
xml_set_element_handler($xml_parser, "startElement", "endElement"); 
xml_set_character_data_handler($xml_parser, "characterData"); 
if (!($fp = fopen($file, "r"))) 
{    die("could not open XML input");} 

while($data = fread($fp, 4096)) 
{    if(!xml_parse($xml_parser, $data, feof($fp))) 
    {    die(sprintf("XML error: %s at line %d",xml_error_string(xml_get_error_code($xml_parser)),xml_get_current_line_number($xml_parser))); 
    } 
} 
xml_parser_free($xml_parser); 

// output HTML 


if(isset($rss_channel["ENTRYS"])) 
{    if(count($rss_channel["ENTRYS"]) > 0) 
    {    for($i = 0;$i < count($rss_channel["ENTRYS"]);$i++) 
        {    if (isset($rss_channel["ENTRYS"][$i]["LINK"])) 
            {print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ENTRYS"][$i]["PLAYER"] . "\" target=\"_blanck\">" . utf8_decode($rss_channel["ENTRYS"][$i]["PLAYER"]) . "</a></div>");} 
            else 
            {print ("\n<div class=\"itemtitle\">" . utf8_decode($rss_channel["ENTRYS"][$i]["TITLE"]) . "</div>");} 
        } 
    }else 
    {    print ("<b>There are no articles in this feed.</b>");} 
} 


?>
  #6 (permalink)  
Antiguo 04/11/2012, 09:37
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Como autopostear videos de Youtube

Encontré este codigo que lo que hace es mostrar los videos de la forma que quiero... pero debes indicar el video no puedes poner el rss.. si alguien me pudiese ayudar a adaptarlo por favor

Este es el codigo

Código:
<?php
/* 
 * Name: Simple Class Info YouTube 
 * Description: Get Information of video YouTube
 * Development: Chuecko
 * Site: http://www.zarpele.com.ar
 * License: GNU GENERAL PUBLIC LICENSE (http://www.gnu.org/licenses/gpl.html)
 * Version: 1.0
 */

class youtube
{
    var $data = '';
    var $id = '';

    public function youtube($id)
    {
        if (strlen($id) >=22)
        {
            parse_str( parse_url( $id, PHP_URL_QUERY ) );
            $this->id = $v;
        }
        else
        {
            $this->id=$id;
        }

        $url = "http://gdata.youtube.com/feeds/videos/".$this->id;
        $browser_id = "none";
        $curl_handle = curl_init();
        $options = array
        (
            CURLOPT_URL=>$url,
            CURLOPT_HEADER=>false,
            CURLOPT_RETURNTRANSFER=>true,
            CURLOPT_USERAGENT=>$browser_id
        );
        curl_setopt_array($curl_handle,$options);
        $server_output = curl_exec($curl_handle);
        curl_close($curl_handle);

        $this->data=$server_output;
    }

    public function getTitle()
    {
        $startString = "<media:title type='plain'>";
        $endString = "</media:title>";

        $tempString = strstr($this->data, $startString);

        $endLocation = strpos($tempString, $endString);
        $title = substr($tempString, 0, $endLocation);

        if (empty($title))
        {
            $title=false;
        }
        else
        {
            $title=substr($title,strlen($startString));
        }

        return $title;
    }

    public function getPublished()
    {
        $startString = "<published>";
        $endString = "</published>";

        $starLocation = strpos($this->data, $startString);
        $tempString = substr($this->data, $starLocation);

        $endLocation = strpos($tempString, $endString);
        $published = substr($tempString, 0, $endLocation);

        if (empty($published))
        {
            $published=false;
        }
        else
        {
            $published=substr($published,strlen($startString));
            $published=substr($published,0,10);
        }

        return $published;
    }

    public function getDescription()
    {
        $startString = "<media:description type='plain'>";
        $endString = "</media:description>";

        $starLocation = strpos($this->data, $startString);
        $tempString = substr($this->data, $starLocation);

        $endLocation = strpos($tempString, $endString);
        $description = substr($tempString, 0, $endLocation);

        if (empty($description))
        {
            $description=false;
        }
        else
        {
            $description=substr($description,strlen($startString));
        }

        return $description;
    }

    public function getMetaTags()
    {
        $startString = "<media:keywords>";
        $endString = "</media:keywords>";

        $starLocation = strpos($this->data, $startString);
        $tempString = substr($this->data, $starLocation);

        $endLocation = strpos($tempString, $endString);
        $metaTags = substr($tempString, 0, $endLocation);

        if (empty($metaTags))
        {
            $metaTags=false;
        }
        else
        {
            $metaTags=substr($metaTags,strlen($startString));
        }

        return $metaTags;
    }

    public function getUrl()
    {
        return "http://www.youtube.com/watch?v=".$this->id;
    }

    public function getUrlImage($option)
    {
        if($option=='default')
        {
            return 'http://i.ytimg.com/vi/'.$this->id.'/default.jpg';
        }
        if($option=='grande')
        {
            return 'http://i.ytimg.com/vi/'.$this->id.'/0.jpg';
        }
        if($option==1)
        {
            return 'http://i.ytimg.com/vi/'.$this->id.'/1.jpg';
        }
        if($option==2)
        {
            return 'http://i.ytimg.com/vi/'.$this->id.'/2.jpg';
        }
        if($option==3)
        {
            return 'http://i.ytimg.com/vi/'.$this->id.'/3.jpg';
        }
    }

    public function getEmbeb($width, $height)
    {
        $autoplay = 1;
        return '<iframe class="youtube-player" type="text/html" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$this->id.'?autoplay='.$autoplay.'" frameborder="0">
        </iframe>';
    }


}

?>

Código:
<?php
/* 
 * Name: Simple Class Info YouTube 
 * Description: Get Information of video YouTube
 * Development: Chuecko
 * Site: http://www.zarpele.com.ar
 * License: GNU GENERAL PUBLIC LICENSE (http://www.gnu.org/licenses/gpl.html)
 * Version: 1.0
 */

require_once 'youtube.class.php';

/*
 * Tambien le pueden pasar como parametro solo el ID de youtube 
 * $youtube = new youtube('59PyU_7iqaU');
 *
 */
$youtube = new youtube('http://www.youtube.com/watch?v=59PyU_7iqaU');

echo 'Titulo: '.$youtube->getTitle().'<br/>';
echo 'Publicado: '.$youtube->getPublished().'<br/>';
echo 'Descripcion: '.$youtube->getDescription().'<br/>';
echo 'Meta Tags: '.$youtube->getMetaTags().'<br/>';
echo 'Link: '.$youtube->getUrl().'<br/>';
echo 'Imagen: '.$youtube->getUrlImage('default').'<br/>';


echo $youtube->getEmbeb(640, 390);

?>
  #7 (permalink)  
Antiguo 04/11/2012, 10:35
 
Fecha de Ingreso: noviembre-2012
Mensajes: 15
Antigüedad: 11 años, 5 meses
Puntos: 0
Respuesta: Como autopostear videos de Youtube

Bueno al final conseguí lo que quería hacer.. Mostrar el titulo con enlace y debajo el video :D
Ahora tengo otro problema que es que no se donde indicar que se muestren menos videos porque me carga como 20 videos y la pagina tarda en cargar...

También me gustaría saber si los ultimos videos irán desapareciendo y si no hay forma de dejarlos y hacer varias paginas (1, 2, 3, 4...) donde se almacenen todos los videos...
Incluso hacer una pagina independiente con url amigable para cada video..

Quizá me estoy complicando de sobremanera y hubiese sido posible con Wordpress crear una entrada por cada video...

Pero no vi nada asi solo vi como incluir información de un canal en un widget pero no vi como crear una entrada en wordpress leyendo el RSS del canal.

Etiquetas: youtube, video
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:34.