[tintuc]
Trong hướng dẫn này tôi sẽ hướng dẫn bạn cách làm để có thể lấy được thời gian của một Video đó thông qua ID của Video.
Đây là script để lấy thời gian dưới dạng số giây thông qua ID của Video là : OnyXzPuF2tQ
Trong hướng dẫn này tôi sẽ hướng dẫn bạn cách làm để có thể lấy được thời gian của một Video đó thông qua ID của Video.
Đây là script để lấy thời gian dưới dạng số giây thông qua ID của Video là : OnyXzPuF2tQ
<script type="text/javascript">Trong đoạn Code trên erhayid là chính là ID của Video của mỗi Youtube. Với đoạn code này sẽ chỉ giúp bạn lấy được thời gian dưới dạng second(giây) của Video đó. Để chuyển sang dạng phút:giây bạn dùng. Bạn có thể save với đuôi HTML để chạy thử.
var erhayid = "OnyXzPuF2tQ";
function youtubeFeedCallback(json){
document.write(json["data"]["duration"]);
}
var timer = document.write("<script src=\"http://gdata.youtube.com/feeds/api/videos/"+erhayid+"?v=2&alt=jsonc&callback=youtubeFeedCallback&prettyprint=true\"><\/script>");
</script>
<script type="text/javascript">
//This code by Erhay.com
function youtubeFeedCallback(json){
var sec1 = (json["data"]["duration"]);
var hour = Math.floor(sec1 / 3600);
var minutes = Math.floor((sec1 - (hour * 3600)) / 60);
var sec = ( json["data"]["duration"] % 60);
document.write(minutes + " : "+sec);
}
var erhayid = "OnyXzPuF2tQ";
var stimer = "<script src=\"http://gdata.youtube.com/feeds/api/videos/"+erhayid+"?v=2&alt=jsonc&callback=youtubeFeedCallback&prettyprint=true\"><\/script>";
document.write(''+stimer+'');
</script>
Ok. Giờ chúng ta sẽ áp dụng vào Json để lấy ra Video và thời gian như sau. Áp dụng vào Blogspot của bạn. Style dạng bài viết mới nhất như hình :
Trong Code trên Số bài viết tối đa được cho phép là 10 bài. Bạn có thể Chỉnh ở max-results=4 thành 10 để sử dụng hết.
Cách post bài :
Ví dụ bạn có một link Youtube như sau : http://www.youtube.com/watch?v=JNSK0647wJI
Trong bài viết bạn chỉ cần post : http://www.youtube.com/watch?v=JNSK0647wJIerhay. Thêm đuôi chữ erhay ở cuối link là được. Nếu bạn không thực hiện được có thể để lại comment để được trợ giúp.
[/tintuc]
Xem thêm các hướng dẫn khác về Blogger :
Bước 1 : Thêm toàn bộ code sau trước </head>
<style type="text/css">
/*Erhay.com style for bài viết mới nhất*/
.feature_news {list-style-type:none; padding:0; margin:0px; height:145px;}
.feature_news li {float:left; width:164px; margin-right:23px !important;height:110px;margin-right:0px;}
img.lazy{width:164px; height:110px; position:relative}
/*.feature_news li:last-child {margin-right:0 }*/
.feature_news li.last {margin-right:0px !important;}
.feature_news li img {margin-bottom:-4px}
.feature_news li a {color:#3f3f3f;}
.feature_news li a:hover { color:#0698DD !important}
.feature_news li p {margin-top:0; padding:10px 10px;}
.feature_news li span {background: none repeat scroll 0 0 #F5F5F5;display: block;height: 40px;overflow: hidden;padding: 3px 9px;line-height: 1.6;color:#468ACA; font-weight:bold; font-size:12px;
}
.feature_news li {position:relative!important}
quactinh.timer {background: none repeat scroll 0 0 #000000; bottom: 4px; color: white; display: block; height: 18px; line-height: 18px; position: absolute; right: 4px; width: 44px; z-index: 9; text-align: center; font-size: 11px; font-weight: bold; opacity: 0.9;
}
</style>
<script type='text/javascript'>
//<![CDATA[
//this code by Erhay.com
var _0x44da=["\x65\x6E\x74\x72\x79","\x66\x65\x65\x64","\x24\x74","\x74\x69\x74\x6C\x65","\x6E\x61\x6D\x65","\x61\x75\x74\x68\x6F\x72","\x6C\x65\x6E\x67\x74\x68","\x6C\x69\x6E\x6B","\x72\x65\x6C","\x72\x65\x70\x6C\x69\x65\x73","\x74\x79\x70\x65","\x74\x65\x78\x74\x2F\x68\x74\x6D\x6C","\x68\x72\x65\x66","\x61\x6C\x74\x65\x72\x6E\x61\x74\x65","\x63\x6F\x6E\x74\x65\x6E\x74","\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x79\x6F\x75\x74\x75\x62\x65\x2E\x63\x6F\x6D\x2F\x77\x61\x74\x63\x68\x3F\x76\x3D","\x69\x6E\x64\x65\x78\x4F\x66","\x65\x72\x68\x61\x79","\x73\x75\x62\x73\x74\x72\x69\x6E\x67","\x3C\x73\x63\x72\x69\x70\x74\x20\x73\x72\x63\x3D\x22\x68\x74\x74\x70\x3A\x2F\x2F\x67\x64\x61\x74\x61\x2E\x79\x6F\x75\x74\x75\x62\x65\x2E\x63\x6F\x6D\x2F\x66\x65\x65\x64\x73\x2F\x61\x70\x69\x2F\x76\x69\x64\x65\x6F\x73\x2F","\x3F\x76\x3D\x32\x26\x61\x6C\x74\x3D\x6A\x73\x6F\x6E\x63\x26\x63\x61\x6C\x6C\x62\x61\x63\x6B\x3D\x79\x6F\x75\x74\x75\x62\x65\x46\x65\x65\x64\x43\x61\x6C\x6C\x62\x61\x63\x6B\x26\x70\x72\x65\x74\x74\x79\x70\x72\x69\x6E\x74\x3D\x74\x72\x75\x65\x22\x3E\x3C\x2F\x73\x63\x72\x69\x70\x74\x3E","\x68\x74\x74\x70\x3A\x2F\x2F\x69\x32\x2E\x79\x74\x69\x6D\x67\x2E\x63\x6F\x6D\x2F\x76\x69\x2F","\x2F\x6D\x71\x64\x65\x66\x61\x75\x6C\x74\x2E\x6A\x70\x67","\x68\x74\x74\x70\x3A\x2F\x2F\x31\x2E\x62\x70\x2E\x62\x6C\x6F\x67\x73\x70\x6F\x74\x2E\x63\x6F\x6D\x2F\x5F\x75\x34\x67\x79\x53\x4E\x32\x5A\x67\x71\x45\x2F\x53\x6D\x57\x47\x62\x45\x55\x39\x73\x67\x49\x2F\x41\x41\x41\x41\x41\x41\x41\x41\x41\x68\x63\x2F\x31\x43\x5F\x57\x78\x65\x48\x68\x66\x6F\x41\x2F\x73\x38\x30\x30\x2F\x6E\x6F\x69\x6D\x61\x67\x65\x74\x68\x75\x6D\x62\x2E\x70\x6E\x67","\x70\x75\x62\x6C\x69\x73\x68\x65\x64","\x4A\x61\x6E","\x46\x65\x62","\x4D\x61\x72","\x41\x70\x72","\x4D\x61\x79","\x4A\x75\x6E","\x4A\x75\x6C","\x41\x75\x67","\x53\x65\x70","\x4F\x63\x74","\x4E\x6F\x76","\x44\x65\x63","\x2F","\x3C\x75\x6C\x20\x63\x6C\x61\x73\x73\x3D\x22\x66\x65\x61\x74\x75\x72\x65\x5F\x6E\x65\x77\x73\x22\x3E\x3C\x6C\x69\x3E\x3C\x61\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x20\x73\x74\x79\x6C\x65\x3D\x22\x22\x20\x20\x68\x72\x65\x66\x3D\x22","\x22\x3E\x3C\x71\x75\x61\x63\x74\x69\x6E\x68\x20\x63\x6C\x61\x73\x73\x3D\x22\x74\x69\x6D\x65\x72\x22\x3E","\x3C\x2F\x71\x75\x61\x63\x74\x69\x6E\x68\x3E\x3C\x69\x6D\x67\x20\x63\x6C\x61\x73\x73\x3D\x22\x6C\x61\x7A\x79\x22\x20\x73\x74\x79\x6C\x65\x3D\x22\x64\x69\x73\x70\x6C\x61\x79\x3A\x20\x69\x6E\x6C\x69\x6E\x65\x3B\x22\x20\x73\x72\x63\x3D\x22","\x22\x20\x61\x6C\x74\x3D\x22\x22\x20\x20\x3E\x3C\x73\x70\x61\x6E\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x3E","\x3C\x2F\x73\x70\x61\x6E\x3E\x3C\x2F\x61\x3E\x3C\x2F\x6C\x69\x3E","\x77\x72\x69\x74\x65","\x3C\x6C\x69\x3E\x3C\x61\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x3E\x3C\x73\x70\x61\x6E\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x20\x61\x6C\x74\x3D\x22\x22\x3E\x3C\x73\x70\x61\x6E\x20\x74\x69\x74\x6C\x65\x3D\x22","\x3C\x6C\x69\x20\x63\x6C\x61\x73\x73\x3D\x22\x6C\x61\x73\x74\x22\x3E\x3C\x61\x20\x74\x69\x74\x6C\x65\x3D\x22","\x22\x20\x61\x6C\x74\x3D\x22\x22\x20\x3E\x3C\x73\x70\x61\x6E\x20\x74\x69\x74\x6C\x65\x3D\x22","\x3C\x2F\x73\x70\x61\x6E\x3E\x3C\x2F\x61\x3E\x3C\x2F\x6C\x69\x3E\x3C\x2F\x75\x6C\x3E"];function newest(_0x5844x2){for(var _0x5844x3=0;_0x5844x3<5;_0x5844x3++){var _0x5844x4=_0x5844x2[_0x44da[1]][_0x44da[0]][_0x5844x3];var _0x5844x5=_0x5844x4[_0x44da[3]][_0x44da[2]];var _0x5844x6=_0x5844x4[_0x44da[5]][0][_0x44da[4]][_0x44da[2]];var _0x5844x7;if(_0x5844x3==_0x5844x2[_0x44da[1]][_0x44da[0]][_0x44da[6]]){break ;} ;for(var _0x5844x8=0;_0x5844x8<_0x5844x4[_0x44da[7]][_0x44da[6]];_0x5844x8++){if(_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[8]]==_0x44da[9]&&_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[10]]==_0x44da[11]){var _0x5844x9=_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[3]];var _0x5844xa=_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[12]];} ;if(_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[8]]==_0x44da[13]){_0x5844x7=_0x5844x4[_0x44da[7]][_0x5844x8][_0x44da[12]];break ;} ;} ;if(_0x44da[14] in _0x5844x4){var _0x5844xb=_0x5844x4[_0x44da[14]][_0x44da[2]];} ;var _0x5844xc=_0x5844xb[_0x44da[18]](_0x5844xb[_0x44da[16]](_0x44da[15])+31,_0x5844xb[_0x44da[16]](_0x44da[17]));var _0x5844xd=_0x44da[19]+_0x5844xc+_0x44da[20];var _0x5844xe=parseInt(_0x5844xd);try{thumburl=_0x44da[21]+_0x5844xc+_0x44da[22];} catch(error){thumburl=_0x44da[23];} ;var _0x5844xf=_0x5844x4[_0x44da[24]][_0x44da[2]];var _0x5844x10=_0x5844xf[_0x44da[18]](0,4);var _0x5844x11=_0x5844xf[_0x44da[18]](5,7);var _0x5844x12=_0x5844xf[_0x44da[18]](8,10);var _0x5844x13= new Array();_0x5844x13[1]=_0x44da[25];_0x5844x13[2]=_0x44da[26];_0x5844x13[3]=_0x44da[27];_0x5844x13[4]=_0x44da[28];_0x5844x13[5]=_0x44da[29];_0x5844x13[6]=_0x44da[30];_0x5844x13[7]=_0x44da[31];_0x5844x13[8]=_0x44da[32];_0x5844x13[9]=_0x44da[33];_0x5844x13[10]=_0x44da[34];_0x5844x13[11]=_0x44da[35];_0x5844x13[12]=_0x44da[36];var _0x5844x14=_0x5844x12+_0x44da[37]+_0x5844x11+_0x44da[37]+_0x5844x10;if(_0x5844x3==0){document[_0x44da[45]](_0x44da[38]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[42]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==1){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[47]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==2){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==3){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==4){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==5){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==6){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==7){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==8){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==9){document[_0x44da[45]](_0x44da[46]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[48]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[44]);} ;if(_0x5844x3==10){document[_0x44da[45]](_0x44da[49]+_0x5844x5+_0x44da[39]+_0x5844x7+_0x44da[40]+_0x5844xd+_0x44da[41]+thumburl+_0x44da[50]+_0x5844x5+_0x44da[43]+_0x5844x5+_0x44da[51]);} ;} ;} ;
//]]>
</script>
Bước 2 : Thêm code hiển thị trên trang. Trong </body>
<script language='JavaScript'>
imgr = new Array();
imgr[0] = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh51wG9SoN5-mANI5jsw2G89eAfP2yYrBss7Q5vbieLaMre48rbZYN3hwK5PFiZRN_I-V2yw0r-59wm9l-m9aSysxWugKE94cZeixuJykfhiQQ_RfMjj0cLiVfqCjv_mblOUveERln4yE0/s149/finallogo.png";
showRandomImg = true;
aBold = false;
summaryPost = 0; //số ký tự của bài viết hiển thị (bài tóm tắt)
sumPost = 0;
numposts = 5; //số bài được hiển thị
label = "A.Máy tính";
</script>
<script src='http://www.hayhay.info/feeds/posts/default/?orderby=published&max-results=4&alt=json-in-script&callback=newest' type='text/javascript'/>
Cách post bài :
Ví dụ bạn có một link Youtube như sau : http://www.youtube.com/watch?v=JNSK0647wJI
Trong bài viết bạn chỉ cần post : http://www.youtube.com/watch?v=JNSK0647wJIerhay. Thêm đuôi chữ erhay ở cuối link là được. Nếu bạn không thực hiện được có thể để lại comment để được trợ giúp.
[/tintuc]
0 nhận xét:
Đăng nhận xét