Skip to content

Commit

Permalink
fix stuck at upload & fix thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
fawazahmed0 committed Jul 25, 2022
1 parent 84cfae2 commit 963c74f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ test

# IDE
.idea
thumbnail.jpg
19 changes: 11 additions & 8 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,16 @@ async function uploadVideo(videoJSON: Video) {
}, 500)
}
// Check if daily upload limit is reached
await page.waitForXPath('//*[contains(text(),"Daily upload limit reached")]', { timeout: 15000 }).then(() => {
await page.waitForXPath('//*[contains(text(),"Daily upload limit reached")]', { timeout: 500 }).then(() => {
console.log("Daily upload limit reached.");
browser.close();
}).catch(() => {});

// Wait for upload to complete
await page.waitForXPath('//*[contains(text(),"Upload complete")]', { hidden: true, timeout: 0 })
// Wait for upload to complete
await page.waitForXPath('//*[contains(text(),"Upload complete")]', { timeout: 0 })
// Wait for upload to go away and processing to start
await page.waitForXPath('//*[contains(text(),"Upload complete")]', { hidden: true, timeout: 0 })

if (videoJSON.onProgress) {
progress = { progress: 0, stage: ProgressEnum.Processing }
videoJSON.onProgress(progress)
Expand All @@ -188,12 +191,12 @@ async function uploadVideo(videoJSON: Video) {

// Wait until title & description box pops up
if (thumb) {
let thumbnailChooserXpath = xpathTextSelector("upload thumbnail")
await page.waitForXPath(thumbnailChooserXpath)
const thumbBtn = await page.$x(thumbnailChooserXpath)
const [thumbChooser] = await Promise.all([
page.waitForFileChooser(),
await page.waitForSelector(
`[class="remove-default-style style-scope ytcp-thumbnails-compact-editor-uploader"]`
),
await page.click(`[class="remove-default-style style-scope ytcp-thumbnails-compact-editor-uploader"]`)
thumbBtn[0].click() // button that triggers file selection
])
await thumbChooser.accept([thumb])
}
Expand Down Expand Up @@ -994,7 +997,7 @@ function escapeQuotesForXPath(str: string) {
return "concat(" + parts.join(",") + ")";
}

function xpathTextSelector( text: string, caseSensitive: boolean, nthElement: number ){
function xpathTextSelector( text: string, caseSensitive?: boolean, nthElement?: number ){
let xpathSelector = ''
if(caseSensitive)
xpathSelector = `//*[contains(normalize-space(text()),"${text}")]`
Expand Down

0 comments on commit 963c74f

Please sign in to comment.