YouTube.js icon indicating copy to clipboard operation
YouTube.js copied to clipboard

Upload Failed But Return Success

Open 3IMAD69 opened this issue 1 year ago • 0 comments

Steps to reproduce

im using the upload template

import { readFileSync, writeFileSync, existsSync } from 'fs';
import { Innertube, UniversalCache } from 'youtubei.js';
import { DeleteLink } from './db/WaitList';
import { updateStatus } from './server';

const creds_path = './client_secret.json';
const creds = existsSync(creds_path) ? JSON.parse(readFileSync(creds_path).toString()) : undefined;

export async function UploadShorts (filename:string,ShortTitle:string,desc:string | undefined,LinkID:string) {
  const yt = await Innertube.create({ cache: new UniversalCache(false) });
  
  yt.session.on('auth-pending', (data) => {
    console.info(`Hello!\nOn your phone or computer, go to ${data.verification_url} and enter the code ${data.user_code}`);
  });

  yt.session.on('auth', (data) => {
    writeFileSync(creds_path, JSON.stringify(data.credentials));
    console.info('Successfully signed in!');
  });

  yt.session.on('update-credentials', (data) => {
    writeFileSync(creds_path, JSON.stringify(data.credentials));
    console.info('Credentials updated!', data);
  });

  await yt.session.signIn(creds);
  
  const file = readFileSync('./ffmpeg-auto/'+filename+'.mp4');
  
  updateStatus("UPLOADING ...");
  console.log(`UPLOADING ...`);
  try{
    const upload = await yt.studio.upload(file.buffer, {
      title: ShortTitle,
      description: desc || hashtags,
      privacy: 'PUBLIC'
      // privacy: 'PRIVATE'
    });
    
  
    console.info('Done!', upload);
    if(upload.success){
      updateStatus("IDLE");
      console.log('Uploaded Succesfully')
      await DeleteLink(LinkID);
      return true
  
    }else{
      updateStatus("ERROR While Uploading");
      console.log('error while uploading')
      return false
    }
  }catch(error){
      console.log('Error While Uploading , '+error)
      updateStatus("ERROR While Uploading");
      //UploadShorts(filename,ShortTitle,desc,LinkID)
  }
 
  //delete file
}

output =>

UPLOADING ...
Done! {
  success: true,
  status_code: 200,
  data: {
    responseContext: {
      visitorData: 'CgtIb1ptMTJBc3l6ayiv3P2uBjIOCgJTRRIIEgQSAgsMIDE6CiCLxLrQh8bb72U%3D',
      serviceTrackingParams: [Array]
    },
    contents: { uploadFeedbackItemRenderer: [Object] }
  }
}
Uploaded Succesfully
Deleted from db 65df6aafe75bc5e2cbc95931

A good response should look like this with an ID to the uploaded video

UPLOADING ...
Done! {
  success: true,
  status_code: 200,
  data: {
    responseContext: {
      visitorData: 'CgtOcUNISTdHS2hVYyiojfquBjIOCgJTRRIIEgQSAgsMIGQ6CiCGmfazoNWh72U%3D',
      serviceTrackingParams: [Array],
      consistencyTokenJar: [Object]
    },
    videoId: 'CuLEWNkzgmM',
    contents: { uploadFeedbackItemRenderer: [Object] }
  }
}
Uploaded Succesfully
Deleted from db 65de1fbde75bc5e2cbc958c0

Failure Logs

the problem with this bug is that it only happend sometimes so to reproduce it , it will be hard , but im guessing that it could be when the video is too short and the upload is fast

Expected behavior

.

Current behavior

.

Version

Default

Anything else?

.

Checklist

  • [X] I am running the latest version.
  • [X] I checked the documentation and found no answer.
  • [X] I have searched the existing issues and made sure this is not a duplicate.
  • [X] I have provided sufficient information.

3IMAD69 avatar Feb 28 '24 20:02 3IMAD69