aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Message.ts3
-rw-r--r--src/server/index.ts2
-rw-r--r--src/server/youtubeApi/youtubeApiSample.js21
3 files changed, 25 insertions, 1 deletions
diff --git a/src/server/Message.ts b/src/server/Message.ts
index 1e29aef0b..aaee143e8 100644
--- a/src/server/Message.ts
+++ b/src/server/Message.ts
@@ -25,12 +25,13 @@ export interface Transferable {
}
export enum YoutubeQueryTypes {
- Channels, SearchVideo
+ Channels, SearchVideo, VideoDetails
}
export interface YoutubeQueryInput {
readonly type: YoutubeQueryTypes;
readonly userInput?: string;
+ readonly videoIds?: string;
}
export interface Reference {
diff --git a/src/server/index.ts b/src/server/index.ts
index 60e34de8c..dfbc1a468 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -537,6 +537,8 @@ function HandleYoutubeQuery([query, callback]: [YoutubeQueryInput, (result?: any
break;
case YoutubeQueryType.SearchVideo:
YoutubeApi.authorizedGetVideos(youtubeApiKey, query.userInput, callback);
+ case YoutubeQueryType.VideoDetails:
+ YoutubeApi.authorizedGetVideoDetails(youtubeApiKey, query.videoIds, callback);
}
}
diff --git a/src/server/youtubeApi/youtubeApiSample.js b/src/server/youtubeApi/youtubeApiSample.js
index f875812d5..cf41a33e7 100644
--- a/src/server/youtubeApi/youtubeApiSample.js
+++ b/src/server/youtubeApi/youtubeApiSample.js
@@ -33,6 +33,10 @@ module.exports.authorizedGetVideos = (apiKey, userInput, callBack) => {
authorize(JSON.parse(apiKey), getSampleVideos, { userInput: userInput, callBack: callBack });
}
+module.exports.authorizedGetVideoDetails = (apiKey, videoIds, callBack) => {
+ authorize(JSON.parse(apiKey), getVideoDetails, { videoIds: videoIds, callBack: callBack });
+}
+
/**
* Create an OAuth2 client with the given credentials, and then execute the
@@ -156,4 +160,21 @@ function getSampleVideos(auth, args) {
console.log('Videos found: ' + videos[0].id.videoId, " ", unescape(videos[0].snippet.title));
args.callBack(videos);
});
+}
+
+function getVideoDetails(auth, args) {
+ let service = google.youtube('v3');
+ service.videos.list({
+ auth: auth,
+ part: 'contentDetails, statistics',
+ id: args.videoIds
+ }, function (err, response) {
+ if (err) {
+ console.log('The API returned an error: ' + err);
+ return;
+ }
+ let videoDetails = response.data.items;
+ console.log('Video Details founds: ', videoDetails);
+ args.callBack(videoDetails);
+ });
} \ No newline at end of file