Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Shorts Upload Without Config #140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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