-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_uploads.js
119 lines (113 loc) · 3.53 KB
/
my_uploads.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
// Define some variables used to remember state.
var playlistId, nextPageToken, prevPageToken;
// After the API loads, call a function to get the uploads playlist ID.
function handleAPILoaded() {
requestUserUploadsPlaylistId();
}
// Call the Data API to retrieve the playlist ID that uniquely identifies the
// list of videos uploaded to the currently authenticated user's channel.
function requestUserUploadsPlaylistId() {
// See https://developers.google.com/youtube/v3/docs/channels/list
var request = gapi.client.youtube.channels.list({
mine: true,
part: "contentDetails"
});
request.execute(function(response) {
playlistId =
response.result.items[0].contentDetails.relatedPlaylists.uploads;
requestVideoPlaylist(playlistId);
});
}
function deleteVid() {
return gapi.client.youtube.videos
.delete({
id: $("#deleteInput").val()
})
.then(
function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) {
console.error("Execute error", err);
}
);
}
function updateVid() {
return gapi.client.youtube.videos
.update({
part: "snippet,status,localizations",
resource: {
id: $("#updateInput").val(),
snippet: {
categoryId: 22,
defaultLanguage: "en",
description: "This description is in English.",
title: "There is nothing to see here."
},
status: {
privacyStatus: "private"
},
localizations: {
es: {
title: "no hay nada a ver aqui",
description: "Esta descripcion es en español."
}
}
}
})
.then(
function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) {
console.error("Execute error", err);
}
);
}
// Retrieve the list of videos in the specified playlist.
function requestVideoPlaylist(playlistId, pageToken) {
$("#video-container").html("");
var requestOptions = {
playlistId: playlistId,
part: "snippet",
maxResults: 10
};
if (pageToken) {
requestOptions.pageToken = pageToken;
}
var request = gapi.client.youtube.playlistItems.list(requestOptions);
request.execute(function(response) {
// Only show pagination buttons if there is a pagination token for the
// next or previous page of results.
nextPageToken = response.result.nextPageToken;
var nextVis = nextPageToken ? "visible" : "hidden";
$("#next-button").css("visibility", nextVis);
prevPageToken = response.result.prevPageToken;
var prevVis = prevPageToken ? "visible" : "hidden";
$("#prev-button").css("visibility", prevVis);
var playlistItems = response.result.items;
if (playlistItems) {
$.each(playlistItems, function(index, item) {
displayResult(item.snippet);
});
} else {
$("#video-container").html("Sorry you have no uploaded videos");
}
});
}
// Create a listing for a video.
function displayResult(videoSnippet) {
var title = videoSnippet.title;
var videoId = videoSnippet.resourceId.videoId;
$("#video-container").append("<p>" + title + " - " + videoId + "</p>");
}
// Retrieve the next page of videos in the playlist.
function nextPage() {
requestVideoPlaylist(playlistId, nextPageToken);
}
// Retrieve the previous page of videos in the playlist.
function previousPage() {
requestVideoPlaylist(playlistId, prevPageToken);
}