server/page/video_editor.js
// TODO: feels very fragile, find another way.
feels very fragile, find another way.
feels very fragile find another way .
async trimToRandomDuration() {
		await this.clickButton(
			'//ytcp-button[@id="trim-button"]//div[contains(text(), "Trim")]'
		)
		await this.tab().waitForXPath("//ytve-trim-marker")
		const trimMarkers = await this.tab().$x("//ytve-trim-marker")
		if (trimMarkers.length != 2) {
			throw new Error(
				"Unexpected number of trim markers: " + trimMarkers.length
			)
		}
		const [leftTrim, rightTrim] = trimMarkers
		const leftBox = await leftTrim.boundingBox()
		const rightBox = await rightTrim.boundingBox()
		const leftCenterX = leftBox.x + (leftBox.width >> 1)
		const rightCenterX = rightBox.x + (rightBox.width >> 1)
		const rightCenterY = rightBox.y + (rightBox.height >> 1)
		const randomTargetX =
			leftCenterX +
			(rightCenterX - leftCenterX) * (Math.random() * 0.6 + 0.2)
		await this.tab().mouse().move(rightCenterX, rightCenterY, { steps: 10 })
		await this.tab().mouse().down()
		await this.tab().mouse().move(randomTargetX, rightCenterY)
		await this.tab().mouse().up()
		await this.tab()
			.mouse()
			.click(randomTargetX, rightBox.y - 15)
		const playhead = await this.tab().waitForXPath(
			'//ytve-playhead[@id="playhead"]'
		)
		const playheadTime = await playhead.evaluate((x) =>
			x.getAttribute("aria-label")
		)
		const rematch = playheadTime.match(/^Playhead ([0-9:]+)$/)
		if (rematch == null || rematch.length != 2) {
			throw new Error("Unexpected playhead aria-label: " + playheadTime)
		}
		const newDuration_s = parseDurationUtil.hhmmssffToSeconds(rematch[1])
		await this.clickButton(
			'//ytcp-button//*[contains(.//text(), "Preview")]'
		)
		await this.clickButton(
			'//ytcp-button[@id="save-button"]//div[contains(.//text(), "Save")]'
		)
		await this.clickButton(
			'//ytcp-button[@dialog-confirm and @label="Save"]//*[contains(.//text(),"Save")]'
		)
		await this.tab().waitForXPath(
			'//*[contains(.//text(), "Video is being processed")]'
		)
		return newDuration_s
	}
async trimToRandomDuration ( ) { await this . clickButton ( '//ytcp-button[@id="trim-button"]//div[contains(text(), "Trim")]' ) await this . tab ( ) . waitForXPath ( "//ytve-trim-marker" ) const trimMarkers = await this . tab ( ) . $x ( "//ytve-trim-marker" ) if ( trimMarkers . length != 2 ) { throw new Error ( "Unexpected number of trim markers: " + trimMarkers . length ) } const [ leftTrim , rightTrim ] = trimMarkers const leftBox = await leftTrim . boundingBox ( ) const rightBox = await rightTrim . boundingBox ( ) const leftCenterX = leftBox . x + ( leftBox . width >> 1 ) const rightCenterX = rightBox . x + ( rightBox . width >> 1 ) const rightCenterY = rightBox . y + ( rightBox . height >> 1 ) const randomTargetX = leftCenterX + ( rightCenterX - leftCenterX ) * ( Math . random ( ) * 0.6 + 0.2 ) await this . tab ( ) . mouse ( ) . move ( rightCenterX , rightCenterY , { steps : 10 } ) await this . tab ( ) . mouse ( ) . down ( ) await this . tab ( ) . mouse ( ) . move ( randomTargetX , rightCenterY ) await this . tab ( ) . mouse ( ) . up ( ) await this . tab ( ) . mouse ( ) . click ( randomTargetX , rightBox . y - 15 ) const playhead = await this . tab ( ) . waitForXPath ( '//ytve-playhead[@id="playhead"]' ) const playheadTime = await playhead . evaluate ( ( x ) => x . getAttribute ( "aria-label" ) ) const rematch = playheadTime . match ( / ^Playhead ([0-9:]+)$ / ) if ( rematch == null || rematch . length != 2 ) { throw new Error ( "Unexpected playhead aria-label: " + playheadTime ) } const newDuration_s = parseDurationUtil . hhmmssffToSeconds ( rematch [ 1 ] ) await this . clickButton ( '//ytcp-button//*[contains(.//text(), "Preview")]' ) await this . clickButton ( '//ytcp-button[@id="save-button"]//div[contains(.//text(), "Save")]' ) await this . clickButton ( '//ytcp-button[@dialog-confirm and @label="Save"]//*[contains(.//text(),"Save")]' ) await this . tab ( ) . waitForXPath ( '//*[contains(.//text(), "Video is being processed")]' ) return newDuration_s }
TODO: feels very fragile, find another way.
TODO : feels very fragile find another way .
// Get the left and right trim markers and their locations. // Click just above where we have scrolled to in order to move the // "playhead" to the same location, then read the playhead's label // which contains the duration we're now trimming to. // TODO: horribly hacky way to get the length that we've trimmed to, // even for already being inside of a horrible hack. // TODO: this won't handle minutes. // Now click save.