Cached Youtube API Client (CaYAC)

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
nhaack

Cached Youtube API Client (CaYAC)

Post by nhaack »

CaYAC is a plug-in that allows access of a users youtube feed via smarty. However, it doesn't use the RSS feed, but the latest uploads xml feed from the youtube api. Thus, there is plenty of information we get extra and can use for fancy stuff with extra smarty :)

Download here: http://dev.cmsmadesimple.org/projects/apiyoutubefeed/

Data structure:

Code: Select all

n = integer

$videos [ n ] -> info -> id
$videos [ n ] -> info -> title
$videos [ n ] -> info -> description
$videos [ n ] -> info -> keywords
$videos [ n ] -> info -> views
$videos [ n ] -> info -> duration
$videos [ n ] -> info -> published
$videos [ n ] -> info -> updated
$videos [ n ] -> info -> rating

$videos [ n ] -> view -> media_content_url
$videos [ n ] -> view -> media_content_type
$videos [ n ] -> view -> pageurl

$videos [ n ] -> thumbnail_small -> width
$videos [ n ] -> thumbnail_small -> height
$videos [ n ] -> thumbnail_small -> url

$videos [ n ] -> thumbnail_large -> width
$videos [ n ] -> thumbnail_large -> height
$videos [ n ] -> thumbnail_large -> url

$videos [ n ] -> comments -> feedurl
$videos [ n ] -> comments -> count
You can call the tag as easy as {api_youtubefeed name="YOUTUBE USERNAME"}. If you don't supply a name, for experimental use, the feed from balcony tv (not affiliated, random pick ;) ) will be used. It features plenty of data.

Dates can optionally be formated using php strftime parameters. Cacheing max age can also be configured optionally.

The cache takes car that the server doesn't have to wait for the youtube server to reply each time a page is requested. Addiionally, only the fewest youtube user feeds will require to be reloaded more frequently than every 4 minutes (default). If you need a refresh before max age, clean cache via reg. admin panel. It also helps to deal with quota limitations.

For playing videos howver... you need to take of that on your own. The plug-in only provides data for further processing with smarty. But here is some info how to embed youtube with valid xhtml  in the wiki.

So, with this plug-in, you can do stuff like:
- User profile with latest videos
- Product TV on Company Site ("Will it blend?") with the newest episodes
- Youtube Video-Casts in Site einbinden

The help contains a sample code snippet to print out all variables (as a little kick-start).

Let me know what you think.

Enjoy
Nils
User avatar
snatrott
Forum Members
Forum Members
Posts: 26
Joined: Tue Mar 13, 2007 7:10 pm
Location: Wisconsin, USA/Bermuda

Re: Cached Youtube API Client (CaYAC)

Post by snatrott »

I installed the plugin for both youtube and twitter and got errors on both. Here is the error I got after installing the youtube plugin:

Fatal error: Call to undefined function: simplexml_load_file() in C:\Inetpub\vhosts\duncan7.ihostsites.net\httpdocs\plugins\function.api_youtubefeed.php on line 39

What do I need to change to get it working?

Thanks.
Websites at NINJA Speed!
nhaack

Re: Cached Youtube API Client (CaYAC)

Post by nhaack »

Hi snatrott,

have you also copied the "nh_essentials" and placed the tag {nh_essentials} into you templates as well?

For Twitter, please use the plug-in from the API collection (which requires nh_essentials).

What CMS Version are you using and what is your PHP version? Can your installation access remote files?

Best
Nils
User avatar
snatrott
Forum Members
Forum Members
Posts: 26
Joined: Tue Mar 13, 2007 7:10 pm
Location: Wisconsin, USA/Bermuda

Re: Cached Youtube API Client (CaYAC)

Post by snatrott »

Sorry I didn't get back to you. I ended up going a different route with both YouTube videos and Twitter but I may attempt them again just so I know for sure how to get them working in case I need them in the future. I will let you know if I have problems with either one.

Thanks.
Websites at NINJA Speed!
Metal Beryl
Forum Members
Forum Members
Posts: 69
Joined: Wed Apr 18, 2007 9:57 am

Re: Cached Youtube API Client (CaYAC)

Post by Metal Beryl »

I'm having the same problem, where do a put

Code: Select all

{nh_essentials}
?

I have the latest CMSMS version 1.6.4 installed this is the error I get

Code: Select all

Fatal error: Call to undefined function: simplexml_load_file() in /homepages/8/d266017000/htdocs/square one/plugins/function.api_youtubefeed.php on line 39
Any ideas how to make this work?

Thanks
Jane
nhaack

Re: Cached Youtube API Client (CaYAC)

Post by nhaack »

Where have you put it now? HAve you placed the php file into your plug-in folder?

Best
Nils
Metal Beryl
Forum Members
Forum Members
Posts: 69
Joined: Wed Apr 18, 2007 9:57 am

Re: Cached Youtube API Client (CaYAC)

Post by Metal Beryl »

Hi Nils,

I have put the php file in my plugins folder and I have put {nh_essentials} in the head of my template. Is this correct?

Thanks
Jane
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Cached Youtube API Client (CaYAC)

Post by JohnnyB »

Hi,

I need to limit the results shown to be less than the default of 25.  Is there a way to do this using smarty functions or should I modify the (CaYAC) script?  I tried to use the newer function.nh_api_youtubesearch.php, but I need to display a specific youtube user and would need to modify this one to do that.  Any sugguestions?

thanks!! :)
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
nhaack

Re: Cached Youtube API Client (CaYAC)

Post by nhaack »

Hi MWW,

