├── .gitignore
├── mod.ts
├── src
├── mod.ts
├── schemas
│ ├── schemas_live.ts
│ └── schemas.ts
├── live-streaming-api.ts
├── oauth.ts
└── youtube-deno.ts
├── .github
└── workflows
│ └── ci.yml
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/mod.ts:
--------------------------------------------------------------------------------
1 | export { YouTube } from "./youtube-deno.ts";
2 | export { YouTube_live } from "./live-streaming-api.ts";
3 |
4 | export * from "./oauth.ts";
5 | export * from "./schemas/schemas.ts";
6 |
--------------------------------------------------------------------------------
/src/mod.ts:
--------------------------------------------------------------------------------
1 | export { YouTube } from "./youtube-deno.ts";
2 | export { YouTube_live } from "./live-streaming-api.ts";
3 |
4 | export * from "./oauth.ts";
5 | export * from "./schemas/schemas.ts";
6 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 | name: tests (${{ matrix.os }})
8 | runs-on: ${{ matrix.os }}
9 | strategy:
10 | matrix:
11 | os: [ubuntu-latest, windows-latest, macOS-latest]
12 | fail-fast: true
13 | steps:
14 | - uses: actions/checkout@v2
15 | - name: download deno
16 | uses: denolib/setup-deno@v2
17 | with:
18 | deno-version: v1.6.1
19 | - name: test
20 | run: deno test
21 | - name: check format
22 | if: matrix.os == 'ubuntu-latest'
23 | run: deno fmt --check
24 | - name: lint
25 | run: deno lint --unstable
26 |
--------------------------------------------------------------------------------
/src/schemas/schemas_live.ts:
--------------------------------------------------------------------------------
1 |
2 | // Schemas for various function parameters.
3 |
4 | export interface param {
5 | // deno-lint-ignore no-explicit-any
6 | [parameter: string]: any;
7 | }
8 |
9 | // ----------Parameter schemas for different methods----------
10 |
11 | export interface schema_live_LiveBroadcasts_list extends param {
12 | part: string;
13 | broadcastStatus?: string;
14 | broadcastType?: string;
15 | id?: string;
16 | maxResults?: number;
17 | mine?: boolean;
18 | onBehalfOfContentOwner?: string;
19 | onBehalfOfContentOwnerChannel?: string;
20 | pageToken?: string;
21 | }
22 |
23 | export interface schema_live_liveChat_list extends param {
24 | part: string;
25 | liveChatId?: string;
26 | maxResults?: number;
27 | hl?: boolean;
28 | pageToken?: string;
29 | onBehalfOfContentOwnerChannel?: string;
30 | profileImageSize?: string;
31 | }
32 |
33 | export interface schema_live_superChatEvent_list extends param {
34 | part: string;
35 | maxResults?: number;
36 | hl?: boolean;
37 | pageToken?: string;
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 youtube-deno authors
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/live-streaming-api.ts:
--------------------------------------------------------------------------------
1 | import * as schemas from "./schemas/schemas_live.ts";
2 | import { YouTube } from "./youtube-deno.ts";
3 |
4 | export class YouTube_live extends YouTube {
5 | constructor(readonly apiKey: string, accessToken: (boolean | string)) {
6 | super(apiKey, accessToken);
7 | }
8 |
9 | liveBroadcasts_list(params: schemas.schema_live_LiveBroadcasts_list) {
10 | const method = "liveBroadcasts";
11 | const request_url = this.create_url(method, params);
12 |
13 | const init = {
14 | headers: this.headers,
15 | };
16 |
17 | return fetch(request_url, init).then(function (response) {
18 | return response.json();
19 | });
20 | }
21 |
22 | liveChat_list(params: schemas.schema_live_liveChat_list) {
23 | const method = "liveChat/messages";
24 | const request_url = this.create_url(method, params);
25 |
26 | const init = {
27 | headers: this.headers,
28 | };
29 |
30 | return fetch(request_url, init).then(function (response) {
31 | return response.json();
32 | });
33 | }
34 |
35 | liveSuperChatEvents_list(params: schemas.schema_live_superChatEvent_list) {
36 | const method = "superChatEvents";
37 | const request_url = this.create_url(method, params);
38 |
39 | const init = {
40 | headers: this.headers,
41 | };
42 |
43 | return fetch(request_url, init).then(function (response) {
44 | return response.json();
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/oauth.ts:
--------------------------------------------------------------------------------
1 | // This module creates the OAuth authentication url of a user.
2 |
3 | import { param } from "./schemas/schemas.ts";
4 |
5 | const oauthEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
6 | const scopes = [
7 | "https://www.googleapis.com/auth/youtube",
8 | "https://www.googleapis.com/auth/youtube.channel-memberships.creator",
9 | "https://www.googleapis.com/auth/youtube.force-ssl",
10 | "https://www.googleapis.com/auth/youtube.readonly",
11 | "https://www.googleapis.com/auth/youtube.upload",
12 | "https://www.googleapis.com/auth/youtubepartner",
13 | "https://www.googleapis.com/auth/youtubepartner-channel-audit",
14 | ];
15 |
16 | export interface authParams extends param {
17 | client_id: string;
18 | redirect_uri: string;
19 | response_type?: "code" | "token";
20 | scope: string;
21 | access_type?: "online" | "offline"; // TODO: handle refreshing
22 | state?: string;
23 | include_granted_scopes?: boolean;
24 | login_hint?: string;
25 | prompt?: "none" | "consent select_account" | "consent" | "select_account";
26 | }
27 |
28 | export class authenticator {
29 | private create_url(creds: authParams): string {
30 | let url: string = oauthEndpoint + "?response_type=token";
31 |
32 | for (const p in creds) {
33 | if (p == "response_type") {
34 | // Don't add to url (pass)
35 | } else if (p == "scope") {
36 | url += "&scope=";
37 | const scopeList: string[] = creds[p].split(" ");
38 | for (const s of scopeList) {
39 | if (scopes.includes(s) == false) {
40 | throw new Error("Invalid scope: " + s);
41 | }
42 | }
43 | const addScopes: string = scopeList.join("+");
44 | url += addScopes;
45 | } else {
46 | url += `&${p}=${creds[p].toString()}`;
47 | }
48 | }
49 |
50 | return url;
51 | }
52 |
53 | authenticate(credentials: authParams): string {
54 | const authUrl: string = this.create_url(credentials);
55 |
56 | // open this authUrl in browser and get the token
57 | return authUrl;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/schemas/schemas.ts:
--------------------------------------------------------------------------------
1 | // Schemas for various function parameters.
2 |
3 | export interface param {
4 | // deno-lint-ignore no-explicit-any
5 | [parameter: string]: any;
6 | }
7 |
8 | export interface header {
9 | [key: string]: string;
10 | }
11 |
12 | // ----------Parameter schemas for different methods----------
13 |
14 | export interface schema_activities_list extends param {
15 | part: string;
16 | channelId?: string;
17 | mine?: boolean;
18 | maxResults?: number;
19 | pageToken?: string;
20 | publishedAfter?: string;
21 | publishedBefore?: string;
22 | regionCode?: string;
23 | }
24 |
25 | export interface schema_captions_list extends param {
26 | part: string;
27 | videoId: string;
28 | id?: string;
29 | onBehalfOfContentOwner?: string;
30 | onBehalfOf?: string;
31 | }
32 |
33 | export interface schema_captions_insert extends param {
34 | part: string;
35 | onBehalfOf?: string;
36 | onBehalfOfContentOwner?: string;
37 | sync?: boolean;
38 | }
39 |
40 | export interface schema_captions_update extends param {
41 | part: string;
42 | onBehalfOf?: string;
43 | onBehalfOfContentOwner?: string;
44 | sync?: boolean;
45 | }
46 |
47 | export interface schema_captions_download extends param {
48 | id: string;
49 | onBehalfOf?: string;
50 | onBehalfOfContentOwner?: string;
51 | tfmt?: "sbv" | "scc" | "srt" | "ttml" | "vtt";
52 | tlang?: string;
53 | }
54 |
55 | export interface schema_captions_delete extends param {
56 | id: string;
57 | onBehalfOf?: string;
58 | onBehalfOfContentOwner?: string;
59 | }
60 |
61 | export interface schema_channelBanners_insert extends param {
62 | channelId?: string;
63 | onBehalfOfContentOwner?: string;
64 | }
65 |
66 | export interface schema_channels_list extends param {
67 | part: string;
68 | forUsername?: string;
69 | hl?: string;
70 | id?: string;
71 | managedByMe?: boolean;
72 | maxResults?: number;
73 | mine?: boolean;
74 | onBehalfOfContentOwner?: string;
75 | pageToken?: string;
76 | }
77 |
78 | export interface schema_channels_update extends param {
79 | part: string;
80 | onBehalfOfContentOwner?: string;
81 | }
82 |
83 | export interface schema_channelSections_list extends param {
84 | part: string;
85 | channelId?: string;
86 | hl?: string;
87 | id?: string;
88 | mine?: boolean;
89 | onBehalfOfContentOwner?: string;
90 | }
91 |
92 | export interface schema_channelSections_insert extends param {
93 | part: string;
94 | onBehalfOfContentOwner?: string;
95 | onBehalfOfContentOwnerChannel?: string;
96 | }
97 |
98 | export interface schema_channelSections_update extends param {
99 | part: string;
100 | onBehalfOfContentOwner?: string;
101 | }
102 |
103 | export interface schema_channelSections_delete extends param {
104 | id: string;
105 | onBehalfOfContentOwner?: string;
106 | }
107 |
108 | export interface schema_comments_list extends param {
109 | part: string;
110 | id?: string;
111 | maxResults?: number;
112 | pageToken?: string;
113 | parentId?: string;
114 | textFormat?: "html" | "plainText";
115 | }
116 |
117 | export interface schema_comments_insert extends param {
118 | part: string;
119 | }
120 |
121 | export interface schema_comments_update extends param {
122 | part: string;
123 | }
124 |
125 | export interface schema_comments_markAsSpam extends param {
126 | id: string;
127 | }
128 |
129 | export interface schema_comments_setModerationStatus extends param {
130 | id: string;
131 | moderationStatus: "heldForReview" | "published" | "rejected";
132 | banAuthor?: boolean;
133 | }
134 |
135 | export interface schema_comments_markAsSpam extends param {
136 | id: string;
137 | }
138 |
139 | export interface schema_comments_delete extends param {
140 | id: string;
141 | }
142 |
143 | export interface schema_commentThreads_list extends param {
144 | part: string;
145 | allThreadsRelatedToChannelId?: string;
146 | channelId?: string;
147 | id?: string;
148 | maxResults?: number;
149 | moderationStatus?: "heldForReview" | "likelySpam" | "published";
150 | order?: "relevance" | "time";
151 | pageToken?: string;
152 | searchTerms?: string;
153 | textFormat?: "html" | "plainText";
154 | videoId?: string;
155 | }
156 |
157 | export interface schema_commentThreads_insert extends param {
158 | part: string;
159 | }
160 |
161 | export interface schema_commentThreads_update extends param {
162 | part: string;
163 | }
164 |
165 | export interface schema_i18nLanguages_list extends param {
166 | part: string;
167 | hl?: string;
168 | }
169 |
170 | export interface schema_i18nRegions_list extends param {
171 | part: string;
172 | hl?: string;
173 | }
174 |
175 | export interface schema_playlistItems_list extends param {
176 | part: string;
177 | id?: string;
178 | maxResults?: number;
179 | onBehalfOfContentOwner?: string;
180 | pageToken?: string;
181 | playlistId?: string;
182 | videoId?: string;
183 | }
184 |
185 | export interface schema_playlistItems_insert extends param {
186 | part: string;
187 | onBehalfOfContentOwner?: string;
188 | }
189 |
190 | export interface schema_playlistItems_update extends param {
191 | part: string;
192 | onBehalfOfContentOwner?: string;
193 | }
194 |
195 | export interface schema_playlistItems_delete extends param {
196 | id: string;
197 | onBehalfOfContentOwner?: string;
198 | }
199 |
200 | export interface schema_playlists_list extends param {
201 | part: string;
202 | channelId?: string;
203 | hl?: string;
204 | id?: string;
205 | maxResults?: number;
206 | mine?: boolean;
207 | onBehalfOfContentOwner?: string;
208 | onBehalfOfContentOwnerChannel?: string;
209 | pageToken?: string;
210 | }
211 |
212 | export interface schema_playlists_insert extends param {
213 | part: string;
214 | onBehalfOfContentOwner?: string;
215 | onBehalfOfContentOwnerChannel?: string;
216 | }
217 |
218 | export interface schema_playlists_update extends param {
219 | part: string;
220 | onBehalfOfContentOwner?: string;
221 | }
222 |
223 | export interface schema_playlists_delete extends param {
224 | id: string;
225 | onBehalfOfContentOwner?: string;
226 | }
227 |
228 | export interface schema_search_list extends param {
229 | part: string;
230 | channelId?: string;
231 | channelType?: "any" | "show";
232 | eventType?: "completed" | "live" | "upcoming";
233 | forContentOwner?: boolean;
234 | forDeveloper?: boolean;
235 | forMine?: boolean;
236 | location?: string;
237 | locationRadius?: string;
238 | maxResults?: number;
239 | onBehalfOfContentOwner?: string;
240 | order?:
241 | | "date"
242 | | "rating"
243 | | "relevance"
244 | | "title"
245 | | "videoCount"
246 | | "viewCount";
247 | pageToken?: string;
248 | publishedAfter?: string;
249 | publishedBefore?: string;
250 | q?: string;
251 | regionCode?: string;
252 | relatedToVideoId?: string;
253 | relevanceLanguage?: string;
254 | safeSearch?: "moderate" | "none" | "strict";
255 | topicId?: string;
256 | type?: string;
257 | videoCaption?: "any" | "closedCaption" | "none";
258 | videoCategoryId?: string;
259 | videoDefinition?: "any" | "high" | "standard";
260 | videoDimension?: "2d" | "3d" | "any";
261 | videoDuration?: "any" | "long" | "medium" | "short";
262 | videoEmbeddable?: "any" | "true";
263 | videoLicense?: "any" | "creativeCommon" | "youtube";
264 | videoSyndicated?: "any" | "true";
265 | videoType?: "any" | "episode" | "movie";
266 | }
267 |
268 | export interface schema_subscriptions_list extends param {
269 | part: string;
270 | channelId?: string;
271 | forChannelId?: string;
272 | id?: string;
273 | maxResults?: number;
274 | mine?: boolean;
275 | myRecentSubscribers?: boolean;
276 | mySubscribers?: boolean;
277 | onBehalfOfContentOwner?: string;
278 | onBehalfOfContentOwnerChannel?: string;
279 | order?: "alphabetical" | "relevance" | "unread";
280 | pageToken?: string;
281 | }
282 |
283 | export interface schema_subscriptions_insert extends param {
284 | part: string;
285 | }
286 |
287 | export interface schema_subscriptions_delete extends param {
288 | id: string;
289 | }
290 |
291 | export interface schema_thumbnails_set extends param {
292 | videoId: string;
293 | onBehalfOfContentOwner?: string;
294 | }
295 |
296 | export interface schema_videoAbuseReportReasons_list extends param {
297 | part: string;
298 | hl?: string;
299 | }
300 |
301 | export interface schema_videoCategories_list extends param {
302 | part: string;
303 | hl?: string;
304 | id?: string;
305 | regionCode?: string;
306 | }
307 |
308 | export interface schema_videos_list extends param {
309 | part: string;
310 | chart?: "mostPopular";
311 | hl?: string;
312 | id?: string;
313 | locale?: string;
314 | maxHeight?: number;
315 | maxResults?: number;
316 | maxWidth?: number;
317 | myRating?: "dislike" | "like";
318 | onBehalfOfContentOwner?: string;
319 | pageToken?: string;
320 | regionCode?: string;
321 | videoCategoryId?: string;
322 | }
323 |
324 | export interface schema_videos_insert extends param {
325 | part: string;
326 | autoLevels?: boolean;
327 | notifySubscribers?: boolean;
328 | onBehalfOfContentOwner?: string;
329 | onBehalfOfContentOwnerChannel?: string;
330 | stabilize?: boolean;
331 | }
332 |
333 | export interface schema_videos_update extends param {
334 | part: string;
335 | onBehalfOfContentOwner?: string;
336 | }
337 |
338 | export interface schema_videos_rate extends param {
339 | id: string;
340 | rating?: "dislike" | "like" | "none";
341 | }
342 |
343 | export interface schema_videos_getRating extends param {
344 | id: string;
345 | onBehalfOfContentOwner?: string;
346 | }
347 |
348 | export interface schema_videos_reportAbuse extends param {
349 | onBehalfOfContentOwner?: string;
350 | }
351 |
352 | export interface schema_videos_delete extends param {
353 | id: string;
354 | onBehalfOfContentOwner?: string;
355 | }
356 |
357 | export interface schema_watermarks_set extends param {
358 | channelId: string;
359 | onBehalfOfContentOwner?: string;
360 | }
361 |
362 | export interface schema_watermarks_unset extends param {
363 | channelId: string;
364 | onBehalfOfContentOwner?: string;
365 | }
366 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # youtube-deno : A [Deno](https://deno.land/) client for the [YouTube Data API](https://developers.google.com/youtube/v3/docs)
4 |
5 | Lets you incorporate core YouTube features, such as uploading videos, creating and managing playlists, searching for content, and almost any interaction with YouTube in your Deno application.
6 |
7 | This library is a part of
8 |
9 |
10 |
11 |
12 | [](https://nest.land/package/youtube-deno)
13 |
14 |
15 |
16 | 
17 | [](hhttps://github.com/akshgpt7/youtube-deno/stargazers)
18 | [](https://t.me/joinchat/N4E6lx25rNG0IJk-hxqnCg)
19 |
20 |
21 |
22 |
23 | ---
24 |
25 |
26 | ## Why?
27 |
28 | - Supports latest YouTube Data API v3.
29 | - OAuth 2.0 support out of the box.
30 | - Easy to use.
31 | - All functionality just a function call away.
32 | - Usable for both Web Applications and personal CLI applications.
33 | - Asynchronous requests.
34 | - No external dependencies.
35 |
36 |
37 | ## Installing
38 | *Deno allows you to directly import modules from URLs!*
39 | To import and use the client in your file, add the following import statement:
40 | ```ts
41 | import { YouTube } from 'https://deno.land/x/youtube@v0.3.0/mod.ts';
42 | ```
43 |
44 |
45 | ## Usage
46 |
47 | ### Configuring your App
48 | Firstly, you'll have to register your app in the [Google Developers Console](https://console.developers.google.com/apis/dashboard).
49 | Browse the console and select "New Project".
50 |
51 | After registering your app, enable the YouTube API for your app by clicking on the "ENABLE APIS AND SERVICES" button and selecting **"YouTube Data API v3"**.
52 |
53 | After this, you'll need to create some credentials through the console depending on what you want to do, to be able to make API requests.
54 | There are two types of objects you can make according to your requirement:
55 |
56 | ### Objects that do not require user interactions
57 | If you only need to fetch public data from YouTube, then all you need is an API key.
58 | Click on the "CREATE CREDENTIALS" button in the console and select **"API key"** from the options.
59 | **(Note that an API key is required for making each and every request to this API, so this step is mandatory)**
60 |
61 | To create an object which uses this API key only for authentication:
62 | ```ts
63 | let yt = new YouTube("Your-api-key-here", false); // The false is for access token
64 | ```
65 | (Remember: This object is not allowed to perform any account related operation, so you won’t be able to like a video, subscribe to a channel or delete a playlist etc. from a specific account. You will only be able to retrieve read-only public data. For these operations, create an [OAuth authorized object](#objects-that-require-user-interactions-user-consent-by-oauth-20-authorization))
66 |
67 | Now, to use this object, just call [any function](https://github.com/akshgpt7/youtube-deno#calling-available-functions) that only lists read-only public data. For example:
68 | ```ts
69 | yt1.search_list({part: "snippet"}).then(function(response){
70 | console.log(response);
71 | });
72 | ```
73 |
74 | ### Objects that require user interactions (user consent by [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2) authorization)
75 | (Note: Creating the API key from the previous section is mandatory.)
76 | If you need to make requests that involve access to a YouTube account, you need the owner of each account to authorize your app. For that, you need an access token to be passed to the object you create. This can have the following cases:
77 |
78 | **Case 1: You already have an access token**
79 | If you already have an access token, you simply have to pass it while creating the object:
80 | ```ts
81 | let yt = new YouTube("your-api-key-here", "access-token-here");
82 | ```
83 | Now, using this object you can call [functions](https://github.com/akshgpt7/youtube-deno#calling-available-functions) (by passing the apt parameters) which require YouTube account interactions.
84 |
85 |
86 | **Case 2: You do not have an access token**
87 | If you do not have an access token already, you can generate it using our `authenticator` class. For that, follow these steps:
88 | - You first need to create some more credentials. Head to the [Google Developers Console](https://console.developers.google.com/apis/credentials) and under "CREATE CREDENTIALS", select "OAuth client ID".
89 | - Select "Web Application" under Application type.
90 | - Fill the "Authorized Redirect URI" textarea with the URL where you want to redirect users after they authorize their YouTube account. (Note: If you're making a CLI application for your own use, you can enter this as `https://localhost:8080`)
91 | - Now, use the following code snippet (replacing with your own keys) to create an authentication URL:
92 | ```ts
93 | import { authenticator, authParams } from 'https://deno.land/x/youtube@v0.3.0/mod.ts';
94 |
95 | let auth = new authenticator();
96 | let creds: authParams = {
97 | client_id: "your-client-id",
98 | redirect_uri: "your-redirect-uri",
99 | scope: "your-decided-scopes"
100 | };
101 |
102 | let auth_url: string = auth.authenticate(creds);
103 | ```
104 | Here, copy the client ID that you just created from the console under `client-id` field. The `redirect_uri` field must contain the same one as you filled in the form at the Developer console. The `scope` field tells how much access you want the user to grant to your app, decide the scopes [from here](https://developers.google.com/identity/protocols/oauth2/scopes#youtube) and add space delimited values in the string for multiple scopes (Exapmle: `scope: "https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/youtube.upload"`).
105 | - The `auth_url` variable made stores the created URL. If you're making a web application, redirect the user to this URL through a button in your app. Then the user will be prompted to decide if they want to grant access or not. Every user who authorizes your app will be redirected to the `redirect_uri` with an extra `#access_token` parameter that is a long random string. Just fetch this access token from the URL and pass it to the object that you create:
106 | ```ts
107 | let yt = new YouTube("your-api-key-here", "access-token-here");
108 | ```
109 | Now, using this object you can call [functions](https://github.com/akshgpt7/youtube-deno#calling-available-functions) (by passing the apt parameters) which require YouTube account interactions.
110 |
111 | *(Note: For CLI applications for personal use, you can open the `auth_url` manually in a browser and after giving access, you'll be redirected to the `redirect_uri` with an extra `#access_token` parameter which you can copy into the object created above)*
112 |
113 |
114 | ## Calling available functions
115 | **For the detailed API docs of this client library, look [here](https://doc.deno.land/https/raw.githubusercontent.com/akshgpt7/youtube-api-deno/master/src/mod.ts).**
116 | **For a better understanding of a particular function and parameters information, refer the [YouTube Data API docs](https://developers.google.com/youtube/v3/docs) for that function.**
117 |
118 | The following is a list of functions that you can call using one of the objects created above:
119 |
120 | The `params` parameter for each function must be an object type, following its [schema](https://doc.deno.land/https/raw.githubusercontent.com/akshgpt7/youtube-api-deno/master/src/mod.ts#schema_activities_insert).
121 |
122 | - `activities_list(params: schema_activities_list)`
123 | - `captions_list(params: schema_captions_list)`
124 | - `captions_insert(params: schema_captions_insert, body: object)`
125 | - `captions_update(params: schema_captions_update, body: object)`
126 | - `captions_download(params: schema_captions_download)`
127 | - `captions_delete(params: schema_captions_delete)`
128 | - `channelBanners_insert(params: schema_channelBanners_insert, body?: object)`
129 | - `channels_list(params: schema_channels_list)`
130 | - `channels_update(params: schema_channels_update, body: object)`
131 | - `channelSections_list(params: schema_channelSections_list)`
132 | - `channelSections_insert(params: schema_channelBanners_insert, body: object)`
133 | - `channelSections_update(params: schema_channelSections_update, body: object)`
134 | - `channelSections_delete(params: schema_channelSections_delete)`
135 | - `comments_list(params: schema_comments_list)`
136 | - `comments_insert(params: schema_comments_insert, body: object)`
137 | - `comments_update(params: schema_comments_update, body?: object)`
138 | - `comments_markAsSpam(params: schema_comments_markAsSpam)`
139 | - `comments_setModerationStatus(params: schema_comments_setModerationStatus)`
140 | - `comments_delete(params: schema_comments_delete)`
141 | - `commentThreads_list(params: schema_commentThreads_list)`
142 | - `commentThreads_insert(params: schema_commentThreads_insert, body: object)`
143 | - `commentThreads_update(params: schema_commentThreads_update, body: object)`
144 | - `i18nLanguages_list(params: schema_i18nLanguages_list)`
145 | - `i18nRegions_list(params: schema_i18nRegions_list)`
146 | - `liveBroadcasts_list(params: schema_live_LiveBroadcasts_list)`
147 | - `liveChat_list(params: schema_live_liveChat_list)`
148 | - `liveSuperChatEvents_list(params: schema_live_superChatEvent_list)`
149 | - `playlistItems_list(params: schema_playlistItems_list)`
150 | - `playlistItems_insert(params: schema_playlistItems_insert, body: object)`
151 | - `playlistItems_update(params: schema_playlistItems_update, body: object)`
152 | - `playlistItems_delete(params: schema_playlistItems_delete)`
153 | - `playlists_list(params: schema_playlists_list)`
154 | - `playlists_insert(params: schema_playlists_insert, body: object)`
155 | - `playlists_update(params: schema_playlists_update, body: object)`
156 | - `playlists_delete(params: schema_playlists_delete)`
157 | - `search_list(params: schema_search_list)`
158 | - `subscriptions_list(params: schema_subscriptions_list)`
159 | - `subscriptions_insert(params: schema_subscriptions_insert, body: object)`
160 | - `subscriptions_delete(params: schema_subscriptions_delete)`
161 | - `thumbnails_set(params: schema_thumbnails_set, body?: object)`
162 | - `videoAbuseReportReasons_list(params: schema_videoAbuseReportReasons_list)`
163 | - `videoCategories_list(params: schema_videoCategories_list)`
164 | - `videos_list(params: schema_videos_list)`
165 | - `videos_insert(params: schema_videos_insert, body: object)`
166 | - `videos_update(params: schema_videos_update, body: object)`
167 | - `videos_rate(params: schema_videos_rate)`
168 | - `videos_getRating(params: schema_videos_getRating)`
169 | - `videos_reportAbuse(params: schema_videos_reportAbuse, body: object)`
170 | - `videos_delete(params: schema_videos_delete)`
171 | - `watermarks_set(params: schema_watermarks_set, body: object)`
172 | - `watermarks_unset(params: schema_watermarks_unset)`
173 |
174 |
175 | *All the functions return the response JSON after making the request.*
176 |
177 |
178 | ## Examples
179 | ```ts
180 | // A simple example to call the search_list() function and log the response json.
181 | import { YouTube } from 'https://deno.land/x/youtube@v0.3.0/mod.ts';
182 |
183 | let obj = new YouTube("your-api-key-here", false);
184 |
185 | obj.search_list({part: "snippet", q: "coldplay"}).then(function(response){
186 | console.log(response);
187 | });
188 |
189 | ```
190 |
191 | ```ts
192 | // An example to call the activities_list() function using an authorized access token and log the response json.
193 | import { YouTube } from 'https://deno.land/x/youtube@v0.3.0/mod.ts';
194 |
195 | let obj = new YouTube("your-api-key-here", "access-token-here");
196 |
197 | obj.activities_list({part: "snippet", mine: true}).then(function(response){
198 | console.log(response);
199 | });
200 |
201 |
202 | ```
203 |
204 |
205 | ## Contributing
206 | youtube-deno needs your support! The goal of youtube-deno is to ease the usage of the YouTube API with Deno, which is a great piece of software!
207 |
208 | If you find that a method is missing, find a change in YouTube Data API v3, notice a bug or issue, open an issue for it and once it's confirmed, just fork the project, make the relevant change, write the appropriate tests, then submit a pull request, and it will gladly be merged!
209 |
210 | **For any sort of queries or discussions regarding the project, [join our Telegram channel](https://t.me/joinchat/N4E6lx25rNG0IJk-hxqnCg)**.
211 |
--------------------------------------------------------------------------------
/src/youtube-deno.ts:
--------------------------------------------------------------------------------
1 | /* The YouTube Data API lets you incorporate functions normally executed
2 | * on the YouTube website into your own website or application.
3 | */
4 |
5 | import * as schemas from "./schemas/schemas.ts";
6 |
7 | const service = "/youtube";
8 | const version = "/v3";
9 | const baseUrl = "https://www.googleapis.com";
10 | const rootUrl: string = baseUrl + service + version + "/";
11 |
12 | // ---------- MAIN YouTube CLASS ----------
13 |
14 | export class YouTube {
15 | key: string;
16 | token: (string | boolean);
17 | headers: schemas.header = {};
18 | contentHeaders: schemas.header = {};
19 |
20 | constructor(readonly apiKey: string, accessToken: (boolean | string)) {
21 | this.key = apiKey;
22 | this.token = accessToken;
23 | if (this.token == false) {
24 | this.headers = { "Accept": "application/json" };
25 | } else {
26 | this.headers = {
27 | "Authorization": `Bearer ${this.token}`,
28 | "Accept": "application/json",
29 | };
30 | }
31 |
32 | this.contentHeaders = this.headers;
33 | this.contentHeaders["Content-Type"] = "application/json";
34 | }
35 |
36 | protected create_url(method: string, params?: schemas.param) {
37 | let url = rootUrl + method + `?key=${this.key}`;
38 |
39 | if (params !== undefined) {
40 | for (const p in params) {
41 | url += `&${p}=${params[p].toString()}`;
42 | }
43 | }
44 |
45 | return url;
46 | }
47 |
48 | // ---------------API METHODS---------------
49 |
50 | activities_list(params: schemas.schema_activities_list) {
51 | const method = "activities";
52 | const requestUrl = this.create_url(method, params);
53 |
54 | const init = { headers: this.headers };
55 |
56 | return fetch(requestUrl, init)
57 | .then(function (response) {
58 | return response.json();
59 | });
60 | }
61 |
62 | captions_list(params: schemas.schema_captions_list) {
63 | const method = "captions";
64 | const requestUrl = this.create_url(method, params);
65 |
66 | const init = { headers: this.headers };
67 |
68 | return fetch(requestUrl, init)
69 | .then(function (response) {
70 | return response.json();
71 | });
72 | }
73 |
74 | captions_insert(
75 | params: schemas.schema_captions_insert,
76 | body: Record,
77 | ) {
78 | const method = "captions";
79 | const requestUrl = this.create_url(method, params);
80 |
81 | const init = {
82 | headers: this.contentHeaders,
83 | body: body.toString(),
84 | method: "POST",
85 | };
86 |
87 | return fetch(requestUrl, init)
88 | .then(function (response) {
89 | return response.json();
90 | });
91 | }
92 |
93 | captions_update(
94 | params: schemas.schema_captions_update,
95 | body: Record,
96 | ) {
97 | const method = "captions";
98 | const requestUrl = this.create_url(method, params);
99 |
100 | const init = {
101 | headers: this.contentHeaders,
102 | body: body.toString(),
103 | method: "PUT",
104 | };
105 |
106 | return fetch(requestUrl, init)
107 | .then(function (response) {
108 | return response.json();
109 | });
110 | }
111 |
112 | captions_download(params: schemas.schema_captions_download) {
113 | const id = params["id"];
114 | const noIdParams: schemas.param = {};
115 | for (const i in params) {
116 | if (i == "id") {
117 | continue;
118 | } else {
119 | noIdParams[i] = params[i];
120 | }
121 | }
122 |
123 | const method = "captions/" + id;
124 | const requestUrl = this.create_url(method, noIdParams);
125 |
126 | const init = { headers: this.headers };
127 |
128 | return fetch(requestUrl, init);
129 | }
130 |
131 | captions_delete(params: schemas.schema_captions_delete) {
132 | const method = "captions";
133 | const requestUrl = this.create_url(method, params);
134 |
135 | const init = { headers: this.headers, method: "DELETE" };
136 |
137 | return fetch(requestUrl, init)
138 | .then(function (response) {
139 | return response.json();
140 | });
141 | }
142 |
143 | channelBanners_insert(
144 | params: schemas.schema_channelBanners_insert,
145 | body?: Record,
146 | ) {
147 | // Provide an empty object {} as first function parameter if you do not
148 | // want to pass any optional parameters.
149 | // The second parameter being body.
150 | const method = "channelBanners/insert";
151 | const requestUrl = this.create_url(method, params);
152 |
153 | const init = {
154 | headers: this.contentHeaders,
155 | body: body?.toString(),
156 | method: "POST",
157 | };
158 |
159 | return fetch(requestUrl, init)
160 | .then(function (response) {
161 | return response.json();
162 | });
163 | }
164 |
165 | channels_list(params: schemas.schema_channels_list) {
166 | const method = "channels";
167 | const requestUrl = this.create_url(method, params);
168 |
169 | const init = { headers: this.headers };
170 |
171 | return fetch(requestUrl, init)
172 | .then(function (response) {
173 | return response.json();
174 | });
175 | }
176 |
177 | channels_update(
178 | params: schemas.schema_channels_update,
179 | body: Record,
180 | ) {
181 | const method = "channels";
182 | const requestUrl = this.create_url(method, params);
183 |
184 | const init = {
185 | headers: this.contentHeaders,
186 | body: body.toString(),
187 | method: "PUT",
188 | };
189 |
190 | return fetch(requestUrl, init)
191 | .then(function (response) {
192 | return response.json();
193 | });
194 | }
195 |
196 | channelSections_list(params: schemas.schema_channelSections_list) {
197 | const method = "channelSections";
198 | const requestUrl = this.create_url(method, params);
199 |
200 | const init = { headers: this.headers };
201 |
202 | return fetch(requestUrl, init)
203 | .then(function (response) {
204 | return response.json();
205 | });
206 | }
207 |
208 | channelSections_insert(
209 | params: schemas.schema_channelBanners_insert,
210 | body: Record,
211 | ) {
212 | const method = "channelSections";
213 | const requestUrl = this.create_url(method, params);
214 |
215 | const init = {
216 | headers: this.contentHeaders,
217 | body: body.toString(),
218 | method: "POST",
219 | };
220 |
221 | return fetch(requestUrl, init)
222 | .then(function (response) {
223 | return response.json();
224 | });
225 | }
226 |
227 | channelSections_update(
228 | params: schemas.schema_channelSections_update,
229 | body: Record,
230 | ) {
231 | const method = "channelSections";
232 | const requestUrl = this.create_url(method, params);
233 |
234 | const init = {
235 | headers: this.contentHeaders,
236 | body: body.toString(),
237 | method: "PUT",
238 | };
239 |
240 | return fetch(requestUrl, init)
241 | .then(function (response) {
242 | return response.json();
243 | });
244 | }
245 |
246 | channelSections_delete(params: schemas.schema_channelSections_delete) {
247 | const method = "channelSections";
248 | const requestUrl = this.create_url(method, params);
249 |
250 | const init = { headers: this.headers, method: "DELETE" };
251 |
252 | return fetch(requestUrl, init)
253 | .then(function (response) {
254 | return response.json();
255 | });
256 | }
257 |
258 | comments_list(params: schemas.schema_comments_list) {
259 | const method = "comments";
260 | const requestUrl = this.create_url(method, params);
261 |
262 | const init = { headers: this.headers };
263 |
264 | return fetch(requestUrl, init)
265 | .then(function (response) {
266 | return response.json();
267 | });
268 | }
269 |
270 | comments_insert(
271 | params: schemas.schema_comments_insert,
272 | body: Record,
273 | ) {
274 | const method = "comments";
275 | const requestUrl = this.create_url(method, params);
276 |
277 | const init = {
278 | headers: this.contentHeaders,
279 | body: body.toString(),
280 | method: "POST",
281 | };
282 |
283 | return fetch(requestUrl, init)
284 | .then(function (response) {
285 | return response.json();
286 | });
287 | }
288 |
289 | comments_update(
290 | params: schemas.schema_comments_update,
291 | body?: Record,
292 | ) {
293 | const method = "comments";
294 | const requestUrl = this.create_url(method, params);
295 |
296 | const init = {
297 | headers: this.contentHeaders,
298 | body: body?.toString(),
299 | method: "PUT",
300 | };
301 |
302 | return fetch(requestUrl, init)
303 | .then(function (response) {
304 | return response.json();
305 | });
306 | }
307 |
308 | comments_markAsSpam(params: schemas.schema_comments_markAsSpam) {
309 | const method = "comments/markAsSpam";
310 | const requestUrl = this.create_url(method, params);
311 |
312 | const init = { headers: this.headers, method: "POST" };
313 |
314 | return fetch(requestUrl, init)
315 | .then(function (response) {
316 | return response.json();
317 | });
318 | }
319 |
320 | comments_setModerationStatus(
321 | params: schemas.schema_comments_setModerationStatus,
322 | ) {
323 | const method = "comments/setModerationStatus";
324 | const requestUrl = this.create_url(method, params);
325 |
326 | const init = { headers: this.headers, method: "POST" };
327 |
328 | return fetch(requestUrl, init)
329 | .then(function (response) {
330 | return response.json();
331 | });
332 | }
333 |
334 | comments_delete(params: schemas.schema_comments_delete) {
335 | const method = "comments";
336 | const requestUrl = this.create_url(method, params);
337 |
338 | const init = { headers: this.headers, method: "DELETE" };
339 |
340 | return fetch(requestUrl, init)
341 | .then(function (response) {
342 | return response.json();
343 | });
344 | }
345 |
346 | commentThreads_list(params: schemas.schema_commentThreads_list) {
347 | const method = "commentThreads";
348 | const requestUrl = this.create_url(method, params);
349 |
350 | const init = { headers: this.headers };
351 |
352 | return fetch(requestUrl, init)
353 | .then(function (response) {
354 | return response.json();
355 | });
356 | }
357 |
358 | commentThreads_insert(
359 | params: schemas.schema_commentThreads_insert,
360 | body: Record,
361 | ) {
362 | const method = "commentThreads";
363 | const requestUrl = this.create_url(method, params);
364 |
365 | const init = {
366 | headers: this.contentHeaders,
367 | body: body.toString(),
368 | method: "POST",
369 | };
370 |
371 | return fetch(requestUrl, init)
372 | .then(function (response) {
373 | return response.json();
374 | });
375 | }
376 |
377 | commentThreads_update(
378 | params: schemas.schema_commentThreads_update,
379 | body: Record,
380 | ) {
381 | const method = "commentThreads";
382 | const requestUrl = this.create_url(method, params);
383 |
384 | const init = {
385 | headers: this.contentHeaders,
386 | body: body.toString(),
387 | method: "PUT",
388 | };
389 |
390 | return fetch(requestUrl, init)
391 | .then(function (response) {
392 | return response.json();
393 | });
394 | }
395 |
396 | i18nLanguages_list(params: schemas.schema_i18nLanguages_list) {
397 | const method = "i18nLanguages";
398 | const requestUrl = this.create_url(method, params);
399 |
400 | const init = { headers: this.headers };
401 |
402 | return fetch(requestUrl, init)
403 | .then(function (response) {
404 | return response.json();
405 | });
406 | }
407 |
408 | i18nRegions_list(params: schemas.schema_i18nRegions_list) {
409 | const method = "i18nRegions";
410 | const requestUrl = this.create_url(method, params);
411 |
412 | const init = { headers: this.headers };
413 |
414 | return fetch(requestUrl, init)
415 | .then(function (response) {
416 | return response.json();
417 | });
418 | }
419 |
420 | // NOTE: The members.list and membershipsLevels.list methods of the API
421 | // require prior approval from YouTube,
422 | // hence we've not included those methods in this client library.
423 |
424 | playlistItems_list(params: schemas.schema_playlistItems_list) {
425 | const method = "playlistItems";
426 | const requestUrl = this.create_url(method, params);
427 |
428 | const init = { headers: this.headers };
429 |
430 | return fetch(requestUrl, init)
431 | .then(function (response) {
432 | return response.json();
433 | });
434 | }
435 |
436 | playlistItems_insert(
437 | params: schemas.schema_playlistItems_insert,
438 | body: Record,
439 | ) {
440 | const method = "playlistItems";
441 | const requestUrl = this.create_url(method, params);
442 |
443 | const init = {
444 | headers: this.contentHeaders,
445 | body: body.toString(),
446 | method: "POST",
447 | };
448 |
449 | return fetch(requestUrl, init)
450 | .then(function (response) {
451 | return response.json();
452 | });
453 | }
454 |
455 | playlistItems_update(
456 | params: schemas.schema_playlistItems_update,
457 | body: Record,
458 | ) {
459 | const method = "playlistItems";
460 | const requestUrl = this.create_url(method, params);
461 |
462 | const init = {
463 | headers: this.contentHeaders,
464 | body: body.toString(),
465 | method: "PUT",
466 | };
467 |
468 | return fetch(requestUrl, init)
469 | .then(function (response) {
470 | return response.json();
471 | });
472 | }
473 |
474 | playlistItems_delete(params: schemas.schema_playlistItems_delete) {
475 | const method = "playlistItems";
476 | const requestUrl = this.create_url(method, params);
477 |
478 | const init = { headers: this.headers, method: "DELETE" };
479 |
480 | return fetch(requestUrl, init)
481 | .then(function (response) {
482 | return response.json();
483 | });
484 | }
485 |
486 | playlists_list(params: schemas.schema_playlists_list) {
487 | const method = "playlists";
488 | const requestUrl = this.create_url(method, params);
489 |
490 | const init = { headers: this.headers };
491 |
492 | return fetch(requestUrl, init)
493 | .then(function (response) {
494 | return response.json();
495 | });
496 | }
497 |
498 | playlists_insert(
499 | params: schemas.schema_playlists_insert,
500 | body: Record,
501 | ) {
502 | const method = "playlists";
503 | const requestUrl = this.create_url(method, params);
504 |
505 | const init = {
506 | headers: this.contentHeaders,
507 | body: body.toString(),
508 | method: "POST",
509 | };
510 |
511 | return fetch(requestUrl, init)
512 | .then(function (response) {
513 | return response.json();
514 | });
515 | }
516 |
517 | playlists_update(
518 | params: schemas.schema_playlists_update,
519 | body: Record,
520 | ) {
521 | const method = "playlists";
522 | const requestUrl = this.create_url(method, params);
523 |
524 | const init = {
525 | headers: this.contentHeaders,
526 | body: body.toString(),
527 | method: "PUT",
528 | };
529 |
530 | return fetch(requestUrl, init)
531 | .then(function (response) {
532 | return response.json();
533 | });
534 | }
535 |
536 | playlists_delete(params: schemas.schema_playlists_delete) {
537 | const method = "playlists";
538 | const requestUrl = this.create_url(method, params);
539 |
540 | const init = { headers: this.headers, method: "DELETE" };
541 |
542 | return fetch(requestUrl, init)
543 | .then(function (response) {
544 | return response.json();
545 | });
546 | }
547 |
548 | search_list(params: schemas.schema_search_list) {
549 | const method = "search";
550 | const requestUrl = this.create_url(method, params);
551 |
552 | const init = { headers: this.headers };
553 |
554 | return fetch(requestUrl, init)
555 | .then(function (response) {
556 | return response.json();
557 | });
558 | }
559 |
560 | subscriptions_list(params: schemas.schema_subscriptions_list) {
561 | const method = "subscriptions";
562 | const requestUrl = this.create_url(method, params);
563 |
564 | const init = { headers: this.headers };
565 |
566 | return fetch(requestUrl, init)
567 | .then(function (response) {
568 | return response.json();
569 | });
570 | }
571 |
572 | subscriptions_insert(
573 | params: schemas.schema_subscriptions_insert,
574 | body: Record,
575 | ) {
576 | const method = "subscriptions";
577 | const requestUrl = this.create_url(method, params);
578 |
579 | const init = {
580 | headers: this.contentHeaders,
581 | body: body.toString(),
582 | method: "POST",
583 | };
584 |
585 | return fetch(requestUrl, init)
586 | .then(function (response) {
587 | return response.json();
588 | });
589 | }
590 |
591 | subscriptions_delete(params: schemas.schema_subscriptions_delete) {
592 | const method = "subscriptions";
593 | const requestUrl = this.create_url(method, params);
594 |
595 | const init = { headers: this.headers, method: "DELETE" };
596 |
597 | return fetch(requestUrl, init)
598 | .then(function (response) {
599 | return response.json();
600 | });
601 | }
602 |
603 | thumbnails_set(
604 | params: schemas.schema_thumbnails_set,
605 | body?: Record,
606 | ) {
607 | const method = "thumbnails/set";
608 | const requestUrl = this.create_url(method, params);
609 |
610 | const init = {
611 | headers: this.headers,
612 | body: body?.toString(),
613 | method: "POST",
614 | };
615 |
616 | return fetch(requestUrl, init)
617 | .then(function (response) {
618 | return response.json();
619 | });
620 | }
621 |
622 | videoAbuseReportReasons_list(
623 | params: schemas.schema_videoAbuseReportReasons_list,
624 | ) {
625 | const method = "videoAbuseReportReasons";
626 | const requestUrl = this.create_url(method, params);
627 |
628 | const init = { headers: this.headers };
629 |
630 | return fetch(requestUrl, init)
631 | .then(function (response) {
632 | return response.json();
633 | });
634 | }
635 |
636 | videoCategories_list(params: schemas.schema_videoCategories_list) {
637 | const method = "videoCategories";
638 | const requestUrl = this.create_url(method, params);
639 |
640 | const init = { headers: this.headers };
641 |
642 | return fetch(requestUrl, init)
643 | .then(function (response) {
644 | return response.json();
645 | });
646 | }
647 |
648 | videos_list(params: schemas.schema_videos_list) {
649 | const method = "videos";
650 | const requestUrl = this.create_url(method, params);
651 |
652 | const init = { headers: this.headers };
653 |
654 | return fetch(requestUrl, init)
655 | .then(function (response) {
656 | return response.json();
657 | });
658 | }
659 |
660 | videos_insert(
661 | params: schemas.schema_videos_insert,
662 | body: Record,
663 | ) {
664 | const method = "videos";
665 | const requestUrl = this.create_url(method, params);
666 |
667 | const init = {
668 | headers: this.contentHeaders,
669 | body: body.toString(),
670 | method: "POST",
671 | };
672 |
673 | return fetch(requestUrl, init)
674 | .then(function (response) {
675 | return response.json();
676 | });
677 | }
678 |
679 | videos_update(
680 | params: schemas.schema_videos_update,
681 | body: Record,
682 | ) {
683 | const method = "videos";
684 | const requestUrl = this.create_url(method, params);
685 |
686 | const init = {
687 | headers: this.contentHeaders,
688 | body: body.toString(),
689 | method: "PUT",
690 | };
691 |
692 | return fetch(requestUrl, init)
693 | .then(function (response) {
694 | return response.json();
695 | });
696 | }
697 |
698 | videos_rate(params: schemas.schema_videos_rate) {
699 | const method = "videos/rate";
700 | const requestUrl = this.create_url(method, params);
701 |
702 | const init = { headers: this.headers, method: "POST" };
703 |
704 | return fetch(requestUrl, init)
705 | .then(function (response) {
706 | return response.json();
707 | });
708 | }
709 |
710 | videos_getRating(params: schemas.schema_videos_getRating) {
711 | const method = "videos/getRating";
712 | const requestUrl = this.create_url(method, params);
713 |
714 | const init = { headers: this.headers };
715 |
716 | return fetch(requestUrl, init)
717 | .then(function (response) {
718 | return response.json();
719 | });
720 | }
721 |
722 | videos_reportAbuse(
723 | params: schemas.schema_videos_reportAbuse,
724 | body: Record,
725 | ) {
726 | // Provide an empty object {} as first function parameter if you do not
727 | // want to pass any optional url parameters.
728 | // The second parameter being body.
729 | const method = "videos/reportAbuse";
730 | const requestUrl = this.create_url(method, params);
731 |
732 | const init = {
733 | headers: this.contentHeaders,
734 | body: body.toString(),
735 | method: "POST",
736 | };
737 |
738 | return fetch(requestUrl, init)
739 | .then(function (response) {
740 | return response.json();
741 | });
742 | }
743 |
744 | videos_delete(params: schemas.schema_videos_delete) {
745 | const method = "videos";
746 | const requestUrl = this.create_url(method, params);
747 |
748 | const init = { headers: this.headers, method: "DELETE" };
749 |
750 | return fetch(requestUrl, init)
751 | .then(function (response) {
752 | return response.json();
753 | });
754 | }
755 |
756 | watermarks_set(
757 | params: schemas.schema_watermarks_set,
758 | body: Record,
759 | ) {
760 | const method = "watermarks/set";
761 | const requestUrl = this.create_url(method, params);
762 |
763 | const init = {
764 | headers: this.contentHeaders,
765 | body: body.toString(),
766 | method: "POST",
767 | };
768 |
769 | return fetch(requestUrl, init)
770 | .then(function (response) {
771 | return response.json();
772 | });
773 | }
774 |
775 | watermarks_unset(params: schemas.schema_watermarks_unset) {
776 | const method = "watermarks/unset";
777 | const requestUrl = this.create_url(method, params);
778 |
779 | const init = { headers: this.headers, method: "POST" };
780 |
781 | return fetch(requestUrl, init)
782 | .then(function (response) {
783 | return response.json();
784 | });
785 | }
786 | }
787 |
--------------------------------------------------------------------------------