Skip to content

Commit

Permalink
Merge pull request #140 from pierreminiggio/handle-short-uploads-with…
Browse files Browse the repository at this point in the history
…out-config

Handle Shorts Upload Without Config
  • Loading branch information
fawazahmed0 committed Jul 26, 2022
2 parents 755e528 + e5f7e11 commit cdc2816
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export interface Video {
onProgress?: (arg0: VideoProgress) => void
channelName?: string
uploadAsDraft?: boolean
/** Allow setting of a custom selector URL to detect completion (e.g. if using shorts, set this to `https://youtube.com/shorts`) */
customSelectorUrl?: string
}

export enum ProgressEnum {
Expand Down
10 changes: 6 additions & 4 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ async function uploadVideo(videoJSON: Video) {
"//*[normalize-space(text())='Publish']/parent::*[not(@disabled)] | //*[normalize-space(text())='Save']/parent::*[not(@disabled)]"
await page.waitForXPath(publishXPath)
// save youtube upload link
const selector = videoJSON.customSelectorUrl ?? "https://youtu.be";
await page.waitForSelector(`[href^="${selector}"]`)
const uploadedLinkHandle = await page.$(`[href^="${selector}"]`)
const videoBaseLink = 'https://youtu.be'
const shortVideoBaseLink = 'https://youtube.com/shorts'
const uploadLinkSelector = `[href^="${videoBaseLink}"], [href^="${shortVideoBaseLink}"]`
await page.waitForSelector(uploadLinkSelector)
const uploadedLinkHandle = await page.$(uploadLinkSelector)

let uploadedLink
do {
await page.waitForTimeout(500)
uploadedLink = await page.evaluate((e) => e.getAttribute('href'), uploadedLinkHandle)
} while (uploadedLink === selector)
} while (uploadedLink === videoBaseLink || uploadedLink === shortVideoBaseLink)

const closeDialogXPath = uploadAsDraft ? saveCloseBtnXPath : publishXPath
let closeDialog
Expand Down

0 comments on commit cdc2816

Please sign in to comment.