|
|
|
@ -44,19 +44,40 @@ class YouTube extends SongProvider {
@@ -44,19 +44,40 @@ class YouTube extends SongProvider {
|
|
|
|
|
var ytPlayerResponse = JSON.parse(match[1]); |
|
|
|
|
} catch(e) { |
|
|
|
|
cb('Could not parse JSON YouTube data for'+url); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if(ytPlayerResponse && ytPlayerResponse.videoDetails) { |
|
|
|
|
|
|
|
|
|
if(!ytPlayerResponse) { |
|
|
|
|
cb('Unrecognized YouTube data for '+url); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let width = null, height = null; |
|
|
|
|
if(ytPlayerResponse.streamingData && ytPlayerResponse.streamingData.formats) { |
|
|
|
|
for(let format of ytPlayerResponse.streamingData.formats) { |
|
|
|
|
if(format.width > width || width === null) { |
|
|
|
|
width = format.width; |
|
|
|
|
height = format.height; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ytPlayerResponse.videoDetails) { |
|
|
|
|
var ret = { |
|
|
|
|
platform: 'youtube', |
|
|
|
|
url: url, |
|
|
|
|
title: ytPlayerResponse.videoDetails.title, |
|
|
|
|
thumbnail: ytPlayerResponse.videoDetails.thumbnail && ytPlayerResponse.videoDetails.thumbnail.thumbnails && ytPlayerResponse.videoDetails.thumbnail.thumbnails[0].url || null, |
|
|
|
|
duration: ytPlayerResponse.videoDetails.lengthSeconds, |
|
|
|
|
duration: parseInt(ytPlayerResponse.videoDetails.lengthSeconds), |
|
|
|
|
author: ytPlayerResponse.videoDetails.author, |
|
|
|
|
author_url: 'https://www.youtube.com/channel/'+ytPlayerResponse.videoDetails.channelId, |
|
|
|
|
description: ytPlayerResponse.videoDetails.shortDescription, |
|
|
|
|
width: width, |
|
|
|
|
height: height, |
|
|
|
|
views: parseInt(ytPlayerResponse.videoDetails.viewCount), |
|
|
|
|
}; |
|
|
|
|
cb(null, ret); |
|
|
|
|
} else cb('Unrecognized YouTube data for '+url); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
cb('Could not parse YouTube data for '+url); |
|
|
|
|
} |
|
|
|
|