Skip to content

Commit

Permalink
Merge pull request #105 from coooo77/main
Browse files Browse the repository at this point in the history
Add feature: upload videos as draft
  • Loading branch information
fawazahmed0 authored May 25, 2022
2 parents 81a92c7 + 049c970 commit efab93e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface Video {
onSuccess?: (url: string) => void
skipProcessingWait?: boolean
onProgress?: (arg0: VideoProgress) => void
channelName: string
channelName?: string,
uploadAsDraft?: boolean
}

export enum ProgressEnum {
Expand Down
13 changes: 10 additions & 3 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ async function uploadVideo(videoJSON: Video) {
const playlistName = videoJSON.playlist
const videoLang = videoJSON.language
const thumb = videoJSON.thumbnail
const uploadAsDraft = videoJSON.uploadAsDraft
await page.evaluate(() => {
window.onbeforeunload = null
})
await page.goto(uploadURL)

const closeBtnXPath = "//*[normalize-space(text())='Close']"
const selectBtnXPath = "//*[normalize-space(text())='Select files']"
const saveCloseBtnXPath = '//*[@aria-label="Save and close"]/tp-yt-iron-icon'
for (let i = 0; i < 2; i++) {
try {
await page.waitForXPath(selectBtnXPath)
Expand Down Expand Up @@ -285,17 +287,22 @@ async function uploadVideo(videoJSON: Video) {
uploadedLink = await page.evaluate((e) => e.getAttribute('href'), uploadedLinkHandle)
} while (uploadedLink === 'https://youtu.be/')

let publish
const closeDialogXPath = uploadAsDraft ? saveCloseBtnXPath : publishXPath
let closeDialog
for (let i = 0; i < 10; i++) {
try {
publish = await page.$x(publishXPath)
await publish[0].click()
closeDialog = await page.$x(closeDialogXPath)
await closeDialog[0].click()
break
} catch (error) {
await page.waitForTimeout(5000)
}
}
// await page.waitForXPath('//*[contains(text(),"Finished processing")]', { timeout: 0})

// no closeBtn will show up if keeps video as draft
if (uploadAsDraft) return uploadedLink

// Wait for closebtn to show up
try {
await page.waitForXPath(closeBtnXPath)
Expand Down

0 comments on commit efab93e

Please sign in to comment.