-
Notifications
You must be signed in to change notification settings - Fork 3
/
searchSuggest.js
63 lines (50 loc) · 1.51 KB
/
searchSuggest.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
/*
BBC searchSuggest API
http://search-suggest.api.bbci.co.uk/search-suggest/suggest?q={query}&scope=iplayer&format=bigscreen-2&mediatype=video&mediaset={mediaset}&apikey={apikey}
*/
var getopt = require('node-getopt');
var nitro = require('./nitroSdk');
function pad(str, padding, padRight) {
if (typeof str === 'undefined')
return padding;
if (padRight) {
return (str + padding).substring(0, padding.length);
} else {
return (padding + str).slice(-padding.length);
}
}
var config = require('./config.json');
var mediaSet = config.nitro.mediaset;
var key = config.searchSuggest.api_key;
var host = config.searchSuggest.host;
var mediaType = 'audio';
var go = getopt.create([
['h','help','show this help'],
['d','domain=ARG','set search domain, tv or radio*']
]).bindHelp();
go.on('domain',function(argv,options){
if (options.domain == 'tv') {
mediaType = 'video';
}
else if (options.domain == 'radio') {
mediaType = 'audio';
}
});
var options = go.parseSystem();
var searchTerm = options.argv[0];
var query = nitro.newQuery();
query.add('scope','iplayer',true)
.add('format','bigscreen-2') // or blq-1 (barlesque?)
.add('mediatype',mediaType) // 'video' or 'audio'
.add('mediaset',mediaSet)
.add('q',searchTerm);
nitro.make_request(host,'/search-suggest/suggest',key,query,
{api_key_name:'apikey'},function(obj){
for (var i in obj[1]) {
var o = obj[1][i];
for (var t in o.tleo) {
var tleo = o.tleo[t];
console.log(tleo.pid+' '+pad(tleo.type,' ',true)+' '+tleo.title);
}
}
});