made youtube api cache have conatcnt part value

This commit is contained in:
Joe Dowd
2020-10-14 20:52:01 +01:00
parent bcf90e8094
commit 830ef7e0dc
4 changed files with 8 additions and 8 deletions

View File

@@ -50,7 +50,7 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) {
if (config.youtubeAPIKey !== null) {
let userSubmissionCountRow = db.prepare('get', "SELECT count(*) as submissionCount FROM sponsorTimes WHERE userID = ?", [userID]);
YouTubeAPI.listVideos(videoID, "snippet", (err, data) => {
YouTubeAPI.listVideos(videoID, (err, data) => {
if (err || data.items.length === 0) {
err && logger.error(err);
return;
@@ -154,7 +154,7 @@ async function autoModerateSubmission(submission) {
// Get the video information from the youtube API
if (config.youtubeAPIKey !== null) {
let {err, data} = await new Promise((resolve, reject) => {
YouTubeAPI.listVideos(submission.videoID, "contentDetails,snippet", (err, data) => resolve({err, data}));
YouTubeAPI.listVideos(submission.videoID, (err, data) => resolve({err, data}));
});
if (err) {
@@ -398,7 +398,7 @@ module.exports = async function postSkipSegments(req, res) {
if (config.youtubeAPIKey !== null) {
let {err, data} = await new Promise((resolve, reject) => {
YouTubeAPI.listVideos(videoID, "contentDetails,snippet", (err, data) => resolve({err, data}));
YouTubeAPI.listVideos(videoID, (err, data) => resolve({err, data}));
});
//get all segments for this video and user

View File

@@ -49,7 +49,7 @@ function sendWebhooks(voteData) {
}
if (config.youtubeAPIKey !== null) {
YouTubeAPI.listVideos(submissionInfoRow.videoID, "snippet", (err, data) => {
YouTubeAPI.listVideos(submissionInfoRow.videoID, (err, data) => {
if (err || data.items.length === 0) {
err && logger.error(err);
return;

View File

@@ -18,13 +18,14 @@ if (config.mode === "test") {
exportObject = YouTubeAPI;
// YouTubeAPI.videos.list wrapper with cacheing
exportObject.listVideos = (videoID, part, callback) => {
exportObject.listVideos = (videoID, callback) => {
let part = 'contentDetails,snippet';
if (videoID.length !== 11 || videoID.includes(".")) {
callback("Invalid video ID");
return;
}
let redisKey = "youtube.video." + videoID + "." + part;
let redisKey = "youtube.video." + videoID;
redis.get(redisKey, (getErr, result) => {
if (getErr || !result) {
logger.debug("redis: no cache for video information: " + videoID);

View File

@@ -8,9 +8,8 @@ YouTubeAPI.videos.list({
// https://developers.google.com/youtube/v3/docs/videos
const YouTubeAPI = {
listVideos: (id, part, callback) => {
listVideos: (id, callback) => {
YouTubeAPI.videos.list({
part: part,
id: id
}, callback);
},