jy95 / YTscheduledVideos2Ical

Extract your scheduled videos publish date to a ical file so that it allows you to to see your scheduling in your favorite calendar app
MIT License
4 stars 0 forks source link

Reverse engineering : New Creator Studio #1

Open jy95 opened 6 years ago

jy95 commented 6 years ago

This issue will resume all my discoveries about how the new interface ( https://studio.youtube.com ) got scheduled videos

When going on video tab , the following request is done (as POST Method) :

https://studio.youtube.com/youtubei/v1/creator/list_creator_videos?alt=json&key=[INNERTUBE_API_KEY]

Where [INNERTUBE_API_KEY] can be found, for example in the HTML body of a embeb video (here a TubeBuddy one) + query parameters

https://www.youtube.com/embed/ZlkPcrAlLoo?rel=0&showinfo=0

in some script balise that begins with yt.setConfig within the key can be found in the object parameter (Full balise Path in document : iframe > html > body > script)

// ... are the other properties I don't need
yt.setConfig({..., "INNERTUBE_API_KEY": "YOUR_INNERTUBE_API_KEY" })

The result of this request give a json that looks like this one :

{
  "nextPageToken": "CAASUwom9_uFVAb_____Mk5JNXFjSHFRZlEA_wH__jJOSTVxY0hxUWZRAAEQHiHqXSSSBd3_5jkAAAAA-at6BEgBUAJaCwklcGPVpVuw1xACYL3XqocF",
  "totalSize": "128",
  "totalSizeAccuracy": "ACCURACY_ESTIMATION",
  "videos": [
        // A videoItem object 
  ],
  "videosTotalSize": {
    "size": "128",
    "accuracy": "ACCURACY_ESTIMATION",
    "achievedTotalSizeAccuracy": "CREATOR_ACHIEVED_TOTAL_SIZE_ACCURACY_LOW"
  }
}

A video object which was scheduled looks like this example in the wiki : https://github.com/jy95/YTscheduledVideos2Ical/wiki/VideoItem-Object

As you can see, in order to extract videos that are still scheduled is to filter videoItem that have this property

// This property could be undefined since scheduledPublishingDetails  is {} for public video
scheduledPublishingDetails.scheduledPublishings.scheduledTimeSeconds

This scheduledTimeSeconds can be easily converted to a Date item (since it is a Unix timestamp)

var scheduledTimeSeconds = 1534501800
new Date(scheduledTimeSeconds *1000).toISOString()

EDIT : Still not finished , I need to talk about the autorization field and the requested size for request ...

jy95 commented 6 years ago

The POST request can be resumed as (Warning : Firebug didn't copy the headers so I will do it manually later ) :

fetch("https://studio.youtube.com/youtubei/v1/creator/list_creator_videos?alt=json&key=[INNERTUBE_API_KEY]", {
    "credentials": "include",
    "headers": {},
    "referrer": "https://studio.youtube.com/?utm_source=NONE&utm_campaign=upgrade&utm_medium=sidebar_button",
    "referrerPolicy": "no-referrer-when-downgrade",
    "method": "POST",
    // the full request object : https://github.com/jy95/YTscheduledVideos2Ical/wiki/Request-object
    "body": JSON.stringify({})
    "mode": "cors"
});