mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 08:26:59 +03:00
made youtube api cache have conatcnt part value
This commit is contained in:
@@ -50,7 +50,7 @@ function sendWebhooks(userID, videoID, UUID, segmentInfo) {
|
|||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let userSubmissionCountRow = db.prepare('get', "SELECT count(*) as submissionCount FROM sponsorTimes WHERE userID = ?", [userID]);
|
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) {
|
if (err || data.items.length === 0) {
|
||||||
err && logger.error(err);
|
err && logger.error(err);
|
||||||
return;
|
return;
|
||||||
@@ -154,7 +154,7 @@ async function autoModerateSubmission(submission) {
|
|||||||
// Get the video information from the youtube API
|
// Get the video information from the youtube API
|
||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let {err, data} = await new Promise((resolve, reject) => {
|
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) {
|
if (err) {
|
||||||
@@ -398,7 +398,7 @@ module.exports = async function postSkipSegments(req, res) {
|
|||||||
|
|
||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
let {err, data} = await new Promise((resolve, reject) => {
|
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
|
//get all segments for this video and user
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ function sendWebhooks(voteData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.youtubeAPIKey !== null) {
|
if (config.youtubeAPIKey !== null) {
|
||||||
YouTubeAPI.listVideos(submissionInfoRow.videoID, "snippet", (err, data) => {
|
YouTubeAPI.listVideos(submissionInfoRow.videoID, (err, data) => {
|
||||||
if (err || data.items.length === 0) {
|
if (err || data.items.length === 0) {
|
||||||
err && logger.error(err);
|
err && logger.error(err);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -18,13 +18,14 @@ if (config.mode === "test") {
|
|||||||
exportObject = YouTubeAPI;
|
exportObject = YouTubeAPI;
|
||||||
|
|
||||||
// YouTubeAPI.videos.list wrapper with cacheing
|
// 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(".")) {
|
if (videoID.length !== 11 || videoID.includes(".")) {
|
||||||
callback("Invalid video ID");
|
callback("Invalid video ID");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let redisKey = "youtube.video." + videoID + "." + part;
|
let redisKey = "youtube.video." + videoID;
|
||||||
redis.get(redisKey, (getErr, result) => {
|
redis.get(redisKey, (getErr, result) => {
|
||||||
if (getErr || !result) {
|
if (getErr || !result) {
|
||||||
logger.debug("redis: no cache for video information: " + videoID);
|
logger.debug("redis: no cache for video information: " + videoID);
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ YouTubeAPI.videos.list({
|
|||||||
// https://developers.google.com/youtube/v3/docs/videos
|
// https://developers.google.com/youtube/v3/docs/videos
|
||||||
|
|
||||||
const YouTubeAPI = {
|
const YouTubeAPI = {
|
||||||
listVideos: (id, part, callback) => {
|
listVideos: (id, callback) => {
|
||||||
YouTubeAPI.videos.list({
|
YouTubeAPI.videos.list({
|
||||||
part: part,
|
|
||||||
id: id
|
id: id
|
||||||
}, callback);
|
}, callback);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user