@ -29,12 +29,13 @@ exports.initialize = (input_db_api) => {
setupDownloads ( ) ;
}
exports . createDownload = async ( url , type , options ) => {
exports . createDownload = async ( url , type , options , user _uid = null ) => {
return await mutex . runExclusive ( async ( ) => {
const download = {
url : url ,
type : type ,
title : '' ,
user _uid : user _uid ,
options : options ,
uid : uuid ( ) ,
step _index : 0 ,
@ -82,7 +83,7 @@ exports.resumeDownload = async (download_uid) => {
exports . restartDownload = async ( download _uid ) => {
const download = await db _api . getRecord ( 'download_queue' , { uid : download _uid } ) ;
await exports . clearDownload ( download _uid ) ;
const success = ! ! ( await exports . createDownload ( download [ 'url' ] , download [ 'type' ] , download [ 'options' ] )) ;
const success = ! ! ( await exports . createDownload ( download [ 'url' ] , download [ 'type' ] , download [ 'options' ] , download [ 'user_uid' ] )) ;
should _check _downloads = true ;
return success ;
@ -171,13 +172,13 @@ async function collectInfo(download_uid) {
const type = download [ 'type' ] ;
const options = download [ 'options' ] ;
if ( options. user && ! options . customFileFolderPath ) {
if ( download[ 'user_uid' ] && ! options . customFileFolderPath ) {
let usersFileFolder = config _api . getConfigItem ( 'ytdl_users_base_path' ) ;
const user _path = path . join ( usersFileFolder , options. user , type ) ;
const user _path = path . join ( usersFileFolder , download[ 'user_uid' ] , type ) ;
options . customFileFolderPath = user _path + path . sep ;
}
let args = await generateArgs ( url , type , options );
let args = await generateArgs ( url , type , options , download [ 'user_uid' ] );
// get video info prior to download
let info = await getVideoInfoByURL ( url , args , download _uid ) ;
@ -198,7 +199,7 @@ async function collectInfo(download_uid) {
if ( category && category [ 'custom_output' ] ) {
options . customOutput = category [ 'custom_output' ] ;
options . noRelativePath = true ;
args = await generateArgs ( url , type , options );
args = await generateArgs ( url , type , options , download [ 'user_uid' ] );
info = await getVideoInfoByURL ( url , args , download _uid ) ;
}
@ -294,7 +295,7 @@ async function downloadQueuedFile(download_uid) {
&& config _api . getConfigItem ( 'ytdl_use_twitch_api' ) && config _api . getConfigItem ( 'ytdl_twitch_auto_download_chat' ) ) {
let vodId = url . split ( 'twitch.tv/videos/' ) [ 1 ] ;
vodId = vodId . split ( '?' ) [ 0 ] ;
twitch _api . downloadTwitchChatByVODID ( vodId , file _name , type , options. user ) ;
twitch _api . downloadTwitchChatByVODID ( vodId , file _name , type , download[ 'user_uid' ] ) ;
}
// renames file if necessary due to bug
@ -321,7 +322,7 @@ async function downloadQueuedFile(download_uid) {
}
// registers file in DB
const file _obj = await db _api . registerFileDB2 ( full _file _path , type , options. user , category , null , options . cropFileSettings ) ;
const file _obj = await db _api . registerFileDB2 ( full _file _path , type , download[ 'user_uid' ] , category , null , options . cropFileSettings ) ;
file _objs . push ( file _obj ) ;
}
@ -329,7 +330,7 @@ async function downloadQueuedFile(download_uid) {
if ( options . merged _string !== null && options . merged _string !== undefined ) {
let current _merged _archive = fs . readFileSync ( path . join ( fileFolderPath , ` merged_ ${ type } .txt ` ) , 'utf8' ) ;
let diff = current _merged _archive . replace ( options . merged _string , '' ) ;
const archive _path = options. user ? path . join ( fileFolderPath , 'archives' , ` archive_ ${ type } .txt ` ) : path . join ( archivePath , ` archive_ ${ type } .txt ` ) ;
const archive _path = download[ 'user_uid' ] ? path . join ( fileFolderPath , 'archives' , ` archive_ ${ type } .txt ` ) : path . join ( archivePath , ` archive_ ${ type } .txt ` ) ;
fs . appendFileSync ( archive _path , diff ) ;
}
@ -338,7 +339,7 @@ async function downloadQueuedFile(download_uid) {
if ( file _objs . length > 1 ) {
// create playlist
const playlist _name = file _objs . map ( file _obj => file _obj . title ) . join ( ', ' ) ;
container = await db _api . createPlaylist ( playlist _name , file _objs . map ( file _obj => file _obj . uid ) , type , options. user ) ;
container = await db _api . createPlaylist ( playlist _name , file _objs . map ( file _obj => file _obj . uid ) , type , download[ 'user_uid' ] ) ;
} else if ( file _objs . length === 1 ) {
container = file _objs [ 0 ] ;
} else {
@ -355,7 +356,7 @@ async function downloadQueuedFile(download_uid) {
// helper functions
async function generateArgs ( url , type , options ) {
async function generateArgs ( url , type , options , user _uid = null ) {
const audioFolderPath = config _api . getConfigItem ( 'ytdl_audio_folder_path' ) ;
const videoFolderPath = config _api . getConfigItem ( 'ytdl_video_folder_path' ) ;
@ -436,13 +437,13 @@ async function generateArgs(url, type, options) {
let useYoutubeDLArchive = config _api . getConfigItem ( 'ytdl_use_youtubedl_archive' ) ;
if ( useYoutubeDLArchive ) {
const archive _folder = options. user ? path . join ( fileFolderPath , 'archives' ) : archivePath ;
const archive _folder = user_uid ? path . join ( fileFolderPath , 'archives' ) : archivePath ;
const archive _path = path . join ( archive _folder , ` archive_ ${ type } .txt ` ) ;
await fs . ensureDir ( archive _folder ) ;
await fs . ensureFile ( archive _path ) ;
let blacklist _path = options. user ? path . join ( fileFolderPath , 'archives' , ` blacklist_ ${ type } .txt ` ) : path . join ( archivePath , ` blacklist_ ${ type } .txt ` ) ;
let blacklist _path = user_uid ? path . join ( fileFolderPath , 'archives' , ` blacklist_ ${ type } .txt ` ) : path . join ( archivePath , ` blacklist_ ${ type } .txt ` ) ;
await fs . ensureFile ( blacklist _path ) ;
let merged _path = path . join ( fileFolderPath , ` merged_ ${ type } .txt ` ) ;