1
+ import { config } from "../../src/config" ;
2
+ import assert from "assert" ;
3
+ // import { innerTubeVideoDetails } from "../../src/types/innerTubeApi.model";
4
+ import { YouTubeAPI } from "../../src/utils/youtubeApi" ;
5
+ import * as innerTube from "../../src/utils/innerTubeAPI" ;
6
+ import { partialDeepEquals } from "../utils/partialDeepEquals" ;
7
+
8
+
9
+ const videoID = "dQw4w9WgXcQ" ;
10
+ const expected = { // partial type of innerTubeVideoDetails
11
+ videoId : videoID ,
12
+ title : "Rick Astley - Never Gonna Give You Up (Official Music Video)" ,
13
+ lengthSeconds : "212" ,
14
+ channelId : "UCuAXFkgsw1L7xaCfnd5JJOw" ,
15
+ isOwnerViewing : false ,
16
+ isCrawlable : true ,
17
+ allowRatings : true ,
18
+ author : "Rick Astley" ,
19
+ isPrivate : false ,
20
+ isUnpluggedCorpus : false ,
21
+ isLiveContent : false
22
+ } ;
23
+ const currentViews = 1284257550 ;
24
+
25
+ describe ( "innertube API test" , function ( ) {
26
+ it ( "should be able to get innerTube details" , async ( ) => {
27
+ const result = await innerTube . getPlayerData ( videoID ) ;
28
+ assert . ok ( partialDeepEquals ( result , expected ) ) ;
29
+ } ) ;
30
+ it ( "Should have more views than current" , async ( ) => {
31
+ const result = await innerTube . getPlayerData ( videoID ) ;
32
+ assert . ok ( Number ( result . viewCount ) >= currentViews ) ;
33
+ } ) ;
34
+ it ( "Should have the same video duration from both endpoints" , async ( ) => {
35
+ const playerData = await innerTube . getPlayerData ( videoID ) ;
36
+ const length = await innerTube . getLength ( videoID ) ;
37
+ assert . equal ( Number ( playerData . lengthSeconds ) , length ) ;
38
+ } ) ;
39
+ it ( "Should have equivalent response from NewLeaf" , async function ( ) {
40
+ if ( ! config . newLeafURLs || config . newLeafURLs . length <= 0 || config . newLeafURLs [ 0 ] == "placeholder" ) this . skip ( ) ;
41
+ const itResponse = await innerTube . getPlayerData ( videoID ) ;
42
+ const newLeafResponse = await YouTubeAPI . listVideos ( videoID , true ) ;
43
+ // validate videoID
44
+ assert . strictEqual ( itResponse . videoId , videoID ) ;
45
+ assert . strictEqual ( newLeafResponse . data ?. videoId , videoID ) ;
46
+ // validate description
47
+ assert . strictEqual ( itResponse . shortDescription , newLeafResponse . data ?. description ) ;
48
+ // validate authorId
49
+ assert . strictEqual ( itResponse . channelId , newLeafResponse . data ?. authorId ) ;
50
+ } ) ;
51
+ } ) ;
0 commit comments