@@ -73,7 +73,7 @@ ipcMain.handle('create-folder', async (event, arg) => {
7373} ) ;
7474
7575ipcMain . handle ( 'open-folder' , async ( event , arg ) => {
76- shell . openPath ( process . cwd ( ) + path . sep + 'downloadedVODs' + path . sep + arg ) ;
76+ shell . openPath ( process . cwd ( ) + path . sep + 'downloadedVODs' + path . sep + arg . replace ( ":" , "#" ) ) ;
7777} ) ;
7878
7979ipcMain . handle ( 'retrieve-video-information' , async ( event , arg ) => {
@@ -118,37 +118,68 @@ ipcMain.handle('open-google-login', async (event, arg) => {
118118 return myApiOauth . openAuthWindowAndGetTokens ( ) ;
119119} ) ;
120120
121+ ipcMain . handle ( 'create-thumbnail-folder' , async ( event , arg ) => {
122+ fs . mkdir ( './downloadedVODs/' + arg . replace ( ":" , "#" ) + "/thumbnails" , { recursive : true } , ( err : Error ) => {
123+ if ( err ) throw err ;
124+ } )
125+ } )
126+
127+ ipcMain . handle ( 'save-thumbnail' , async ( event , args ) => {
128+ console . log ( "Saving thumbnail: " , args )
129+ // fs.mkdir('./downloadedVODs/' + args.folderName.replace(":", "#") + "/thumbnails", { recursive: true }, (err: Error) => {
130+ // if (err) throw err;
131+ // })
132+ fs . writeFile ( "./downloadedVODs/" + args . folderName . replace ( ":" , "#" ) + "/thumbnails/" + args . fileName . replace ( ":" , "#" ) + ".jpg" , args . buf , function ( err : any ) {
133+ if ( err ) {
134+ console . log ( err ) ;
135+ }
136+ } )
137+ } )
138+
121139ipcMain . handle ( 'upload-videos' , async ( event , args ) => {
122- const fileSize = fs . statSync ( args . path ) . size ;
123- return youtube . videos . insert (
124- {
125- part : 'id,snippet,status' ,
126- notifySubscribers : false ,
127- requestBody : {
128- snippet : {
129- title : args . videoName . replace ( / \. [ ^ / . ] + $ / , '' ) ,
130- description : args . description ,
131- } ,
132- status : {
133- privacyStatus : 'unlisted' ,
134- } ,
135- } ,
136- media : {
137- body : fs . createReadStream ( args . path ) ,
138- } ,
139- access_token : args . accessToken ,
140- } ,
141- {
142- // Use the `onUploadProgress` event from Axios to track the
143- // number of bytes uploaded to this point.
144- onUploadProgress : ( evt : any ) => {
145- const progress = ( evt . bytesRead / fileSize ) * 100 ;
146- readline . clearLine ( process . stdout , 0 ) ;
147- readline . cursorTo ( process . stdout , 0 , null ) ;
148- process . stdout . write ( `${ Math . round ( progress ) } % complete` ) ;
149- } ,
140+ return fs . readdirSync ( args . path ) . forEach ( ( videoName : any ) => {
141+ const fileSize = fs . statSync ( args . path + videoName ) . size ;
142+ if ( path . extname ( videoName ) . toLowerCase ( ) === '.mp4' ) {
143+ console . log ( 'videoName' , videoName ) ;
144+ return youtube . videos
145+ . insert (
146+ {
147+ part : 'id,snippet,status' ,
148+ notifySubscribers : true ,
149+ requestBody : {
150+ snippet : {
151+ title : videoName . replace ( / \. [ ^ / . ] + $ / , '' ) ,
152+ description : args . description ,
153+ } ,
154+ status : {
155+ privacyStatus : args . visibility ,
156+ } ,
157+ } ,
158+ media : {
159+ body : fs . createReadStream ( args . path + videoName ) ,
160+ } ,
161+ access_token : args . accessToken ,
162+ } ,
163+ {
164+ // Use the `onUploadProgress` event from Axios to track the
165+ // number of bytes uploaded to this point.
166+ onUploadProgress : ( evt : any ) => {
167+ const progress = ( evt . bytesRead / fileSize ) * 100 ;
168+ readline . clearLine ( process . stdout , 0 ) ;
169+ readline . cursorTo ( process . stdout , 0 , null ) ;
170+ process . stdout . write ( `${ Math . round ( progress ) } % complete` ) ;
171+ } ,
172+ }
173+ )
174+ . then ( ( response : any ) => {
175+ console . log ( 'response' , response ) ;
176+ } )
177+ . catch ( ( error : any ) => {
178+ console . log ( 'error' , error ) ;
179+ return error . errors [ 0 ] . message ;
180+ } ) ;
150181 }
151- )
182+ } )
152183} ) ;
153184
154185ipcMain . handle ( 'get-api-key' , async ( event , arg ) => {
0 commit comments