-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.js
134 lines (124 loc) · 5.34 KB
/
results.js
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
/**
* Created by Calvin on 21/03/2017.
*/
/* initializing youtube API */
function init() {
gapi.client.setApiKey("AIzaSyDJgFr0e-Z5UF28f-klWqhPgS-k0efBFtU");
gapi.client.load("youtube", "v3", function () {
});
console.log('youtube API ready');
searchparaminit();
}
/* defining whether search happened on genre or mood */
searchParams = new URLSearchParams(window.location.search);
function searchparaminit() {
console.log('started search fn');
console.log(searchParams.entries());
for (p in searchParams) {
if (searchParams.has("pickgenre") === true) {
genremakeRequest(searchParams.get('pickgenre'));
} else if (searchParams.has("pickmood") === true) {
moodmakeRequest(searchParams.get('pickmood'));
} else if (searchParams.has("random") === true) {
randomrequest();
} else if (searchParams.has("top") === true) {
toprequest();
} else if (searchParams.has("featured") === true) {
featuredrequest();
}
}
}
/* making the request for genre and mood keywords */
function genremakeRequest() {
console.log('started make request');
gapi.client.setApiKey('AIzaSyDJgFr0e-Z5UF28f-klWqhPgS-k0efBFtU');
gapi.client.load('youtube', 'v3', function () {
var q = searchParams.get('pickgenre') + '+radio';
console.log(q, jQuery.type(q));
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet',
maxResults: 20,
type: 'video',
eventType: 'live',
topicId: '/m/04rlf',
videoEmbeddable: 'true',
videoSyndicated: 'true'
});
request.execute(function (response) {
$('.results').empty();
var srchItems = response.result.items;
console.log(srchItems);
$.each(srchItems, function (index, item) {
vidId = item.id.videoId;
vidUrl = 'https://www.youtube.com/watch?v=' + vidId;
vidTitle = item.snippet.title;
vidThumburl = item.snippet.thumbnails.medium.url;
vidThumb = '<a><figure class="vidresult"><img src="' + vidThumburl + '" alt="No Image Available."><figcaption id="' + vidId + '" onclick="clickvid(this);"><span>' + vidTitle + '</span></figcaption></figure>';
$('.results').append(vidThumb);
})
})
});
}
function moodmakeRequest() {
gapi.client.setApiKey('AIzaSyDJgFr0e-Z5UF28f-klWqhPgS-k0efBFtU');
gapi.client.load('youtube', 'v3', function () {
var q = searchParams.get('pickmood') + '+radio';
console.log(q, jQuery.type(q));
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet',
maxResults: 20,
type: 'video',
eventType: 'live',
topicId: '/m/04rlf',
videoEmbeddable: 'true',
videoSyndicated: 'true'
});
request.execute(function (response) {
$('.results').empty();
var srchItems = response.result.items;
$.each(srchItems, function (index, item) {
vidId = item.id.videoId;
vidUrl = 'https://www.youtube.com/watch?v=' + vidId;
vidTitle = item.snippet.title;
vidThumburl = item.snippet.thumbnails.medium.url;
vidThumb = '<a><figure class="vidresult"><img src="' + vidThumburl + '" alt="No Image Available."><figcaption id="' + vidId + '" onclick="clickvid(this);"><span>' + vidTitle + '</span></figcaption></figure>';
$('.results').append(vidThumb);
})
})
});
}
function toprequest() {
gapi.client.setApiKey('AIzaSyDJgFr0e-Z5UF28f-klWqhPgS-k0efBFtU');
gapi.client.load('youtube', 'v3', function () {
var q = 'radio';
console.log(q, jQuery.type(q));
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet',
maxResults: 20,
type: 'video',
eventType: 'live',
topicId: '/m/04rlf',
videoEmbeddable: 'true',
videoSyndicated: 'true',
order: 'viewCount'
});
request.execute(function (response) {
$('.results').empty();
var srchItems = response.result.items;
$.each(srchItems, function (index, item) {
vidId = item.id.videoId;
vidUrl = 'https://www.youtube.com/watch?v=' + vidId;
vidTitle = item.snippet.title;
vidThumburl = item.snippet.thumbnails.medium.url;
vidThumb = '<a><figure class="vidresult"><img src="' + vidThumburl + '" alt="No Image Available."><figcaption id="' + vidId + '" onclick="clickvid(this);"><span>' + vidTitle + '</span></figcaption></figure>';
$('.results').append(vidThumb);
})
})
});
}
function clickvid(vidid) {
window.location = "player.html?vidid=" + vidid.id
}