-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (40 loc) · 2.19 KB
/
Copy pathtest.js
File metadata and controls
51 lines (40 loc) · 2.19 KB
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
/* Import Library */
const iyoutube = require("../");
//OR ESM:
//import * as iyoutube from 'iyoutube';
(async function() {
//Get new Instance for Node.JS (! REQUIRES ASYNC USAGE !)
const ytClient = await iyoutube.nodeDefault();
//Init the Client
await ytClient.init();
//Check if there needs to be User Login
if (ytClient.authenticator.requiresLogin()) {
//Get new Codes for Login
var codes = await ytClient.authenticator.getNewLoginCode();
//Display message with Code and URL for User Action
console.log("This program requires Login at: " + codes.userUrl);
console.log("Use the following Code: " + codes.userCode);
//Load the Tokens with the Device Code (will wait until finished)
await ytClient.authenticator.loadTokensWithDeviceCode(codes.deviceCode);
console.log("Thank you for login!");
}
//We are now Authenticated and can get started
var testPlaylist = await ytClient.getUser().getLikedPlaylist(); //Get the Watch Later Playlist
await testPlaylist.loadAll(); //Load all Details we can get
console.log(testPlaylist.videoCount);
var testPlaylistVideos = testPlaylist.getContinuatedList(); //Get the Continuated List
await testPlaylistVideos.loadFurhter(); //Load Batch of Videos into List
console.log(testPlaylistVideos.getVideos().length);
await testPlaylistVideos.loadFurhter(); //Load next Batch of Videos into List
console.log(testPlaylistVideos.getVideos().length);
console.log(testPlaylistVideos.endReached);
//Dirty way of getting the Results (without any Type), use the Getters instead!
console.log(testPlaylistVideos.results);
var testWhat = ytClient.getWhatToWatch(); //Get the Start Page Video List (what to watch Page)
await testWhat.loadFurhter(); //Load Batch of Videos from List
console.log(testWhat.getVideos().length);
await testWhat.loadFurhter(); //Load Batch of Videos from List
console.log(testWhat.getVideos().length);
// The Video Amount per Batch varies from List Type (e.g Playlist, Search) but also from Randomness of the Youtube API
// Hint: loadFurther() returns the new Videos and adds them to the results at the same Time
})();