Welcome Guest, Not a member yet? Register   Sign In
[youtube]URL[/youtube]
#1

[eluser]EEssam[/eluser]
Hi,

Can anyone tell me please how can I parse the following:

Code:
[youtube]http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1[/youtube]

To:

Code:
&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param>&lt;embed src="http://www.youtube.com/v/PC4HhI0bK4c&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed>&lt;/object&gt;

Thanks.
#2

[eluser]alectrash[/eluser]
I just get link:

http://uk.youtube.com/watch?v=VlBWm_UXbS0

and then get id after 'v' ie VlBWm_UXbS0

i then call this $url and pass to simplepie like so:

Code:
function add_youtube($url)
   {
    $this->load->library('simplepie');
        
    // code by fellow sheffield lad and leicester based php guru fiaz khan of nextbigleap.com
    // $this->simplepie->feed_url(’http://www.digg.com/rss/indexdig.xml’);
    // You may have encountered an error where it couldn’t find feed_url. This is due
    // to a change in the latest version of simplepie. Simply, feed_url is now set_feed_url
    //$this->simplepie->set_cache_location('/var/www/html/system/application/cache/');
    $this->simplepie->set_cache_location(BASEPATH . 'cache');
    $this->simplepie->set_feed_url("http://gdata.youtube.com/feeds/videos?vq=" . $url);
    $this->simplepie->init();
    $video_feed = $this->simplepie;
    
    foreach($video_feed->get_items() as $item)
    {      
        if($enclosure = $item->get_enclosure())
          {  
            //get video title
          $data['video_title'] = $item->get_title();
          //get video author
          $data['video_author'] =  $item->get_author();
          $data['video_author'] =  $data['video_author']->get_name();
          //get video tags
            $data['video_tags'] = $enclosure->get_keywords();
            $tags = "";
              foreach($data['video_tags'] as $tag)
              {
                $tags = $tag . " " . $tags;
              }
          $data['video_tags'] = $tags;
          //get video category
          $data['video_category'] = $enclosure->get_category();
          $data['video_category'] =  $data['video_category']->get_label();
          //get video description
          $data['video_description'] = $enclosure->get_description();
          //get video thumbnail
          $data['video_thumbnail'] = $enclosure->get_thumbnail();      
        }
    }
    
    if($data['video_thumbnail'] != "")
    {
      $youtubedata = array('dburl' => $this->make_nice_url($data['video_title']),
                           'dbtitle' => $data['video_title'],
                           'dbdescription' => $data['video_description'],
                           'dbcategory' => $data['video_category'],
                           'dbtags' => $data['video_tags'],  
                           'dbfilename' => $url,
                           'dbthumbimage' => $data['video_thumbnail'],
                           'dbtype' => 'video_youtube',
                           'dbstatus' => 'published',
                           'dbowner' => $this->db_session->userdata('user_name'),
                           'dbauthor' => $this->db_session->userdata('user_name'),
                           'dbdate' => time());
                          
      $this->db->insert('tblmedia', $youtubedata);
      return TRUE;
    }
    else
    {
      return FALSE;
    }
    
   }

get fiaz khans simplepie tutorial here

http://www.nextbigleap.com/blog/developm...deigniter/

enjoy!
#3

[eluser]Jamie Rumbelow[/eluser]
Do a simple preg_replace()...

Code:
preg_replace('[youtube](*.)[/youtube]', '&lt;object width="425" height="344"&gt;&lt;param name="movie" value="$1"></param><param name="allowFullScreen" value="true"></param>&lt;embed src="$1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed>&lt;/object&gt;');
#4

[eluser]Unknown[/eluser]
&lt;?php
// Get Youtube Data Feed With use Of Simple Pie in PHP
// Munir Sunni ( [email protected] )
include('simplepie/simplepie.class.php');

$urlList = array();

$urlList =
(
//List Of Youtube Videos
'http://www.youtube.com/watch?v=D5xxUkLhZe4',
'http://www.youtube.com/watch?v=VBURsTurlH8',
'http://www.youtube.com/watch?v=_qNx7ggPTLc',

//List Of Youtube Channels

'http://www.youtube.com/user/jalil7',
'http://www.youtube.com/user/maddyvora'
);

foreach ($urlList as $videoUrl)
{
// Check that if this Video/channel is actully coming from Youtube or not
if (stristr(strtolower($videoUrl), 'youtube.com'))
{
// Explode all the value through '/' for getting Video/channel ID and stored into array
$linkHref = explode('/', $videoUrl);

// Get the Five Charactor of third value of array to defing that if it is video or channel
$linkHrefText = substr($linkHref[3], 0, 5);

if ($linkHrefText == 'watch')
{
// Get the Video Id of Youtube Video
$urlVars = GetYoutubeUrlVars($videoUrl);
if ($urlVars['v'] != '')
{
$videoAndChannelList[] = 'http://gdata.youtube.com/feeds/videos?vq=' . $urlVars['v'];
}
}
else
{
// Get the Channel Id of Youtube Channel
$channelName = ($linkHref[3] != 'user') ? $linkHref[3] : $linkHref[4];
$videoAndChannelList[] = 'http://gdata.youtube.com/feeds/api/users/'. $channelName .'/uploads';
}
}
}


$feed = new SimplePie();
$feed->set_cache_location('SimplePie/cache');

//Put the List of channel/videos from which you get Videos
$feed->set_feed_url($videoAndChannelList);
$feed->init();
$feed->handle_content_type();

$items = $feed->get_items();
$items = array_slice($items, 0, 50, true);

foreach ($items as $item)
{
$date = $item->get_date('U');
$link = $item->get_permalink();
$enclosure = $item->get_enclosure();
if ($enclosure)
{
$title = $enclosure->get_title();
$duration = $enclosure->duration;
$thumb = $enclosure->get_thumbnail();
$description = $enclosure->get_description();
}

if (empty($link))
$link = $item->feed->feed_url;

$object = null;
$object->Title = $title;
$object->Date = $date;
$object->Link = $link;
$object->Description = $description;
$object->Duration = $duration;
$object->Thumb = $thumb;

$externalVideos[] = $object;
}
echo '<pre>';
print_r($externalVideos);

function GetYoutubeUrlVars($url)
{
$vars = array();
$urlstr = substr($url, strpos($url, '?') + 1, strlen($url));

$urlargs = explode('&',$urlstr);
foreach ($urlargs as $arg)
{
$exploded = explode('=', $arg);

if (count($exploded) > 1)
$vars[$exploded[0]] = $exploded[1];
}

return $vars;
}
?&gt;
Quote:




Theme © iAndrew 2016 - Forum software by © MyBB