Skip to content

Commit

Permalink
Merge pull request #203 from ClassAxion/main
Browse files Browse the repository at this point in the history
feat: support monetized channels
  • Loading branch information
fawazahmed0 authored Mar 13, 2023
2 parents 4416b37 + a15c57c commit b8fc6e9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Video {
uploadAsDraft?: boolean
isAgeRestriction?: boolean
isNotForKid?: boolean
isChannelMonetized?: boolean
gameTitleSearch?: string
gameSelector?: ( arg0: GameData ) => Promise<boolean> | null
}
Expand Down
50 changes: 48 additions & 2 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,44 @@ async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport)
await selectGame( page, gameTitleSearch, videoJSON.gameSelector )
}

// click next button
const nextBtnXPath = "//*[normalize-space(text())='Next']/parent::*[not(@disabled)]"
let next

if (videoJSON.isChannelMonetized) { // Always enable monetization if channel is monetized
await page.waitForXPath(nextBtnXPath);
next = await page.$x(nextBtnXPath);
await next[0].click();

await page.waitForSelector("#child-input ytcp-video-monetization", { visible: true });

await page.waitForTimeout(1500);

await page.click("#child-input ytcp-video-monetization");

await page.waitForSelector(
"ytcp-video-monetization-edit-dialog.cancel-button-hidden .ytcp-video-monetization-edit-dialog #radioContainer #onRadio"
);
await page.evaluate(() =>
document
.querySelector(
"ytcp-video-monetization-edit-dialog.cancel-button-hidden .ytcp-video-monetization-edit-dialog #radioContainer #onRadio"
)
.click()
);

await page.waitForTimeout(1500);

await page.waitForSelector(
"ytcp-video-monetization-edit-dialog.cancel-button-hidden .ytcp-video-monetization-edit-dialog #save-button",
{ visible: true }
);
await page.click(
"ytcp-video-monetization-edit-dialog.cancel-button-hidden .ytcp-video-monetization-edit-dialog #save-button"
);
}

await page.waitForXPath(nextBtnXPath)
let next = await page.$x(nextBtnXPath)
next = await page.$x(nextBtnXPath)
await next[0].click()
// await sleep(2000)
await page.waitForXPath(nextBtnXPath)
Expand Down Expand Up @@ -379,6 +413,18 @@ async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport)
await page.waitForTimeout(5000)
}
}

if (videoJSON.isChannelMonetized) {
try {
await page.waitForSelector(
"#dialog-buttons #secondary-action-button",
{ visible: true }
);

await page.click("#dialog-buttons #secondary-action-button");
} catch {}
}

// await page.waitForXPath('//*[contains(text(),"Finished processing")]', { timeout: 0})

// no closeBtn will show up if keeps video as draft
Expand Down

0 comments on commit b8fc6e9

Please sign in to comment.