Only show console.log if debug is set to true
KirianCaumes opened this issue · 3 comments
Hello,
As I'd rather handle console.log
myself, what do you think about hiding them in the index.js
if debug
is not set to true
:
//...
async fetch() {
this.session.debugOn = this.debug;
await this.session.fetch();
if (this.session.status === 'OK') {
this.video = new Video(this.session, this.options);
this.video.debugOn = this.debug;
await this.video.fetch();
if (this.video.status === 'OK') {
if (this.debug)
console.log(ut.jsp(this.video.info(exclusions)));
await this.video.download();
if (this.video.downloaded) {
if (this.debug) {
console.log('\n\nDone!');
console.log(`Downloaded: ${this.video.fn}`);
}
} else {
throw new Error(`Video status: ${this.video.status} (${this.video.reason})`);
}
} else {
throw new Error(`Video status: ${this.video.status} (${this.video.reason})`);
}
} else {
throw new Error(`Session status: ${this.session.status} (${this.session.reason})`);
}
}
//...
As you can see, I've also put some throw new Error('...')
, which allow my script to do the error handling.
Thank you, awesome lib!
Thanks for the support. What I would suggest you do in your code instead of editing index.js is create your own main.js, extend the Download class and overwrite the fetch() method. Something like this.
const ytcog = require('ytcog');
class MyDL extends ytcog.Download {
async fetch() {
this.session.debugOn = this.debug;
await this.session.fetch();
if (this.session.status === 'OK') {
this.video = new ytcog.Video(this.session, this.options);
this.video.debugOn = this.debug;
await this.video.fetch();
if (this.video.status === 'OK') {
this.video.debug(this.video.info());
await this.video.download();
if (this.video.downloaded) {
this.video.debug('\n\nDone!');
this.video.debug(`Downloaded: ${this.video.fn}`);
} else {
throw new Error(`Video status: ${this.video.status} (${this.video.reason})`);
}
} else {
throw new Error(`Video status: ${this.video.status} (${this.video.reason})`);
}
} else {
throw new Error(`Session status: ${this.session.status} (${this.session.reason})`);
}
}
}
let download = new MyDL(options, cookie, userAgent, proxy, debug);
await download.fetch();
That's perfect for me that way, thank you!
I found something else : some video that I downloaded have don't have sound. Can we discuss that here, or would you prefer that I open a new issue?
You can close this and open an new issue. If you can give me an example that I can replicate then I can fix asap.