Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update googlevideo to 4.0.2
  • Loading branch information
absidue committed Jul 25, 2025
commit 36e76b4d9a7fd7f954c48a523ea8486c023629d2
2 changes: 2 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"compilerOptions": {
"strictNullChecks": true,
"baseUrl": "./",
"module": "esnext",
"moduleResolution": "bundler",
"paths": {
"DB_HANDLERS_ELECTRON_RENDERER_OR_WEB": [
"src/datastores/handlers/electron",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"autolinker": "^4.1.5",
"bgutils-js": "^3.2.0",
"electron-context-menu": "^4.1.0",
"googlevideo": "^3.0.0",
"googlevideo": "^4.0.2",
"marked": "^16.1.1",
"portal-vue": "^2.1.7",
"process": "^0.11.10",
Expand Down
16 changes: 15 additions & 1 deletion src/renderer/helpers/player/SabrManifestParser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import shaka from 'shaka-player'
import { parseWebmSegmentIndex } from './WebmSegmentIndexParser'
import { parseMp4SegmentIndex } from './Mp4SegmentIndexParser'
import { QUALITY } from 'googlevideo'

/**
* @typedef {{
Expand Down Expand Up @@ -586,6 +585,21 @@ function createImageStreams(storyboards, presentationTimeline, currentId) {
})
}

const QUALITY = {
AUTO: 0,
TINY: 144,
SMALL: 240,
MEDIUM: 360,
LIGHT: 144,
LARGE: 480,
HD720: 720,
HD1080: 1080,
HD1440: 1440,
HD2160: 2160,
HD2880: 2880,
HIGHRES: 4320
}

/**
* @param {SabrManifest['formats'][0]} format
* @param {shaka.extern.Stream} stream
Expand Down
68 changes: 39 additions & 29 deletions src/renderer/helpers/player/SabrSchemePlugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { GoogleVideo, base64ToU8, concatenateChunks, PART, Protos } from 'googlevideo'
import {
MediaHeader,
SabrError,
SabrRedirect,
StreamProtectionStatus,
UMPPartId,
VideoPlaybackAbrRequest
} from 'googlevideo/protos'
import { CompositeBuffer, UmpReader } from 'googlevideo/ump'
import { base64ToU8, concatenateChunks, EnabledTrackTypes } from 'googlevideo/utils'
import shaka from 'shaka-player'

import { deepCopy } from '../utils'
Expand All @@ -20,7 +29,7 @@ function formatIdFromString(str) {
}

/**
* @param {Protos.FormatId} formatId
* @param {import('googlevideo/protos').FormatId} formatId
* @param {shaka.extern.BufferedRange} buffered
* @param {shaka.media.SegmentIndex} segmentIndex
*/
Expand All @@ -38,7 +47,7 @@ function createBufferedRange(formatId, buffered, segmentIndex) {
* @param {shaka.Player} player
* @param {shaka.extern.Manifest} manifest
* @param {boolean} audioFormatsActive
* @param {Protos.BufferedRange[]} bufferedRanges
* @param {import('googlevideo/protos').BufferedRange[]} bufferedRanges
* @param {shaka.extern.Track} activeVariant
*/
function fillBufferedRanges(player, manifest, audioFormatsActive, bufferedRanges, activeVariant) {
Expand Down Expand Up @@ -138,8 +147,8 @@ async function doRequest(
headersReceived
) {
let response
/** @type {GoogleVideo.ChunkedDataBuffer | null} */
let chunkedDataBuffer = null
/** @type {CompositeBuffer | null} */
let compositeBuffer = null
/** @type {Uint8Array[]} */
const responseDataChunks = []
let segmentComplete = false
Expand All @@ -161,35 +170,35 @@ async function doRequest(
let readObj = await reader.read()

while (!readObj.done && !abortStatus.finished) {
if (chunkedDataBuffer) {
chunkedDataBuffer.append(readObj.value)
if (compositeBuffer) {
compositeBuffer.append(readObj.value)
} else {
chunkedDataBuffer = new GoogleVideo.ChunkedDataBuffer([readObj.value])
compositeBuffer = new CompositeBuffer([readObj.value])
}

const remainingData = new GoogleVideo.UMP(chunkedDataBuffer).parse((part) => {
const remainingData = new UmpReader(compositeBuffer).read((part) => {
switch (part.type) {
case PART.STREAM_PROTECTION_STATUS: {
const streamProtectionStatus = Protos.StreamProtectionStatus.decode(part.data.chunks[0])
case UMPPartId.STREAM_PROTECTION_STATUS: {
const streamProtectionStatus = StreamProtectionStatus.decode(part.data.chunks[0])
if (streamProtectionStatus.status === 3) {
invalidPoToken = true
}
break
}
case PART.SABR_ERROR: {
const sabrError = Protos.SabrError.decode(part.data.chunks[0])
case UMPPartId.SABR_ERROR: {
const sabrError = SabrError.decode(part.data.chunks[0])
error = `SABR Error: type: ${sabrError.type}, code: ${sabrError.code}`
break
}
case PART.SABR_REDIRECT: {
const sabrRedirect = Protos.SabrRedirect.decode(part.data.chunks[0])
case UMPPartId.SABR_REDIRECT: {
const sabrRedirect = SabrRedirect.decode(part.data.chunks[0])
redirectUrl = sabrRedirect.url
updateSabrUrl(redirectUrl)
break
}
case PART.MEDIA_HEADER: {
case UMPPartId.MEDIA_HEADER: {
if (mediaHeaderId === undefined) {
const mediaHeader = Protos.MediaHeader.decode(part.data.chunks[0])
const mediaHeader = MediaHeader.decode(part.data.chunks[0])

if (
mediaHeader.formatId.itag === itag &&
Expand All @@ -206,13 +215,13 @@ async function doRequest(

break
}
case PART.MEDIA: {
case UMPPartId.MEDIA: {
if (mediaHeaderId === part.data.getUint8(0)) {
responseDataChunks.push(...part.data.split(1).remainingBuffer.chunks)
}
break
}
case PART.MEDIA_END: {
case UMPPartId.MEDIA_END: {
if (mediaHeaderId === part.data.getUint8(0)) {
segmentComplete = true
abortStatus.finished = true
Expand All @@ -225,9 +234,9 @@ async function doRequest(

if (!abortStatus.finished) {
if (remainingData) {
chunkedDataBuffer = remainingData.data
compositeBuffer = remainingData.data
} else {
chunkedDataBuffer = null
compositeBuffer = null
}

readObj = await reader.read()
Expand Down Expand Up @@ -409,7 +418,7 @@ export function setupSabrScheme(sabrData, getPlayer, getManifest, playerWidth, p
}
}

/** @type {Protos.BufferedRange[]} */
/** @type {import('googlevideo/protos').BufferedRange[]} */
const bufferedRanges = []

if (!isInit && activeVariant) {
Expand All @@ -426,30 +435,31 @@ export function setupSabrScheme(sabrData, getPlayer, getManifest, playerWidth, p

const resolution = streamIsVideo ? parseInt(url.searchParams.get('resolution')) : undefined

/** @type {Protos.VideoPlaybackAbrRequest} */
/** @type {import('googlevideo/protos').VideoPlaybackAbrRequest} */
const requestData = {
clientAbrState: {
bandwidthEstimate: Math.round(player.getStats().estimatedBandwidth),
timeSinceLastManualFormatSelectionMs: streamIsVideo ? 0 : undefined,
stickyResolution: resolution,
lastManualSelectedResolution: resolution,
playbackRate: player.getPlaybackRate(),
enabledTrackTypesBitfield: streamIsAudio ? 1 : 0,
enabledTrackTypesBitfield: streamIsAudio ? EnabledTrackTypes.AUDIO_ONLY : EnabledTrackTypes.VIDEO_AND_AUDIO,
drcEnabled,
playerTimeMs,
clientViewportWidth: playerWidth.value,
clientViewportHeight: playerHeight.value,
clientViewportIsFlexible: false
},
selectedAudioFormatIds: [audioFormatId],
selectedVideoFormatIds: [videoFormatId],
preferredAudioFormatIds: [audioFormatId],
preferredVideoFormatIds: [videoFormatId],
preferredSubtitleFormatIds: [],
selectedFormatIds: isInit ? [] : [audioFormatId, videoFormatId],
bufferedRanges,
streamerContext: {
poToken: poToken,
clientInfo: clientInfo,
field5: [],
field6: []
sabrContexts: [],
unsentSabrContexts: []
},
field1000: [],
videoPlaybackUstreamerConfig,
Expand All @@ -458,7 +468,7 @@ export function setupSabrScheme(sabrData, getPlayer, getManifest, playerWidth, p
let body

try {
body = Protos.VideoPlaybackAbrRequest.encode(requestData).finish()
body = VideoPlaybackAbrRequest.encode(requestData).finish()
} catch (error) {
console.error('Invalid VideoPlaybackAbrRequest data', requestData)
throw error
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4813,10 +4813,10 @@ globjoin@^0.1.4:
resolved "https://registry.yarnpkg.com/globjoin/-/globjoin-0.1.4.tgz#2f4494ac8919e3767c5cbb691e9f463324285d43"
integrity sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==

googlevideo@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/googlevideo/-/googlevideo-3.0.0.tgz#383137303553c6625bafae32c1b8a7203be565a8"
integrity sha512-8LGFjbZFG4RCsyhMbjX2+IlU5Suj94FeQr1JandPSsKfAMrqL08pOoQsBYl/5P+bqIFm0wQEVpKIhm5wpiekwg==
googlevideo@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/googlevideo/-/googlevideo-4.0.2.tgz#981a854c4b198e20c0f180785383a9511c9d50c4"
integrity sha512-Act4v5gCsJ9WL6+/XbJwnAF/Ui/pEQHqBve5eN4VCni+cy7xoJ/fWLP0TMdsaTzSH+OK3+6vNI0Y9tW9sFysqg==
dependencies:
"@bufbuild/protobuf" "^2.0.0"

Expand Down
Loading