Skip to content

Commit

Permalink
getVideos API added
Browse files Browse the repository at this point in the history
  • Loading branch information
adasq committed Jan 4, 2023
1 parent 5489215 commit d91d8d4
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "youtube-studio",
"version": "0.0.22",
"version": "0.0.23",
"description": "Unofficial YouTube Studio API",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "echo 'ignore'"
},
"repository": {
"type": "git",
Expand Down
92 changes: 92 additions & 0 deletions src/youtube-studio-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ async function getConfig() {
VISITOR_DATA: windowRef.ytcfg.data_.VISITOR_DATA,
INNERTUBE_API_KEY: windowRef.ytcfg.data_.INNERTUBE_API_KEY,
DELEGATED_SESSION_ID: windowRef.ytcfg.data_.DELEGATED_SESSION_ID,
CHANNEL_ID: windowRef.ytcfg.data_.CHANNEL_ID
};
} catch (err) {
}
Expand Down Expand Up @@ -233,6 +234,22 @@ async function getVideo(videoId) {
.then(res => res.json())
}

async function getVideos(pageSize = 30) {
const template = list_creator_videos_template;


_.set(template, 'pageSize', pageSize);
_.set(template, 'context.user.delegationContext.externalChannelId', config.CHANNEL_ID);
_.set(template, 'filter.and.operands[0].channelIdIs.value', config.CHANNEL_ID);

return fetch(`${YT_STUDIO_URL}/youtubei/v1/creator/list_creator_videos?alt=json&key=${config.INNERTUBE_API_KEY}`, {
method: 'POST',
headers,
body: `${JSON.stringify(template)}`
})
.then(res => res.json())
}


const POSITION_TOP_LEFT = {
"left": 0.022807017,
Expand Down Expand Up @@ -622,6 +639,80 @@ const get_creator_videos_template = {
}
}


const list_creator_videos_template = {
"filter": {"and": {"operands": [{"channelIdIs": {"value": IT_WILL_BE_SET_DURING_REQUEST_BUILD}}, {"videoOriginIs": {"value": "VIDEO_ORIGIN_UPLOAD"}}]}},
"order": "VIDEO_ORDER_DISPLAY_TIME_DESC",
"pageSize": 30,
"mask": {
"channelId": true,
"videoId": true,
"lengthSeconds": true,
"livestream": {"all": true},
"publicLivestream": {"all": true},
"origin": true,
"premiere": {"all": true},
"publicPremiere": {"all": true},
"status": true,
"thumbnailDetails": {"all": true},
"title": true,
"draftStatus": true,
"downloadUrl": true,
"watchUrl": true,
"shareUrl": true,
"permissions": {"all": true},
"timeCreatedSeconds": true,
"timePublishedSeconds": true,
"privacy": true,
"contentOwnershipModelSettings": {"all": true},
"features": {"all": true},
"shorts": {"all": true},
"responseStatus": {"all": true},
"statusDetails": {"all": true},
"description": true,
"metrics": {"all": true},
"titleFormattedString": {"all": true},
"descriptionFormattedString": {"all": true},
"audienceRestriction": {"all": true},
"allRestrictions": {"all": true},
"inlineEditProcessingStatus": true,
"videoPrechecks": {"all": true},
"selfCertification": {"all": true},
"contentType": true,
"videoResolutions": {"all": true},
"scheduledPublishingDetails": {"all": true},
"visibility": {"all": true},
"privateShare": {"all": true},
"sponsorsOnly": {"all": true},
"unlistedExpired": true,
"videoTrailers": {"all": true},
"remix": {"isSource": true}
},
"context": {
"client": {
"clientName": 62,
"clientVersion": "1.20230102.03.00",
"hl": "en",
"gl": "PL",
"experimentsToken": "",
"utcOffsetMinutes": 60,
"userInterfaceTheme": "USER_INTERFACE_THEME_DARK",
"screenWidthPoints": 1920,
"screenHeightPoints": 714,
"screenPixelDensity": 1,
"screenDensityFloat": 1
},
"request": {"returnLogEntry": true, "internalExperimentFlags": []},
"user": {
"delegationContext": {
"externalChannelId": IT_WILL_BE_SET_DURING_REQUEST_BUILD,
"roleType": {"channelRoleType": "CREATOR_CHANNEL_ROLE_TYPE_OWNER"}
}, "serializedDelegationContext": ""
},
"clientScreenNonce": ""
}
}

module.exports = {
init,
getVideo,
Expand All @@ -631,6 +722,7 @@ module.exports = {
getEndScreen,
endScreen,
getDebugInfo,
getVideos,
setInfoCards,
getVideoClaims,
upload
Expand Down
13 changes: 10 additions & 3 deletions src/youtube-studio-api.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
jest.requireActual('node-fetch')
const nconf = require('nconf')

const { setMonetisation, setCommentOptions, init, setInfoCards, getVideo, setEndScreen, getEndScreen, endScreen, getVideoClaims, upload } = require('./youtube-studio-api');
const { setMonetisation, setCommentOptions, init, setInfoCards, getVideo, setEndScreen, getEndScreen, endScreen, getVideoClaims, upload,
getVideos
} = require('./youtube-studio-api');

nconf.env().file({ file: './config.json' });

Expand Down Expand Up @@ -98,11 +100,16 @@ describe('for authenticated user', () => {

expect(video.videoId).toEqual(VIDEO_ID)
expect(video.status).toEqual("VIDEO_STATUS_PROCESSED")
expect(video.monetization.adMonetization.effectiveStatus).toEqual("VIDEO_MONETIZING_STATUS_MONETIZING_WITH_LIMITED_ADS")
expect(video.lengthSeconds).toEqual("1404")
expect(video.monetization.adMonetization.effectiveStatus).toEqual("VIDEO_MONETIZING_STATUS_NOT_MONETIZING_CHANNEL_NOT_MONETIZING")
expect(video.lengthSeconds).toEqual("1271")
expect(video.watchUrl).toEqual("https://www.youtube.com/watch?v=" + VIDEO_ID)
})

it('should list videos', async () => {
const result = await getVideos(60)
expect(result.videos.length).toBeGreaterThan(0)
})

describe('info cards', () => {
it('should set info cards', async () => {
const result = await setInfoCards(VIDEO_ID, [
Expand Down

0 comments on commit d91d8d4

Please sign in to comment.