Skip to content

Commit

Permalink
fix: check nullable properties (#15)
Browse files Browse the repository at this point in the history
* fix: sometimes `simpleText` is null
* fix: nullable properties
* feat(package): bump version

Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
  • Loading branch information
sawa-ko and Yimura committed Nov 15, 2022
1 parent dc8ac09 commit f186f73
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yimura/scraper",
"version": "1.2.3",
"version": "1.2.4",
"description": "A YouTube scraper using zero dependencies",
"main": "index.js",
"types": "index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const getChannelLink = (cRender) => {
}

const getChannelVideoCount = (cRender) => {
if (!cRender.videoCountText) return 0;
if (!cRender.videoCountText?.runs) return 0;
return +cRender.videoCountText.runs[0].text;
}

Expand Down Expand Up @@ -82,7 +82,7 @@ const getUploadDate = (vRender) => {
}

const getViews = (vRender) => {
if (!vRender.viewCountText) return 0;
if (!vRender.viewCountText?.simpleText) return 0;
return +vRender.viewCountText.simpleText.replace(/[^0-9]/g, '');
}

Expand All @@ -96,7 +96,7 @@ const idToThumbnail = function(id) {
}

const parseDuration = (vRender) => {
if (!vRender.lengthText) return 0;
if (!vRender.lengthText?.simpleText) return 0;

const nums = vRender.lengthText.simpleText.split(':');
let time = nums.reduce((a, t) => (60 * a) + +t) * 1e3;
Expand Down

0 comments on commit f186f73

Please sign in to comment.