mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 20:27:52 +08:00
feat: support multiple youtube keys
This commit is contained in:
@@ -369,7 +369,7 @@ Access control includes a whitelist and a blacklist, support IP and route, use `
|
|||||||
|
|
||||||
- youtube: [API Key application](https://console.developers.google.com/)
|
- youtube: [API Key application](https://console.developers.google.com/)
|
||||||
|
|
||||||
- `YOUTUBE_KEY`: YouTube API Key
|
- `YOUTUBE_KEY`: YouTube API Key, support multiple keys, split them with `,`
|
||||||
|
|
||||||
- telegram: [Bot application](https://telegram.org/blog/bot-revolution)
|
- telegram: [Bot application](https://telegram.org/blog/bot-revolution)
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
|
|||||||
|
|
||||||
- youtube 全部路由: [申请地址](https://console.developers.google.com/)
|
- youtube 全部路由: [申请地址](https://console.developers.google.com/)
|
||||||
|
|
||||||
- `YOUTUBE_KEY`: YouTube API Key
|
- `YOUTUBE_KEY`: YouTube API Key,支持多个 key,用英文逗号 `,` 隔开
|
||||||
|
|
||||||
- telegram - 贴纸包路由: [Telegram 机器人](https://telegram.org/blog/bot-revolution)
|
- telegram - 贴纸包路由: [Telegram 机器人](https://telegram.org/blog/bot-revolution)
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,32 @@
|
|||||||
const { google } = require('googleapis');
|
const { google } = require('googleapis');
|
||||||
const config = require('@/config').value;
|
const config = require('@/config').value;
|
||||||
|
|
||||||
const youtube = google.youtube({
|
let getYoutube = () => null;
|
||||||
version: 'v3',
|
if (config.youtube.key) {
|
||||||
auth: config.youtube.key,
|
const keys = config.youtube.key.split(',');
|
||||||
});
|
const youtube = {};
|
||||||
|
let count = 0;
|
||||||
|
let index = -1;
|
||||||
|
|
||||||
|
keys.forEach((key, index) => {
|
||||||
|
if (key) {
|
||||||
|
youtube[index] = google.youtube({
|
||||||
|
version: 'v3',
|
||||||
|
auth: key,
|
||||||
|
});
|
||||||
|
count = index + 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getYoutube = () => {
|
||||||
|
index++;
|
||||||
|
return youtube[index % count];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const youtubeUtils = {
|
const youtubeUtils = {
|
||||||
getPlaylistItems: async (id, part) => {
|
getPlaylistItems: async (id, part) => {
|
||||||
const res = await youtube.playlistItems.list({
|
const res = await getYoutube().playlistItems.list({
|
||||||
part,
|
part,
|
||||||
playlistId: id,
|
playlistId: id,
|
||||||
});
|
});
|
||||||
@@ -16,7 +34,7 @@ const youtubeUtils = {
|
|||||||
},
|
},
|
||||||
getPlaylist: async (id, part, cache) =>
|
getPlaylist: async (id, part, cache) =>
|
||||||
await cache.tryGet('getPlaylist' + id, async () => {
|
await cache.tryGet('getPlaylist' + id, async () => {
|
||||||
const res = await youtube.playlists.list({
|
const res = await getYoutube().playlists.list({
|
||||||
part,
|
part,
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
@@ -24,7 +42,7 @@ const youtubeUtils = {
|
|||||||
}),
|
}),
|
||||||
getChannelWithId: async (id, part, cache) =>
|
getChannelWithId: async (id, part, cache) =>
|
||||||
await cache.tryGet('getChannelWithId' + id, async () => {
|
await cache.tryGet('getChannelWithId' + id, async () => {
|
||||||
const res = await youtube.channels.list({
|
const res = await getYoutube().channels.list({
|
||||||
part,
|
part,
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
@@ -32,7 +50,7 @@ const youtubeUtils = {
|
|||||||
}),
|
}),
|
||||||
getChannelWithUsername: async (username, part, cache) =>
|
getChannelWithUsername: async (username, part, cache) =>
|
||||||
await cache.tryGet('getPlaylist' + username, async () => {
|
await cache.tryGet('getPlaylist' + username, async () => {
|
||||||
const res = await youtube.channels.list({
|
const res = await getYoutube().channels.list({
|
||||||
part,
|
part,
|
||||||
forUsername: username,
|
forUsername: username,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user