Skip to content

Commit 683352e

Browse files
codercatdevMiriadvideopipe
authored
feat: add YOUTUBE_UPLOAD_VISIBILITY env var, default to private (#596)
Co-authored-by: Miriad <miriad@miriad.systems> Co-authored-by: videopipe <videopipe@miriad.systems>
1 parent d122920 commit 683352e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CRON_SECRET= # Secret for authenticating cron job re
5656
# YouTube integration
5757
YOUTUBE_API_KEY= # YouTube Data API v3 key
5858
YOUTUBE_CHANNEL_ID= # YouTube channel ID to fetch videos from
59+
YOUTUBE_UPLOAD_VISIBILITY= # YouTube upload privacy: "public", "private", or "unlisted" (default: "private")
5960

6061
# Vercel
6162
VERCEL_PROJECT_PRODUCTION_URL= # Production URL (auto-set by Vercel)

lib/youtube-upload.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ oauth2Client.setCredentials({
1010

1111
const youtube = google.youtube({ version: "v3", auth: oauth2Client });
1212

13+
function getDefaultPrivacyStatus(): "public" | "private" | "unlisted" {
14+
const envValue = process.env.YOUTUBE_UPLOAD_VISIBILITY?.toLowerCase();
15+
if (envValue === "public" || envValue === "private" || envValue === "unlisted") {
16+
return envValue;
17+
}
18+
return "private"; // Default to private when not set
19+
}
20+
1321
interface UploadOptions {
1422
title: string;
1523
description: string;
@@ -27,6 +35,9 @@ export async function uploadVideo(opts: UploadOptions): Promise<{ videoId: strin
2735
const response = await fetch(opts.videoUrl);
2836
if (!response.ok) throw new Error(`Failed to fetch video: ${response.statusText}`);
2937

38+
const resolvedPrivacyStatus = opts.privacyStatus || getDefaultPrivacyStatus();
39+
console.log(`[youtube-upload] Uploading "${opts.title.slice(0, 60)}" with privacy: ${resolvedPrivacyStatus}`);
40+
3041
const res = await youtube.videos.insert({
3142
part: ["snippet", "status"],
3243
requestBody: {
@@ -38,7 +49,7 @@ export async function uploadVideo(opts: UploadOptions): Promise<{ videoId: strin
3849
defaultLanguage: "en",
3950
},
4051
status: {
41-
privacyStatus: opts.privacyStatus || "public",
52+
privacyStatus: resolvedPrivacyStatus,
4253
selfDeclaredMadeForKids: opts.madeForKids ?? false,
4354
},
4455
},

0 commit comments

Comments
 (0)