Skip to content

Commit f186f73

Browse files
sawa-koYimura
andauthored
fix: check nullable properties (#15)
* fix: sometimes `simpleText` is null * fix: nullable properties * feat(package): bump version Co-authored-by: Yimura <[email protected]>
1 parent dc8ac09 commit f186f73

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yimura/scraper",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "A YouTube scraper using zero dependencies",
55
"main": "index.js",
66
"types": "index.d.ts",

Diff for: src/Util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const getChannelLink = (cRender) => {
3434
}
3535

3636
const getChannelVideoCount = (cRender) => {
37-
if (!cRender.videoCountText) return 0;
37+
if (!cRender.videoCountText?.runs) return 0;
3838
return +cRender.videoCountText.runs[0].text;
3939
}
4040

@@ -82,7 +82,7 @@ const getUploadDate = (vRender) => {
8282
}
8383

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

@@ -96,7 +96,7 @@ const idToThumbnail = function(id) {
9696
}
9797

9898
const parseDuration = (vRender) => {
99-
if (!vRender.lengthText) return 0;
99+
if (!vRender.lengthText?.simpleText) return 0;
100100

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

0 commit comments

Comments
 (0)