dimanche 13 juillet 2014

API Dailymotion et JQuery part II :)

Obtenir les vidéos du channel "music" qui ont eu le plus de visites durant la dernière heure pour le pays France :

<!DOCTYPE html>
<html>
<head>
<!--<script src="./jquery-2.1.1.js"></script>-->
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide();
  });

//https://api.dailymotion.com/video/xxt41x_glenn-gould-little-prelude-in-c-minor-bwv-934_music?fields=ratings_total,country,comments_total,created_time,description,geoloc,isrc,upc,views_last_day
//https://api.dailymotion.com/videos?channel=music&country=FR&sort=visited-hour
$.getJSON("https://api.dailymotion.com/videos?channel=music&country=FR&sort=visited-hour",
function( data ) {
    console.log(data);
    var items = [];
    $.each( data, function( key, val ) {
        console.log(key);
        items.push( "<li id='" + key + "'>key = " + key + " : val = " + val + "</li>" );
        if (key=='list'){
            //items.push("List detected");
            $.each(val, function(subkey,subval){
                console.log(subkey + ":" + subval);
                items.push( "<li id='" + subkey + "'>subkey = " + subkey + " : subval = " + subval + "</li>" );               
                $.each(subval, function(subkey2, subval2){
                    console.log(subkey2 + ":" + subval2);
                    items.push( "<li id='" + subkey2 + "'>subkey2 = " + subkey2 + " : subval2 = " + subval2 + "</li>" );               
                });
            });
        }
    });
   
$( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
    }).appendTo( "body" );
});
 
});

</script>
</head>
<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>