you have two options. You can limit the output using Smarty and Section (http://www.smarty.net/manual/en/languag ... ection.php). This way, you could address the first 10 Videos for example.

Alternatively, you could change the script in line 108 to request fewer videos.

Change:

Code: Select all


	// This is the XML Feed we want to get. The XML feed provides more info than the regular RSS
		$feed_url = "http://gdata.youtube.com/feeds/api/users/".$user_name."/uploads";

Into:

Code: Select all


	// This is the XML Feed we want to get. The XML feed provides more info than the regular RSS
		$feed_url = "http://gdata.youtube.com/feeds/api/users/".$user_name."/uploads?max-results=4";

That should do the trick. Just adjust max-results to your personal preference.

Let me know if that solved your problem.

Best
Nils
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Cached Youtube API Client (CaYAC)

Post by JohnnyB »

Hi Nils,

Those are great suggestions - thank you!

I think I will change the code using ... uploads?max-results=4";

This is what I did yesterday which works really well, but changing the code will use less processing probably.

Code: Select all

{api_youtubefeed name=youtube-user ttl=480}
	{counter assign=max print=0}
		{foreach from=$videos item=video}
		{counter}
		{if $max <= 2}
		<div class="video-feed">
			<p>
			<a class="external" title="{$video->info->description|truncate:80}" href="{$video->view->pageurl}">
			<img src="{$video->thumbnail_small->url}" alt="{$video->info->keywords}" width="100" height="75" align="left" /><strong>{$video->info->published|cms_date_format}—{$video->info->title}</strong></a>
			<br />{$video->info->description|truncate:120:"..."}</p>
		</div>
		<br class="clear" />
		{/if}
	{/foreach}
Thanks for providing this script to the cmsms community!!!
Last edited by JohnnyB on Fri Jan 22, 2010 6:26 pm, edited 1 time in total.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Cached Youtube API Client (CaYAC)

Post by JohnnyB »

How would I implement the Smarty {section}{/section}?  I need to use the tag in more than one place so editing the tag script isn't an option for me right now.

I tried the following:

Code: Select all

<div class="social-block-content">
{api_youtubefeed name=crcanney ttl=480}
{foreach from=$videos item=video}
	{section loop=$video name=video2 max=1}
	<p><a class="external" title="{$video->info->description|truncate:80}" href="{$video->view->pageurl}"><img src="{$video->thumbnail_small->url}" alt="{$video->info->keywords}" width="100" height="75" align="left" /><strong>{$video->info->published|cms_date_format}—{$video->info->title}</strong></a><br />{$video->info->description|truncate:120:"..."}</p>
	{/section}
{/foreach}
</div>
and

Code: Select all

<div class="social-block-content">
{api_youtubefeed name=crcanney ttl=480}
{section loop=$videos name=video max=1}
	<p><a class="external" title="{$video->info->description|truncate:80}" href="{$video->view->pageurl}"><img src="{$video->thumbnail_small->url}" alt="{$video->info->keywords}" width="100" height="75" align="left" /><strong>{$video->info->published|cms_date_format}—{$video->info->title}</strong></a><br />{$video->info->description|truncate:120:"..."}</p>
{/section}
</div>
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
nhaack

Re: Cached Youtube API Client (CaYAC)

Post by nhaack »

Do you want to call different user feeds on the same page or just place the videos into different locations (e.g. not a "classical" list of videos)?

You could do something like:

Code: Select all


$video[0]->view->pageurl and 
$video[1]->view->pageurl ...
$video[n]->view->pageurl ...

Would that solve your question?

Best
Nils
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Cached Youtube API Client (CaYAC)

Post by JohnnyB »

Do you want to call different user feeds on the same page or just place the videos into different locations (e.g. not a "classical" list of videos)?
The website needed a feed list of current videos and it also needs to show the most recent video. Same author for both and they are on the same page in different locations.

For now I used Simplepie for the second feed.


I edited CaYAC so it can take a max="" parameter (Thanks!)

Code: Select all

	// Select the max returned results wanted
		if ($params['max'] != '') {
			$max_results = '?max-results='.$params['max'];
		} else {
			$max_results = '';
		}

$feed_url = "http://gdata.youtube.com/feeds/api/users/".$user_name."/uploads".$max_results;

"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
nhaack

Re: Cached Youtube API Client (CaYAC)

Post by nhaack »

Hi MWW,

sorry for the late reply, have been working out of town the last weeks. I'm still not quite sure what you try to accomplish. Though I may be because I'm a little sleepy right now and don't get it.

I understood the following:

You have a video embedded of user XYZ and below you feature a list of the other newest videos of that person (in form of links)? In that case, the best way to go ahead would indeed be the section approach (I think). Without updating the script itself, you could do something like the following.

Code: Select all


{assign var=video_count value=$videos|@count}
{if $video_count > 0}
	<h1>The Single Video</h1>
	{section name=my_counter start=0 loop=1 step=1}
		{$videos[$my_counter]->view->pageurl}...
		...
		...
	{/section}
{/if}

{if $video_count > 1}
	<h1>The Video-List</h1>
	<ul>
	{section name=my_counter start=1 loop=$video_count step=1}
		<li>{$videos[$my_counter]->view->pageurl}...</li>
	{/section}
	</ul>
{/if}

I haven't run this smarty code but think this could work, at least it might provide you with some inspiration ;D
Let me know if that worked.

Best
Nils
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: Cached Youtube API Client (CaYAC)

Post by JohnnyB »

Hi,
You have a video embedded of user XYZ and below you feature a list of the other newest videos of that person (in form of links)? In that case, the best way to go ahead would indeed be the section approach (I think).
Yes, that is what the site needs.

I tried the section suggestion and couldn't get it to work. I tried a few variations and tried using a section without a count, but still couldn't figure it out.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Locked

Return to “Modules/Add-Ons”