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

Handling wrong file path #146

Closed
pierreminiggio opened this issue Aug 1, 2022 · 7 comments · Fixed by #155
Closed

Handling wrong file path #146

pierreminiggio opened this issue Aug 1, 2022 · 7 comments · Fixed by #155
Labels
enhancement New feature or request

Comments

@pierreminiggio
Copy link
Contributor

pierreminiggio commented Aug 1, 2022

If we happen to send a wrong file path, the program is stuck on this page :
image
We could probably check for file existence before launching the launch, or look for the file unreadable error.
Or maybe even both ? I'd guess the unreadable file error might get thrown as well if the video is corrupted ?

@github-actions
Copy link

github-actions bot commented Aug 1, 2022

Paid support is available for quick resolution, new features etc. For paid support, please write mail to youtube-uploader@datascraping.pp.ua

@fawazahmed0 fawazahmed0 added the enhancement New feature or request label Aug 1, 2022
@picola07
Copy link

picola07 commented Aug 8, 2022

i got the same error did anyone figured it out yet ?

@pierreminiggio
Copy link
Contributor Author

pierreminiggio commented Aug 10, 2022

i got the same error did anyone figured it out yet ?

If you have the same error, that means that you sent a wrong file path, a format Youtube can't handle, or a corrupted file.
The purpose of my issue is simply to throw an error to the person using the package so that the program simply doesn't freeze on that page if you happen to send a bad file.
TL;DR : Check the file path you passed to the program and your file, that's on your end if you get that error.

@picola07
Copy link

I'am sure I used a right path I copied it by using shit and right click then I just paste it, I changed the file so many times and when I uploaded em manually and everything goes well I even changed format from mp4 to mkv and still have the same problem

@pierreminiggio
Copy link
Contributor Author

pierreminiggio commented Aug 11, 2022

Sorry to be repeating myself, but please check again that you're actually passing a local file path to a correct file, supported by NodeJS, it's very very likely that it's on your end.
There is a really small chance that Youtube could be having an issue, but on a feature as important as the file upload, I don't believe it would go without fix for more than a few hours. So very unlikely.

As you can see here, there is no process done in that library when it comes to the file path, it's straight up fed into the input file that Youtube reads the file from.

async function uploadVideo(videoJSON: Video, messageTransport: MessageTransport) {
const pathToFile = videoJSON.path
if (!pathToFile) {
throw new Error("function `upload`'s second param `videos`'s item `video` must include `path` property.")
}
for (let i in invalidCharacters)
if (videoJSON.title.includes(invalidCharacters[i]))
throw new Error(`"${videoJSON.title}" includes a character not allowed in youtube titles (${invalidCharacters[i]})`)
if (videoJSON.channelName) {
await changeChannel(videoJSON.channelName);
}
const title = videoJSON.title
const description = videoJSON.description
const tags = videoJSON.tags
// For backward compatablility playlist.name is checked first
const playlistName = videoJSON.playlist
const videoLang = videoJSON.language
const thumb = videoJSON.thumbnail
const uploadAsDraft = videoJSON.uploadAsDraft
await page.evaluate(() => {
window.onbeforeunload = null
})
await page.goto(uploadURL)
const closeBtnXPath = "//*[normalize-space(text())='Close']"
const selectBtnXPath = "//*[normalize-space(text())='Select files']"
const saveCloseBtnXPath = '//*[@aria-label="Save and close"]/tp-yt-iron-icon'
const createBtnXPath = '//*[@id="create-icon"]/tp-yt-iron-icon'
const addVideoBtnXPath = '//*[@id="text-item-0"]/ytcp-ve/div/div/yt-formatted-string'
if((await page.waitForXPath(createBtnXPath).catch(() => null))){
const createBtn = await page.$x(createBtnXPath);
await createBtn[0].click();
}
if((await page.waitForXPath(addVideoBtnXPath).catch(() => null))){
const addVideoBtn =await page.$x(addVideoBtnXPath);
await addVideoBtn[0].click();
}
for (let i = 0; i < 2; i++) {
try {
await page.waitForXPath(selectBtnXPath)
await page.waitForXPath(closeBtnXPath)
break
} catch (error) {
const nextText = i === 0 ? ' trying again' : ' failed again'
messageTransport.log('Failed to find the select files button' + nextText)
messageTransport.log(error)
await page.evaluate(() => {
window.onbeforeunload = null
})
await page.goto(uploadURL)
}
}
// Remove hidden closebtn text
const closeBtn = await page.$x(closeBtnXPath)
await page.evaluate((el) => {
el.textContent = 'oldclosse'
}, closeBtn[0])
const selectBtn = await page.$x(selectBtnXPath)
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
selectBtn[0].click() // button that triggers file selection
])
await fileChooser.accept([pathToFile])

@pierreminiggio
Copy link
Contributor Author

... or look for the file unreadable error.

Here is an MR to close the program and throw an error if Youtube shows us an error.
This will cover the "You file could not be found or read" error in my issue, but it might also cover some other errors Youtube could show us that I'm not aware of : #155

@pierreminiggio
Copy link
Contributor Author

pierreminiggio commented Sep 8, 2022

I'am sure I used a right path I copied it by using shit and right click then I just paste it, I changed the file so many times and when I uploaded em manually and everything goes well I even changed format from mp4 to mkv and still have the same problem

IDK if you found what you did wrong with your file path.
But I noticed something : While using an asbolute path that has a few "../", it failed.
So make sure to pass your file pathes into formatting functions to remove all the "../".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants