-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
214 lines (186 loc) · 10.1 KB
/
index.html
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://apis.google.com/js/api.js"></script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"
integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
</head>
<body class="bg-dark">
<!---------------------------FIN DE HEADER--------------------------->
<header>
<nav class="navbar nabvar-expand-md bg-dark navbar-dark border b-rounded">
<a href="" class="navbar-brand">Tecnologias Informatica Examen</a>
<button data-target="#menu" data-toggle="collapse" class="navbar-toggler" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<!--Add buttons to initiate auth sequence and sign out-->
<div id="menu" class="collapse navbar-collapse">
<ul class="navbar-nav ml-auto">
<li class="navbar-item"><a class="nav-link text-white" href="">Home</a></li>
</ul>
</div>
</nav>
</header>
<!---------------------------FIN DE HEADER--------------------------->
<!---------------------------INICIO DE MAIN--------------------------->
<main>
<div class="container-fluid bg-dark ">
<div class="row-fluid">
<div class="col-4-md mt-5 border bg-dark rounded " style="opacity:0.8; ">
<div class="card-group rounded-5">
<div class="card-img-top img-circle ml-5 mt-5">
<div class="card-img" id="imagen"></div>
<h3></h3>
<div class="card-body">
<pre class="h2 card-title text-info" id="content"></pre>
<div class="col-8-md bg-danger mt-5 border ml-auto mb-auto rounded bt-4 ">
<div class="card-body" id="videos" name="videos"></div>
</div>
<div class="card-footer">
<button class="btn btn-primary form-control" type="button" id="authorize-button"
style="display: none;">Autorizar</button>
<button class="btn btn-danger form-control mt-5" type="button" id="signout-button"
style="display: none;">Desconectarse</button>
<button class="btn btn-info form-control mt-5" type="button" id="saveJson"
style="display: none;">Guardar Sesion</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
CLIENT_ID = '414973337482-vbmp75623qbvdtps1tl4krqk1jak0afi.apps.googleusercontent.com';
apikey = 'AIzaSyBkDCtH8YSkqsXEgM9kMf-AHPHAy-Hj15o';
usernames = "radicalneoevo";
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"];
var SCOPES = 'https://www.googleapis.com/auth/youtube.readonly';
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
var saveJsonButton = document.getElementById('saveJson-button');
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
function initClient() {
gapi.client.init({
discoveryDocs: DISCOVERY_DOCS,
clientId: CLIENT_ID,
scope: SCOPES
}).then(function () {
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
});
}
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
authorizeButton.style.display = 'none';
signoutButton.style.display = 'block';
saveJson.style.display = 'block';
getChannel();
} else {
saveJson.style.display = 'none';
signoutButton.style.display = 'none';
authorizeButton.style.display = 'block';
}
}
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
function getChannel() {
function getJSONData(yourUrl) {
var Httpreq = new XMLHttpRequest();
try {
Httpreq.open("GET", yourUrl, false);
Httpreq.send(null);
} catch (ex) {
alert(ex.message);
}
return Httpreq.responseText;
}
gapi.client.youtube.channels.list({
'part': 'snippet,contentDetails,statistics',
'forUsername': [usernames],
}).then(function (response) {
var channel = response.result.items[0];
appendPre('Bienvenido: ' + channel.snippet.title);
document.getElementById("imagen").innerHTML += "<div style='width:100%;min-height:90px;'>"
+ "<img class='border b-rounded mb-4 img-rounded' src='" + channel.snippet.thumbnails.default.url + "' style='border:none;float:left;margin-right:10px;'/></a>"
+ "</div>";
try {
var videoinfo = JSON.parse(getJSONData("https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=" + channel.id + "&maxResults=25&key=" + apikey));
var videos = videoinfo.items;
var videocount = videoinfo.pageInfo.totalResults;
// video listing
for (var i = 0; i < videos.length; i++) {
var videoid = videos[i].id.videoId;
var videotitle = videos[i].snippet.title;
var videodescription = videos[i].snippet.description;
var videodate = videos[i].snippet.publishedAt; // date time published
var videothumbnail = videos[i].snippet.thumbnails.default.url; // default, medium or high
document.getElementById("videos").innerHTML += "<hr /><div style='width:200;min-height:200px; opacity:80%;'>"
+ "<h3 class='text-white'>" + " Lista de Videos" + "</h3>" + "<a href='https://www.youtube.com/watch?v=" + videoid + "' target='_blank'>"
+ "<img src='" + videothumbnail + "' style='border:none;float:left;margin-right:10px;' alt='" + videotitle + "' title='" + videotitle + "' /></a>"
+ "<h3><a href='https://www.youtube.com/watch?v=" + videoid + "' target='_blank'>" + videotitle + "</a></h3>" + videodescription + ""
+ "</div>";
}
} catch (ex) {
alert(ex.message);
}
});
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function () {
getyoutubes();
$("#saveJson").on("click", function (event) {
$.get("http://localhost:3000/youtubes", function (data) {
alert("Json Guardado");
$.foreach(data, function (index, data) {
sendPOSTRequest(data);
console.log(data);
});
});
});
});
function getyoutubes() {
$.get("http://localhost:3000/youtubes", function (data) {
$.each(data, function (index, data) {
console.log(data);
});
});
}
function sendPOSTRequest(body_object) {
$.post("http://localhost:3000/youtubes", body_object,
function () {
alert("youtubes guardado.");
getyoutubes();
});
}
</script>
</html>