@ -51,6 +51,7 @@ var useDefaultDownloadingAgent = null;
var customDownloadingAgent = null ;
var allowSubscriptions = null ;
var subscriptionsCheckInterval = null ;
var archivePath = path . join ( _ _dirname , 'appdata' , 'archives' ) ;
// other needed values
var options = null ; // encryption options
@ -197,6 +198,11 @@ async function loadConfig() {
url _domain = new URL ( url ) ;
// creates archive path if missing
if ( ! fs . existsSync ( archivePath ) ) {
fs . mkdirSync ( archivePath ) ;
}
// get subscriptions
if ( allowSubscriptions ) {
// runs initially, then runs every ${subscriptionCheckInterval} seconds
@ -452,7 +458,7 @@ async function deleteAudioFile(name, blacklistMode = false) {
let useYoutubeDLArchive = config _api . getConfigItem ( 'ytdl_use_youtubedl_archive' ) ;
if ( useYoutubeDLArchive ) {
const archive _path = audioFolderPath + 'archive.txt' ;
const archive _path = path. join ( archivePath , 'archive_audio.txt' ) ;
// get ID from JSON
@ -510,7 +516,7 @@ async function deleteVideoFile(name, customPath = null, blacklistMode = false) {
let useYoutubeDLArchive = config _api . getConfigItem ( 'ytdl_use_youtubedl_archive' ) ;
if ( useYoutubeDLArchive ) {
const archive _path = videoFolderPath + 'archive.txt' ;
const archive _path = path. join ( archivePath , 'archive_video.txt' ) ;
// get ID from JSON
@ -633,10 +639,10 @@ async function getUrlInfos(urls) {
}
function writeToBlacklist ( type , line ) {
let blacklist Base Path = ( type === 'audio' ) ? audioFolderPath : videoFolderPath ;
let blacklist Path = path . join ( archivePath , ( type === 'audio' ) ? 'blacklist_audio.txt' : 'blacklist_video.txt' ) ;
// adds newline to the beginning of the line
line = '\n' + line ;
fs . appendFileSync ( blacklist Base Path + 'blacklist.txt' , line ) ;
fs . appendFileSync ( blacklist Path, line ) ;
}
async function startYoutubeDL ( ) {
@ -806,13 +812,13 @@ app.post('/api/tomp3', async function(req, res) {
let useYoutubeDLArchive = config _api . getConfigItem ( 'ytdl_use_youtubedl_archive' ) ;
if ( useYoutubeDLArchive ) {
let archive _path = audioFolderPath + 'archive.txt' ;
const archive _path = path . join ( archivePath , 'archive_audio.txt' ) ;
// create archive file if it doesn't exist
if ( ! fs . existsSync ( archive _path ) ) {
fs . closeSync ( fs . openSync ( archive _path , 'w' ) ) ;
}
let blacklist _path = audioFolderPath + 'blacklist.txt' ;
let blacklist _path = path. join ( archivePath , 'blacklist_audio.txt' ) ;
// create blacklist file if it doesn't exist
if ( ! fs . existsSync ( blacklist _path ) ) {
fs . closeSync ( fs . openSync ( blacklist _path , 'w' ) ) ;
@ -886,7 +892,8 @@ app.post('/api/tomp3', async function(req, res) {
if ( merged _string !== null ) {
let current _merged _archive = fs . readFileSync ( merged _path , 'utf8' ) ;
let diff = current _merged _archive . replace ( merged _string , '' ) ;
fs . appendFileSync ( audioFolderPath + 'archive.txt' , diff ) ;
const archive _path = path . join ( archivePath , 'archive_audio.txt' ) ;
fs . appendFileSync ( archive _path , diff ) ;
fs . unlinkSync ( merged _path )
}
@ -902,7 +909,6 @@ app.post('/api/tomp3', async function(req, res) {
app . post ( '/api/tomp4' , async function ( req , res ) {
var url = req . body . url ;
var date = Date . now ( ) ;
var path = videoFolderPath ;
var videopath = '%(title)s' ;
var globalArgs = config _api . getConfigItem ( 'ytdl_custom_args' ) ;
var customArgs = req . body . customArgs ;
@ -928,9 +934,9 @@ app.post('/api/tomp4', async function(req, res) {
}
if ( customOutput ) {
downloadConfig = [ '-o' , p ath + customOutput + ".mp4" , '-f' , qualityPath , '--write-info-json' , '--print-json' ] ;
downloadConfig = [ '-o' , videoFolderP ath + customOutput + ".mp4" , '-f' , qualityPath , '--write-info-json' , '--print-json' ] ;
} else {
downloadConfig = [ '-o' , p ath + videopath + ".mp4" , '-f' , qualityPath , '--write-info-json' , '--print-json' ] ;
downloadConfig = [ '-o' , videoFolderP ath + videopath + ".mp4" , '-f' , qualityPath , '--write-info-json' , '--print-json' ] ;
}
if ( youtubeUsername && youtubePassword ) {
@ -943,13 +949,13 @@ app.post('/api/tomp4', async function(req, res) {
let useYoutubeDLArchive = config _api . getConfigItem ( 'ytdl_use_youtubedl_archive' ) ;
if ( useYoutubeDLArchive ) {
let archive _path = videoFolderPath + 'archive.txt' ;
const archive _path = path . join ( archivePath , 'archive_video.txt' ) ;
// create archive file if it doesn't exist
if ( ! fs . existsSync ( archive _path ) ) {
fs . closeSync ( fs . openSync ( archive _path , 'w' ) ) ;
}
let blacklist _path = videoFolderPath + 'blacklist.txt' ;
let blacklist _path = path. join ( archivePath , 'blacklist_video.txt' ) ;
// create blacklist file if it doesn't exist
if ( ! fs . existsSync ( blacklist _path ) ) {
fs . closeSync ( fs . openSync ( blacklist _path , 'w' ) ) ;
@ -1023,7 +1029,8 @@ app.post('/api/tomp4', async function(req, res) {
if ( merged _string !== null ) {
let current _merged _archive = fs . readFileSync ( videoFolderPath + 'merged.txt' , 'utf8' ) ;
let diff = current _merged _archive . replace ( merged _string , '' ) ;
fs . appendFileSync ( videoFolderPath + 'archive.txt' , diff ) ;
const archive _path = path . join ( archivePath , 'archive_video.txt' ) ;
fs . appendFileSync ( archive _path , diff ) ;
}
var videopathEncoded = encodeURIComponent ( file _names [ 0 ] ) ;