@ -241,65 +241,22 @@ async function getVideosForSub(sub, user_uid = null) {
logger . verbose ( 'Subscription: finished check for ' + sub . name ) ;
if ( err && ! output ) {
logger . error ( err . stderr ? err . stderr : err . message ) ;
if ( err . stderr . includes ( 'This video is unavailable' ) ) {
if ( err . stderr . includes ( 'This video is unavailable' ) || err . stderr . includes ( 'Private video' ) ) {
logger . info ( 'An error was encountered with at least one video, backup method will be used.' )
try {
// TODO: reimplement
// const outputs = err.stdout.split(/\r\n|\r|\n/);
// for (let i = 0; i < outputs.length; i++) {
// const output = JSON.parse(outputs[i]);
// await handleOutputJSON(sub, output, i === 0, multiUserMode)
// if (err.stderr.includes(output['id']) && archive_path) {
// // we found a video that errored! add it to the archive to prevent future errors
// if (sub.archive) {
// archive_dir = sub.archive;
// archive_path = path.join(archive_dir, 'archive.txt')
// fs.appendFileSync(archive_path, output['id']);
// }
// }
// }
const outputs = err . stdout . split ( /\r\n|\r|\n/ ) ; // .map(jsonStr => JSON.parse(jsonStr));
const files _to _download = await handleOutputJSON ( outputs , sub , user _uid ) ;
resolve ( files _to _download ) ;
} catch ( e ) {
logger . error ( 'Backup method failed. See error below:' ) ;
logger . error ( e ) ;
}
} else {
logger . error ( 'Subscription check failed!' ) ;
}
resolve ( false ) ;
} else if ( output ) {
if ( config _api . getConfigItem ( 'ytdl_subscriptions_redownload_fresh_uploads' ) ) {
await setFreshUploads ( sub , user _uid ) ;
checkVideosForFreshUploads ( sub , user _uid ) ;
}
if ( output . length === 0 || ( output . length === 1 && output [ 0 ] === '' ) ) {
logger . verbose ( 'No additional videos to download for ' + sub . name ) ;
resolve ( true ) ;
return ;
}
const output _jsons = [ ] ;
for ( let i = 0 ; i < output . length ; i ++ ) {
let output _json = null ;
try {
output _json = JSON . parse ( output [ i ] ) ;
output _jsons . push ( output _json ) ;
} catch ( e ) {
output _json = null ;
}
if ( ! output _json ) {
continue ;
}
}
const files _to _download = await getFilesToDownload ( sub , output _jsons ) ;
const base _download _options = generateOptionsForSubscriptionDownload ( sub , user _uid ) ;
for ( let j = 0 ; j < files _to _download . length ; j ++ ) {
const file _to _download = files _to _download [ j ] ;
file _to _download [ 'formats' ] = utils . stripPropertiesFromObject ( file _to _download [ 'formats' ] , [ 'format_id' , 'filesize' , 'filesize_approx' ] ) ; // prevent download object from blowing up in size
await downloader _api . createDownload ( file _to _download [ 'webpage_url' ] , sub . type || 'video' , base _download _options , user _uid , sub . id , sub . name , file _to _download ) ;
}
const files _to _download = await handleOutputJSON ( output , sub , user _uid ) ;
resolve ( files _to _download ) ;
}
} ) ;
@ -309,6 +266,43 @@ async function getVideosForSub(sub, user_uid = null) {
} ) ;
}
async function handleOutputJSON ( output , sub , user _uid ) {
if ( config _api . getConfigItem ( 'ytdl_subscriptions_redownload_fresh_uploads' ) ) {
await setFreshUploads ( sub , user _uid ) ;
checkVideosForFreshUploads ( sub , user _uid ) ;
}
if ( output . length === 0 || ( output . length === 1 && output [ 0 ] === '' ) ) {
logger . verbose ( 'No additional videos to download for ' + sub . name ) ;
return [ ] ;
}
const output _jsons = [ ] ;
for ( let i = 0 ; i < output . length ; i ++ ) {
let output _json = null ;
try {
output _json = JSON . parse ( output [ i ] ) ;
output _jsons . push ( output _json ) ;
} catch ( e ) {
output _json = null ;
}
if ( ! output _json ) {
continue ;
}
}
const files _to _download = await getFilesToDownload ( sub , output _jsons ) ;
const base _download _options = generateOptionsForSubscriptionDownload ( sub , user _uid ) ;
for ( let j = 0 ; j < files _to _download . length ; j ++ ) {
const file _to _download = files _to _download [ j ] ;
file _to _download [ 'formats' ] = utils . stripPropertiesFromObject ( file _to _download [ 'formats' ] , [ 'format_id' , 'filesize' , 'filesize_approx' ] ) ; // prevent download object from blowing up in size
await downloader _api . createDownload ( file _to _download [ 'webpage_url' ] , sub . type || 'video' , base _download _options , user _uid , sub . id , sub . name , file _to _download ) ;
}
return files _to _download ;
}
function generateOptionsForSubscriptionDownload ( sub , user _uid ) {
let basePath = null ;
if ( user _uid )