-
Notifications
You must be signed in to change notification settings - Fork 4
/
youtubeembed.php
121 lines (97 loc) · 3.72 KB
/
youtubeembed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="container">
<div class="row">
<div class="modal fade" id="myyoutube" role="dialog">
<div class="modal-dialog" style="width:670px">
<!-- Modal content-->
<div class="modal-content col-sm-12" style="background-color:black">
<div class="modal-header">
</div>
<div class="modal-body">
<p id="r" style="opacity:1;background-color:white"> </p><span>
</div>
<div class="modal-footer">
<h4 class="modal-title" style="opacity:0.3;color:yellow">MOST REVIEWED RELATED VIDEO ON YOUTUBE</h4>
<button type="button" class="btn btn-default" data-dismiss="modal">PLAY IN BACKGROUND</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
function tplawesome(template, data) {
// initiate the result to the basic template
res = template;
// for each data key, replace the content of the brackets with the data
for(var i = 0; i < data.length; i++) {
res = res.replace(/\{\{(.*?)\}\}/g, function(match, j) { // some magic regex
return data[i][j];
})
}
return res;
} // and that's it!
$(function(){
$(".youtube").on("click",function(e){
e.preventDefault();
//prepare request
var request=gapi.client.youtube.search.list({
part:"snippet",
type:"video",
q: encodeURIComponent($(this).attr("you")).replace(/%20/g,"+"),
maxResults:1,
//order:"viewCount",
publishedAfter:"1950-01-01T00:00:00Z",
});
//execuate request
request.execute(function(response){
$(".youtube").html(" ");
var results=response.result;
$.each(results.items,function(index,item){
// console.log(item);
$.get("youtubeembedsupport.html",function(data){
$(".youtube").append(tplawesome(data,[{"title":item.snippet.title,"videoid":item.id.videoId}]));
});
});
});
});
});
$(function(){
$("#lest").on("click",function(e){
e.preventDefault();
//prepare request
var request=gapi.client.youtube.search.list({
part:"snippet",
type:"video",
q: encodeURIComponent($(this).attr("you")).replace(/%20/g,"+"),
maxResults:1,
//order:"viewCount",
publishedAfter:"1950-01-01T00:00:00Z",
});
//execuate request
request.execute(function(response){
// $(".you").html(" ");
var results=response.result;
$.each(results.items,function(index,item){
$.get("item.html",function(data){
$("#r").append(tplawesome(data,[{"title":item.snippet.title,"videoid":item.id.videoId}]));
});
});
});
});
});
function init()
{
gapi.client.setApiKey("your_key");
gapi.client.load("youtube","v3",function(){
//api is ready now
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=init"></script>+-
</body>
</html>