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

extract lengthSeconds for YouTube Shorts #75

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class YoutubeGrabberHelper {
}

parseVideo(obj, channelInfo) {
const shortsRegex = /(months?|years?|days?|hours?|weeks?) ago (\d*) (second|minute)/
let video
let liveNow = false
let premiere = false
Expand Down Expand Up @@ -236,6 +237,14 @@ class YoutubeGrabberHelper {
const seconds = parseInt(durationSplit[1])

lengthSeconds = (minutes * 60) + seconds
} else if (durationSplit[0] === 'SHORTS') { // durationText will still be 'SHORTS' for shorts
const regexMatch = video.title.accessibility.accessibilityData.label.match(shortsRegex)
lengthSeconds = parseInt(regexMatch[2])
durationText = '0:' + (lengthSeconds.toString().padStart(2,'0'))
if (regexMatch[3] == 'minute') {
lengthSeconds *= 60
durationText = '1:00'
}
}
} else {
lengthSeconds = 0
Expand Down
7 changes: 7 additions & 0 deletions test/channelVideos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('Getting channel videos', () => {
})
})

test('Shorts Channel', () => {
const parameters = { channelId: 'UC4-79UOlP48-QNGgCko5p2g', channelIdType: 1 }
return ytch.getChannelVideos(parameters).then((data) => {
expect(data.items[0].lengthSeconds).not.toBe(0)
})
})

test('Public channel w/o videos', () => {
const parameters = { channelId: 'UCS-DgEvT4XuQsrrmI7iZVsA', channelIdType: 1 }
return ytch.getChannelVideos(parameters).then((data) => {
Expand Down