@ -853,7 +853,7 @@ async function createPlaylistZipFile(fileNames, type, outputName, fullPathProvid
let zipFolderPath = null ;
if ( ! fullPathProvided ) {
zipFolderPath = path . join ( _ _dirname , ( type === 'audio' ) ? audioFolderPath : videoFolderPath ) ;
zipFolderPath = ( type === 'audio' ) ? audioFolderPath : videoFolderPath
if ( user _uid ) zipFolderPath = path . join ( config _api . getConfigItem ( 'ytdl_users_base_path' ) , user _uid , zipFolderPath ) ;
} else {
zipFolderPath = path . join ( _ _dirname , config _api . getConfigItem ( 'ytdl_subscriptions_base_path' ) ) ;
@ -1155,7 +1155,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
}
// download file
youtubedl . exec ( url , downloadConfig , { } , function ( err , output ) {
youtubedl . exec ( url , downloadConfig , { } , async function ( err , output ) {
if ( download _checker ) clearInterval ( download _checker ) ; // stops the download checker from running as the download finished (or errored)
download [ 'downloading' ] = false ;
@ -1227,8 +1227,12 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
const file _path = options . noRelativePath ? path . basename ( full _file _path ) : full _file _path . substring ( fileFolderPath . length , full _file _path . length ) ;
const customPath = options . noRelativePath ? path . dirname ( full _file _path ) . split ( path . sep ) . pop ( ) : null ;
if ( options . cropFileSettings ) {
await cropFile ( full _file _path , options . cropFileSettings . cropFileStart , options . cropFileSettings . cropFileEnd , ext ) ;
}
// registers file in DB
file _uid = db _api . registerFileDB ( file _path , type , multiUserMode , null , customPath , category ) ;
file _uid = db _api . registerFileDB ( file _path , type , multiUserMode , null , customPath , category , options . cropFileSettings );
if ( file _name ) file _names . push ( file _name ) ;
}
@ -1587,6 +1591,8 @@ async function getUrlInfos(urls) {
} ) ;
}
// ffmpeg helper functions
async function convertFileToMp3 ( input _file , output _file ) {
logger . verbose ( ` Converting ${ input _file } to ${ output _file } ... ` ) ;
return new Promise ( resolve => {
@ -1604,6 +1610,33 @@ async function convertFileToMp3(input_file, output_file) {
} ) ;
}
async function cropFile ( file _path , start , end , ext ) {
return new Promise ( resolve => {
const temp _file _path = ` ${ file _path } .cropped ${ ext } ` ;
let base _ffmpeg _call = ffmpeg ( file _path ) ;
if ( start ) {
base _ffmpeg _call = base _ffmpeg _call . seekOutput ( start ) ;
}
if ( end ) {
base _ffmpeg _call = base _ffmpeg _call . duration ( end - start ) ;
}
base _ffmpeg _call
. on ( 'end' , ( ) => {
logger . verbose ( ` Cropping for ' ${ file _path } ' complete. ` ) ;
fs . unlinkSync ( file _path ) ;
fs . moveSync ( temp _file _path , file _path ) ;
resolve ( true ) ;
} )
. on ( 'error' , ( err , test , test2 ) => {
logger . error ( ` Failed to crop ${ file _path } . ` ) ;
logger . error ( err ) ;
resolve ( false ) ;
} ) . save ( temp _file _path ) ;
} ) ;
}
// archive helper functions
async function writeToBlacklist ( type , line ) {
let blacklistPath = path . join ( archivePath , ( type === 'audio' ) ? 'blacklist_audio.txt' : 'blacklist_video.txt' ) ;
// adds newline to the beginning of the line
@ -1908,7 +1941,8 @@ app.post('/api/tomp4', optionalJwt, async function(req, res) {
youtubeUsername : req . body . youtubeUsername ,
youtubePassword : req . body . youtubePassword ,
ui _uid : req . body . ui _uid ,
user : req . isAuthenticated ( ) ? req . user . uid : null
user : req . isAuthenticated ( ) ? req . user . uid : null ,
cropFileSettings : req . body . cropFileSettings
}
const safeDownloadOverride = config _api . getConfigItem ( 'ytdl_safe_download_override' ) || config _api . globalArgsRequiresSafeDownload ( ) ;
@ -2666,7 +2700,7 @@ app.post('/api/downloadFile', optionalJwt, async (req, res) => {
for ( let i = 0 ; i < fileNames . length ; i ++ ) {
fileNames [ i ] = decodeURIComponent ( fileNames [ i ] ) ;
}
file = await createPlaylistZipFile ( fileNames , type , outputName , fullPathProvided , req . body . uuid ) ;
file = await createPlaylistZipFile ( fileNames , type , outputName , fullPathProvided , req . body . uuid || req . user . uid ) ;
if ( ! path . isAbsolute ( file ) ) file = path . join ( _ _dirname , file ) ;
}
res . sendFile ( file , function ( err ) {