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

Fixed issue where uploading would result in Show More being toggled incorrectly… #180

Merged
merged 2 commits into from
Jan 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ comment(credentials, [comment1], {headless:false}).then(console.log)
- [Sai Charan](https://github.com/charan0017) - For [onSuccess Option](https://github.com/fawazahmed0/youtube-uploader/pull/32)
- [Tue Nguyen](https://github.com/TueeNguyen) - For [Better error messages](https://github.com/fawazahmed0/youtube-uploader/pull/46)
- [weizhiqimail](https://github.com/weizhiqimail) - For [Extra Debug messages](https://github.com/fawazahmed0/youtube-uploader/pull/47)
- [DaddyFrosty](https://github.com/DaddyFrosty) - For [Path Escaping](https://github.com/fawazahmed0/youtube-uploader/pull/55), [Skip Processing wait](https://github.com/fawazahmed0/youtube-uploader/pull/57) and [onProgress event](https://github.com/fawazahmed0/youtube-uploader/pull/60)
- [DaddyFrosty](https://github.com/DaddyFrosty) - For [Path Escaping](https://github.com/fawazahmed0/youtube-uploader/pull/55), [Skip Processing wait](https://github.com/fawazahmed0/youtube-uploader/pull/57), [onProgress event](https://github.com/fawazahmed0/youtube-uploader/pull/60) and [Show More being toggled incorrectly…](https://github.com/fawazahmed0/youtube-uploader/pull/180)
- [Owl Burger](https://github.com/Zebraslive) - For [Create Channel](https://github.com/fawazahmed0/youtube-uploader/pull/66)
- [Ítalo Andrade](https://github.com/italodeandra) - For [Channel Switcher](https://github.com/fawazahmed0/youtube-uploader/pull/73)
- [Dominic Findlay](https://github.com/DominicFindlay) - For Supporting [Single Quotes in playlist name](https://github.com/fawazahmed0/youtube-uploader/pull/82) and [skip processing bug fix](https://github.com/fawazahmed0/youtube-uploader/pull/162)
Expand Down
31 changes: 26 additions & 5 deletions src/upload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Credentials, Video, VideoToEdit, Comment, VideoProgress, ProgressEnum, MessageTransport } from './types'
import puppeteer from 'puppeteer-extra'
import { PuppeteerNodeLaunchOptions, Browser, Page } from 'puppeteer'
import { PuppeteerNodeLaunchOptions, Browser, Page, ElementHandle } from 'puppeteer'
import fs from 'fs-extra'
import path from 'path'

Expand Down Expand Up @@ -217,11 +217,13 @@ async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport)
await textBoxes[0].evaluate(e => (e as any).__shady_native_textContent = "")
await textBoxes[1].type(description.substring(0, maxDescLen))


const childOption = await page.$x('//*[contains(text(),"No, it\'s")]')
await childOption[0].click()
const moreOption = await page.$x("//*[normalize-space(text())='Show more']")
await moreOption[0].click()

// There is no reason for this to be called. Also you should be using #toggle-button not going by the text...
// const moreOption = await page.$x("//*[normalize-space(text())='Show more']")
// await moreOption[0]?.click()

const playlist = await page.$x("//*[normalize-space(text())='Select']")
let createplaylistdone
if (playlistName) {
Expand Down Expand Up @@ -262,6 +264,7 @@ async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport)
}
}
}

if (!videoJSON.isNotForKid) {
await page.click("tp-yt-paper-radio-button[name='VIDEO_MADE_FOR_KIDS_MFK']").catch(()=>{})
} else if (videoJSON.isAgeRestriction) {
Expand All @@ -270,7 +273,25 @@ async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport)
await page.click("tp-yt-paper-radio-button[name='VIDEO_MADE_FOR_KIDS_NOT_MFK']").catch(()=>{})
}
// await page.waitForXPath('//ytcp-badge[contains(@class,"draft-badge")]//div[contains(text(),"Saved as private")]', { timeout: 0})
await page.click("#toggle-button")

// await page.click("#toggle-button")
// Was having issues because of await page.$x("//*[normalize-space(text())='Show more']").click(), so I started messing with the line above.
// The issue was obviously not the line above but I either way created code to ensure that Show more has been pressed before proceeding.
let showMoreButton = await page.$( "#toggle-button" )
if ( showMoreButton == undefined )
throw `uploadVideo - Toggle button not found.`
else {
// console.log( "Show more start." )
let moreInformation: ElementHandle
while ( ( moreInformation = await page.$( "ytcp-video-metadata-editor-advanced" ) ) == undefined )
{
// console.log( "Show more while." )
await showMoreButton.click()
await sleep( 1000 )
}
// console.log( "Show more finished." )
}

// Add tags
if (tags) {
//show more
Expand Down