diff --git a/app/helper.js b/app/helper.js index 4a60d91..271def5 100644 --- a/app/helper.js +++ b/app/helper.js @@ -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 @@ -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 diff --git a/test/channelVideos.test.js b/test/channelVideos.test.js index ff9f01d..bddabdc 100644 --- a/test/channelVideos.test.js +++ b/test/channelVideos.test.js @@ -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) => {