Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-11-2012, 11:04 AM   PM User | #1
leew
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
leew is an unknown quantity at this point
Creating a youtube view countdown

Hi,

I want to create a very simple page that shows a countdown to a video getting a certain number of views.

At the moment I've been building it in wordpress, but ideally I'd like to build it as a html page. This is what I've done in wordpress so far:

I got this code to show the viewcount figure which worked:
<code>[ytviews video="DpwgblBeDz4"]</code>

then this one to try to show the number of views remaining until it gets to 220k which didn't:
<script type="text/javascript">
document.write((220000-(<code>[ytviews video="
DpwgblBeDz4"]</code>)));
</script>

Any help much appreciated! I'm hoping to get some code that will return the number value. Thanks,
leew is offline   Reply With Quote
Old 12-11-2012, 04:09 PM   PM User | #2
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
You don't want it to show views until 220,000

I'm not sure that I fully understand you.
tempz is offline   Reply With Quote
Old 12-12-2012, 10:12 AM   PM User | #3
leew
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
leew is an unknown quantity at this point
I'd like to show the number of views to go until it reaches that target. So a calculation that is
=220,000 - (current viewcount on youtube server)

at the moment it would return 9077. Each time the page refreshes it would show the views still to go. It would be really cool if it could update in real time!
leew is offline   Reply With Quote
Old 12-12-2012, 02:44 PM   PM User | #4
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
I think, the easiest way, is to get video info in JSON format. If you want to use JavaScript, try jQuery.getJSON()... But I prefer PHP:

Code:
<?php
$video_ID = 'your-video-ID';
$JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'};
echo $views;
?>
tempz is offline   Reply With Quote
Users who have thanked tempz for this post:
leew (12-13-2012)
Old 12-13-2012, 04:27 PM   PM User | #5
leew
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
leew is an unknown quantity at this point
Thanks - how do I put this into a html page? Sorry, I'm a novice
leew is offline   Reply With Quote
Old 12-13-2012, 06:44 PM   PM User | #6
tempz
Regular Coder

 
Join Date: Jul 2012
Location: London
Posts: 436
Thanks: 4
Thanked 80 Times in 80 Posts
tempz is an unknown quantity at this point
Here is an example:

http://dev.tempz.webatu.com/youtube-test/


PHP Code:

<div style="float:left;">
<iframe width="560" height="315" src="http://www.youtube.com/embed/Yx82V2zN3tQ" frameborder="0" allowfullscreen></iframe>

<p>
<div style="float:left; display:inline;">
Views:
<?php
$video_ID 
'Yx82V2zN3tQ'//http://www.youtube.com/watch?v=[Yx82V2zN3tQ]
$JSON file_get_contents("https://gdata.youtube.com/feeds/api/videos/{$video_ID}?v=2&alt=json");
$JSON_Data json_decode($JSON);
$views $JSON_Data->{'entry'}->{'yt$statistics'}->{'viewCount'};
echo 
$views;
?>
</div>
</div>
tempz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:15 AM.


Advertisement
Log in to turn off these ads.