@@ -7,12 +7,13 @@ const os = require('os');
77const https = require ( 'https' ) ; // Add this import
88const { v4 : uuidv4 } = require ( 'uuid' ) ;
99const { Decoder } = require ( 'ts-ebml' ) ;
10+ const { shell } = require ( 'electron' ) ;
1011
12+ let savePath = path . join ( os . homedir ( ) , 'Downloads' ) ;
1113
1214const expressApp = express ( ) ;
1315let serverPort , ytWin ;
1416let youtubeCookies = "" ;
15-
1617const baseDir = path . join ( os . homedir ( ) , 'Library/Application Support/videosnatcher' ) ;
1718const logsDir = path . join ( baseDir , 'logs' ) ;
1819const liveLogPath = path . join ( logsDir , 'live.log' ) ;
@@ -347,6 +348,13 @@ app.whenReady().then(() => {
347348 path . join ( executablesDir , 'yt-dlp-mac' ) ,
348349 'https://jemcats.software/github_pages/VideoSnatcher/files/yt-dlp-mac'
349350 ) ;
351+ exec ( '/usr/sbin/softwareupdate --install-rosetta --agree-to-license' , ( error , stdout , stderr ) => {
352+ if ( error ) {
353+ console . error ( `Error installing Rosetta: ${ error . message } ` ) ;
354+ } else {
355+ console . log ( 'Rosetta installed successfully.' ) ;
356+ }
357+ } ) ;
350358 ensureFile (
351359 path . join ( executablesDir , 'ffmpeg-mac' ) ,
352360 'https://jemcats.software/github_pages/VideoSnatcher/files/ffmpeg-mac'
@@ -359,42 +367,17 @@ expressApp.get('/get_vid', (req, res) => {
359367
360368 if ( ! videoPath ) return res . status ( 400 ) . send ( 'Missing "path" parameter' ) ;
361369
362- const stream = fs . createReadStream ( videoPath ) ;
363- stream . on ( 'error' , ( err ) => {
364- console . error ( err ) ;
365- res . status ( 500 ) . send ( 'Error reading video file' ) ;
366- } ) ;
367- const ext = path . extname ( videoPath ) . toLowerCase ( ) ;
368- if ( ext === '.mp4' ) {
369- const stat = fs . statSync ( videoPath ) ;
370- const ebmlDecoder = new Decoder ( ) ;
371- const fileBuffer = fs . readFileSync ( videoPath ) ;
372- const elements = ebmlDecoder . decode ( fileBuffer ) ;
373- const isAudioOnly = elements . some ( element => element . name === 'TrackType' && element . value === 2 ) ; // Check if the file contains audio-only tracks
374- if ( isAudioOnly ) {
375- res . setHeader ( 'Content-Type' , 'audio/mp4' ) ;
376- } else {
377- res . setHeader ( 'Content-Type' , 'video/mp4' ) ;
378- }
379- } else if ( ext === '.webm' ) {
380- const stat = fs . statSync ( videoPath ) ;
381- const ebmlDecoder = new Decoder ( ) ;
382- const fileBuffer = fs . readFileSync ( videoPath ) ;
383- const elements = ebmlDecoder . decode ( fileBuffer ) ;
384- const isAudioOnly = elements . some ( element => element . name === 'TrackType' && element . value === 2 ) ; // Check if the file contains audio-only tracks
385- if ( isAudioOnly ) {
386- res . setHeader ( 'Content-Type' , 'audio/webm' ) ;
387- } else {
388- res . setHeader ( 'Content-Type' , 'video/webm' ) ;
370+ const destinationPath = path . join ( savePath , path . basename ( videoPath ) ) ;
371+
372+ fs . rename ( videoPath , destinationPath , ( err ) => {
373+ if ( err ) {
374+ console . error ( 'Error moving file:' , err ) ;
375+ return res . status ( 500 ) . send ( 'Error moving file' ) ;
389376 }
390- } else if ( ext === '.mp3' ) {
391- res . setHeader ( 'Content-Type' , 'audio/mp3' ) ;
392- } else if ( ext === '.m4a' ) {
393- res . setHeader ( 'Content-Type' , 'audio/m4a' ) ;
394- } else {
395- res . setHeader ( 'Content-Type' , 'application/octet-stream' ) ;
396- }
397- stream . pipe ( res ) ;
377+ shell . showItemInFolder ( destinationPath ) ;
378+ res . send ( JSON . stringify ( { path : destinationPath } ) ) ;
379+ } ) ;
380+
398381} ) ;
399382
400383app . on ( 'window-all-closed' , ( ) => {
0 commit comments