Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Check if video duration exists and return 0 if it doesn't
Browse files Browse the repository at this point in the history
  • Loading branch information
PrestonN committed Sep 26, 2020
1 parent 85a7f38 commit ec86892
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,12 @@ class YoutubeGrabberHelper {
if (typeof (title) === 'undefined') {
title = video.title.runs[0].text
}

if (typeof (video.shortViewCountText) !== 'undefined' && typeof (video.shortViewCountText.simpleText) === 'undefined') {
liveNow = true
publishedText = 'Live'
viewCount = parseInt(video.shortViewCountText.runs[0].text)
viewCountText = video.shortViewCountText.runs[0].text + video.shortViewCountText.runs[1].text
} else if (video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer.text.simpleText === 'PREMIERE') {
} else if (typeof (video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer) !== 'undefined' && video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer.text.simpleText === 'PREMIERE') {
premiere = true
durationText = 'PREMIERE'
viewCount = 0
Expand All @@ -101,20 +100,24 @@ class YoutubeGrabberHelper {

publishedText = video.publishedTimeText.simpleText

durationText = video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer.text.simpleText
const durationSplit = durationText.split(':')
if (typeof (video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer) !== 'undefined') {
durationText = video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer.text.simpleText
const durationSplit = durationText.split(':')

if (durationSplit.length === 3) {
const hours = parseInt(durationSplit[0])
const minutes = parseInt(durationSplit[1])
const seconds = parseInt(durationSplit[2])
if (durationSplit.length === 3) {
const hours = parseInt(durationSplit[0])
const minutes = parseInt(durationSplit[1])
const seconds = parseInt(durationSplit[2])

lengthSeconds = (hours * 3600) + (minutes * 60) + seconds
} else if (durationSplit.length === 2) {
const minutes = parseInt(durationSplit[0])
const seconds = parseInt(durationSplit[1])
lengthSeconds = (hours * 3600) + (minutes * 60) + seconds
} else if (durationSplit.length === 2) {
const minutes = parseInt(durationSplit[0])
const seconds = parseInt(durationSplit[1])

lengthSeconds = (minutes * 60) + seconds
lengthSeconds = (minutes * 60) + seconds
}
} else {
lengthSeconds = 0
}
}

Expand Down

0 comments on commit ec86892

Please sign in to comment.