• 0

YouTube PHP Script?


Question

I'm looking for a script that will PULL my videos from youtube and display them in a list or whatever.

I've transfered all my websites vids to youtube and at the moment i'm just linking to the youtube page but would love to integrate it into my website properly.

does such a thing exist?

Link to comment
https://www.neowin.net/forum/topic/894566-youtube-php-script/
Share on other sites

17 answers to this question

Recommended Posts

  • 0
  On 22/04/2010 at 10:12, njlouch said:

No problems. They may have API's to integrate with, but that was the simplest option in my mind - that said, I don't know what restrictions it may have (max count, etc)

Just out of curiosity, anyway in getting that in JSON format? :p

  • 0

I'm looking at the XML file now.

<div class="entry">
 	<h3><a href="http://www.youtube.com/watch?v=5pfu1b63s20&feature=youtube_gdata">Vibee Studio, Durham 01-10-2009 Part 2</a>

How would i grab the title from that?

I've been looking online and it suggests using GetElementById or TagName but it does't have an Id.

(n00b)

  • 0

I personally use SimplePie's class for XML parsing and feed fetching. You may want to look at it. It just makes it easier.

  On 22/04/2010 at 10:12, njlouch said:

They may have API's to integrate with, but that was the simplest option in my mind - that said, I don't know what restrictions it may have (max count, etc)

As long as you cache the feeds you are fine (insert the records in database etc). If you don't and your website gets alot of hits, then the server will get banned eventually. That said, fetching the feed like once in a hour and you should be fine.

  • 0
  On 22/04/2010 at 12:59, Gocom said:

I personally use SimplePie's class for XML parsing and feed fetching. You may want to look at it. It just makes it easier.

As long as you cache the feeds you are fine (insert the records in database etc). If you don't and your website gets alot of hits, then the server will get banned eventually. That said, fetching the feed like once in a hour and you should be fine.

Wow that's amazing i'm already up and running.

One problem is the links are coming out like this:

http://www.youtube.c...3Dyoutube_gdata

i quickly tried:

$replace = str_replace("%3D", "=", $item);

which did change the link in the URL on the page, but when it's clicked it takes you to this:

http://www.youtube.c...3Dyoutube_gdata

This is the full code i used:

<?
foreach ($feed->get_items() as $item): ?>
<div class="item">
<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>

<p><?php echo $item->get_description(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?> 

  • 0

Thanks it worked great :-)

Is it now possible to limit this to show a certain number of videos? a limit on the loop.

This is the code now:

 <? foreach ($feed->get_items() as $item): ?> 	
<div style="padding:15px;"> 	
<h2><a href="<?php echo urldecode($item->get_permalink()); ?>"><?php echo $item->get_title(); ?></a></h2> 	
<p><?php echo $item->get_description(); ?></p> 	
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p> 	
</div> 	
<?php endforeach; ?> 

  • 0

You could switch to a regular for-loop from 0 to n.

<?php
$items = feed->get_items();
for ($i = 0; $i < 5; ++$i) {
    $item = $items[$i];
    // Output item
}
?>

You could also keep the foreach-loop and add a key enumerator variable. After this enumerator hits n, you break out of the loop before outputting the next item.

<?php
foreach ($feed->get_items() as $i => $item) {
    if($i >= 5) break;
    // Output item
}
?>

Of course, it would be better and more efficient if you'd put the limit directly on the get_items() function or even on the feed request query itself rather than retrieving all items and then only using some.

  • 0
  On 22/04/2010 at 18:09, Calculator said:

Of course, it would be better and more efficient if you'd put the limit directly on the get_items() function or even on the feed request query itself rather than retrieving all items and then only using some.

Yep. See get_items().

foreach($feed->get_items(0,5) as $item) [...]

  • 0

I've found that Youtube thumbnails all contain a url such as:

http://img.youtube.com/vi/*VIDEO_ID*/2.jpg

So i created a line of code to strip the VIDEO_ID out of the url:

$thumb = substr(urldecode($item->get_permalink()),strpos(urldecode($item->get_permalink()),"="),11);

This SHOULD grab all 11 characters after the =

But it's showing the string as:

=IW3wM5s5OE

Now what would i use to remove the "=" from the string?

I've tried a few replace functions but it doesn't seem to be working.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Amazon Deals: Samsung Q990F Q900F Q800F 2025 Dolby Atmos soundbars with wireless subwoofers by Sayan Sen While separate AV receivers with hi-fi speakers are generally the preferred way to listed to music and watch movies/shows by audiophiles, the more general folks often prefer soundbars instead as they offer a capable all in one solution that is still plenty good. Currently Nakamichi is running discounts on multiple products from its Dragaon lineup as well as its Shockwafe model. If you are looking for more options to choose from Samsung has its Q-series products at lowest prices (purchase links towards the end of article). Q990F The flagship Q990F is an 11.1.4 system and the single subwoofer unit on it houses two opposite-facing 8-inch subwoofer drivers. Thus, together they move around the same amount of air as a single 12-inch subwoofer unit. In addition to increasing the bass by +3 dB, dual opposing drivers are also said to help reduce vibrations of the subwoofer cabinet by cancelling out the resonance. Samsung also says that the bass is "AI-optimized" but we are not sure if it actually helps or if it's just a buzz term here. Aside from the bass, dialogue in movies is the second most important thing, and Samsung claims great vocal clarity from its front speakers thanks to AVA (Active Voice Amplifier) Pro feature that is said to detect noise disturbances and amplify dialogue to make it more audible over such surrounding noises. Q900F Feature wise the Q900F is similar to the 990F model except it has fewer channels and it is a 7.1.2 setup. Finally the Q800F is a 5.1.2 system and it has a passive radiator instead of the additonal subwoofer driver unit. Get the Samsung Q series soundbars at the links below: Samsung Q990F 11.1.4ch Wireless Dolby Atmos, Q-Symphony, Game Mode Pro, Adaptive Sound (HW-Q990F, 2025): $1497.99 (Shipped and Sold by Amazon US) Samsung HW-Q900F 7.1.2 ch Wireless Dolby Atmos, Q-Symphony: $997.99 (Shipped and Sold by Amazon US) Samsung Q800F 5.1.2ch Q Series Soundbar + Subwoofer, Wireless Dolby Atmos, Q-Symphony, Game Mode Pro, Smart Integration (HW-Q800F, 2025): $697.99 (Shipped and Sold by Amazon US) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • They are shifting into AI now. Don't you see?
    • Exactly. No need to pay to rent a license. I'd rather own it.
  • Recent Achievements

    • One Month Later
      Helen Shafer earned a badge
      One Month Later
    • One Month Later
      ambani880 earned a badge
      One Month Later
    • Week One Done
      ambani880 earned a badge
      Week One Done
    • First Post
      artistro08 earned a badge
      First Post
    • First Post
      paul29 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      ATLien_0
      223
    3. 3
      Michael Scrip
      196
    4. 4
      Xenon
      160
    5. 5
      +FloatingFatMan
      138
  • Tell a friend

    Love Neowin? Tell a friend!