mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +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_KEY`: YouTube API Key
|
||||
- `YOUTUBE_KEY`: YouTube API Key, support multiple keys, split them with `,`
|
||||
|
||||
- telegram: [Bot application](https://telegram.org/blog/bot-revolution)
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ RSSHub 支持 `memory` 和 `redis` 两种缓存方式
|
||||
|
||||
- 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)
|
||||
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
const { google } = require('googleapis');
|
||||
const config = require('@/config').value;
|
||||
|
||||
const youtube = google.youtube({
|
||||
let getYoutube = () => null;
|
||||
if (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: config.youtube.key,
|
||||
});
|
||||
auth: key,
|
||||
});
|
||||
count = index + 1;
|
||||
}
|
||||
});
|
||||
|
||||
getYoutube = () => {
|
||||
index++;
|
||||
return youtube[index % count];
|
||||
};
|
||||
}
|
||||
|
||||
const youtubeUtils = {
|
||||
getPlaylistItems: async (id, part) => {
|
||||
const res = await youtube.playlistItems.list({
|
||||
const res = await getYoutube().playlistItems.list({
|
||||
part,
|
||||
playlistId: id,
|
||||
});
|
||||
@@ -16,7 +34,7 @@ const youtubeUtils = {
|
||||
},
|
||||
getPlaylist: async (id, part, cache) =>
|
||||
await cache.tryGet('getPlaylist' + id, async () => {
|
||||
const res = await youtube.playlists.list({
|
||||
const res = await getYoutube().playlists.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
@@ -24,7 +42,7 @@ const youtubeUtils = {
|
||||
}),
|
||||
getChannelWithId: async (id, part, cache) =>
|
||||
await cache.tryGet('getChannelWithId' + id, async () => {
|
||||
const res = await youtube.channels.list({
|
||||
const res = await getYoutube().channels.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
@@ -32,7 +50,7 @@ const youtubeUtils = {
|
||||
}),
|
||||
getChannelWithUsername: async (username, part, cache) =>
|
||||
await cache.tryGet('getPlaylist' + username, async () => {
|
||||
const res = await youtube.channels.list({
|
||||
const res = await getYoutube().channels.list({
|
||||
part,
|
||||
forUsername: username,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user