@@ -11,6 +11,14 @@ oauth2Client.setCredentials({
1111
1212const 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+
1422interface 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