forked from montagejs/popcorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube-service.js
36 lines (27 loc) · 944 Bytes
/
youtube-service.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
/**
* @module ./youtube-service
* @requires montage/core/core
*/
var Montage = require("montage/core/core").Montage;
var sharedTransport = require("./jsonp-transport").shared;
var TRAILERS_FEED = "https://gdata.youtube.com/feeds/api/videos?q=%s+official+trailer&max-results=1&v=2&alt=json";
/**
* @class YoutubeService
* @extends Montage
*/
exports.YoutubeService = Montage.specialize(/** @lends YoutubeService# */ {
constructor: {
value: function YoutubeService() {
}
},
searchYoutubeTrailer: {
value: function (title) {
var searchString = title.split(' ').join('+'),
searchUrl = TRAILERS_FEED.replace("%s", searchString);
return sharedTransport.makeRequest(searchUrl).then(function (response) {
return response.feed.entry[0].media$group.yt$videoid.$t;
});
}
}
});
exports.shared = new exports.YoutubeService();