format: rephrasing error messages

This commit is contained in:
LuanRT
2021-10-15 00:09:14 -03:00
parent 1a68875aad
commit 028e723226

View File

@@ -136,24 +136,24 @@ class Innertube extends EventEmitter {
}
async getDetails(id) {
if (!id) return { error: 'Video id missing' };
if (!id) return { error: 'Missing video id' };
const data = await this.requestVideoInfo(id, false);
const video_data = Constants.formatVideoData(data, this, false);
if (video_data.metadata.is_live_content) {
const data_continuation = await Actions.getContinuation(this, { video_id: id });
if (!data_continuation.data.contents.twoColumnWatchNextResults.conversationBar) return;
video_data.getLivechat = () => new Livechat(this, data_continuation.data.contents.twoColumnWatchNextResults.conversationBar.liveChatRenderer.continuations[0].reloadContinuationData.continuation, video_data.metadata.channel_id, id);
}
video_data.like = () => Actions.engage(this, 'like/like', { video_id: id });
video_data.dislike = () => Actions.engage(this, 'like/dislike', { video_id: id });
video_data.removeLike = () => Actions.engage(this, 'like/removelike', { video_id: id });
video_data.subscribe = () => Actions.engage(this, 'subscription/subscribe', { video_id: id, channel_id: video_data.metadata.channel_id });
video_data.unsubscribe = () => Actions.engage(this, 'subscription/unsubscribe', { video_id: id, channel_id: video_data.metadata.channel_id });
video_data.comment = text => Actions.engage(this, 'comment/create_comment', { video_id: id, text });
video_data.setNotificationPref = pref => Actions.notifications(this, 'modify_channel_preference', { channel_id: video_data.metadata.channel_id, pref: pref || 'NONE'});
video_data.setNotificationPref = pref => Actions.notifications(this, 'modify_channel_preference', { channel_id: video_data.metadata.channel_id, pref: pref || 'NONE' });
return video_data;
}
@@ -177,7 +177,7 @@ class Innertube extends EventEmitter {
};
}).filter((notification_block) => notification_block);
}
async getUnseenNotificationsCount() {
const response = await Actions.notifications(this, 'get_unseen_count');
return response.data.unseenCount;
@@ -195,8 +195,8 @@ class Innertube extends EventEmitter {
}
download(id, options = {}) {
if (!id) throw new Error('Video id missing');
if (!id) throw new Error('Missing video id');
options.quality = options.quality || '360p';
options.type = options.type || 'videoandaudio';
options.format = options.format || 'mp4';
@@ -329,6 +329,14 @@ class Innertube extends EventEmitter {
stream.emit('progress', { chunk_size: chunk.length, downloaded_size: (downloaded_size / 1024 / 1024).toFixed(2), percentage, size, raw_data: { chunk_size: chunk.length, downloaded: downloaded_size, size: response.headers['content-length'] } });
});
response.data.on('error', (err) => {
if (cancelled) {
stream.emit('error', { message: 'The download was cancelled.', type: 'DOWNLOAD_CANCELLED' });
} else {
stream.emit('error', { message: err.message, type: 'DOWNLOAD_ABORTED' });
}
});
response.data.on('end', () => {
chunk_start = chunk_end + 1;
chunk_end += chunk_size;
@@ -340,14 +348,6 @@ class Innertube extends EventEmitter {
}
});
response.data.on('error', (err) => {
if (cancelled) {
stream.emit('error', { message: 'The download was cancelled.', type: 'DOWNLOAD_CANCELLED' });
} else {
stream.emit('error', { message: err.message, type: 'DOWNLOAD_ABORTED' });
}
});
response.data.pipe(stream, { end: false });
};
downloadChunk();
@@ -358,6 +358,7 @@ class Innertube extends EventEmitter {
cancelled = true;
cancel();
};
return stream;
}
}