Skip to content

Commit c587604

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

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ oauth2Client.setCredentials({
1111

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

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

39+
const resolvedPrivacyStatus = opts.privacyStatus || getDefaultPrivacyStatus();
40+
console.log(`[youtube-upload] Uploading "${opts.title.slice(0, 60)}" with privacy: ${resolvedPrivacyStatus}`);
3141
// Convert Web ReadableStream to Node.js Readable stream
3242
// googleapis expects a Node.js stream with .pipe(), not a Web ReadableStream
3343
const buffer = Buffer.from(await response.arrayBuffer());
@@ -44,7 +54,7 @@ export async function uploadVideo(opts: UploadOptions): Promise<{ videoId: strin
4454
defaultLanguage: "en",
4555
},
4656
status: {
47-
privacyStatus: opts.privacyStatus || "public",
57+
privacyStatus: resolvedPrivacyStatus,
4858
selfDeclaredMadeForKids: opts.madeForKids ?? false,
4959
},
5060
},

0 commit comments

Comments
 (0)