@ -588,7 +588,18 @@ function calculateSubcriptionRetrievalDelay(amount) {
}
function watchSubscriptions ( ) {
let subscriptions = subscriptions _api . getAllSubscriptions ( ) ;
let subscriptions = null ;
const multiUserMode = config _api . getConfigItem ( 'ytdl_multi_user_mode' ) ;
if ( multiUserMode ) {
subscriptions = [ ] ;
let users = users _db . get ( 'users' ) . value ( ) ;
for ( let i = 0 ; i < users . length ; i ++ ) {
if ( users [ i ] [ 'subscriptions' ] ) subscriptions = subscriptions . concat ( users [ i ] [ 'subscriptions' ] ) ;
}
} else {
subscriptions = subscriptions _api . getAllSubscriptions ( ) ;
}
if ( ! subscriptions ) return ;
@ -600,7 +611,7 @@ function watchSubscriptions() {
let sub = subscriptions [ i ] ;
logger . verbose ( 'Watching ' + sub . name + ' with delay interval of ' + delay _interval ) ;
setTimeout ( ( ) => {
subscriptions _api . getVideosForSub ( sub );
subscriptions _api . getVideosForSub ( sub , sub . user _uid );
} , current _delay ) ;
current _delay += delay _interval ;
if ( current _delay >= subscriptionsCheckInterval * 1000 ) current _delay = 0 ;
@ -2022,17 +2033,19 @@ app.post('/api/disableSharing', optionalJwt, function(req, res) {
} ) ;
} ) ;
app . post ( '/api/subscribe' , async ( req , res ) => {
app . post ( '/api/subscribe' , optionalJwt , async ( req , res ) => {
let name = req . body . name ;
let url = req . body . url ;
let timerange = req . body . timerange ;
let streamingOnly = req . body . streamingOnly ;
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
const new _sub = {
name : name ,
url : url ,
id : uuid ( ) ,
streamingOnly : streamingOnly
streamingOnly : streamingOnly ,
user _uid : user _uid
} ;
// adds timerange if it exists, otherwise all videos will be downloaded
@ -2040,7 +2053,7 @@ app.post('/api/subscribe', async (req, res) => {
new _sub . timerange = timerange ;
}
const result _obj = await subscriptions _api . subscribe ( new _sub );
const result _obj = await subscriptions _api . subscribe ( new _sub , user _uid );
if ( result _obj . success ) {
res . send ( {
@ -2054,11 +2067,12 @@ app.post('/api/subscribe', async (req, res) => {
}
} ) ;
app . post ( '/api/unsubscribe' , async ( req , res ) => {
app . post ( '/api/unsubscribe' , optionalJwt , async ( req , res ) => {
let deleteMode = req . body . deleteMode
let sub = req . body . sub ;
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
let result _obj = subscriptions _api . unsubscribe ( sub , deleteMode );
let result _obj = subscriptions _api . unsubscribe ( sub , deleteMode , user _uid );
if ( result _obj . success ) {
res . send ( {
success : result _obj . success
@ -2071,12 +2085,13 @@ app.post('/api/unsubscribe', async (req, res) => {
}
} ) ;
app . post ( '/api/deleteSubscriptionFile' , async ( req , res ) => {
app . post ( '/api/deleteSubscriptionFile' , optionalJwt , async ( req , res ) => {
let deleteForever = req . body . deleteForever ;
let file = req . body . file ;
let sub = req . body . sub ;
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
let success = await subscriptions _api . deleteSubscriptionFile ( sub , file , deleteForever );
let success = await subscriptions _api . deleteSubscriptionFile ( sub , file , deleteForever , user _uid );
if ( success ) {
res . send ( {
@ -2088,11 +2103,12 @@ app.post('/api/deleteSubscriptionFile', async (req, res) => {
} ) ;
app . post ( '/api/getSubscription' , async ( req , res ) => {
app . post ( '/api/getSubscription' , optionalJwt , async ( req , res ) => {
let subID = req . body . id ;
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
// get sub from db
let subscription = subscriptions _api . getSubscription ( subID );
let subscription = subscriptions _api . getSubscription ( subID , user _uid );
if ( ! subscription ) {
// failed to get subscription from db, send 400 error
@ -2102,7 +2118,12 @@ app.post('/api/getSubscription', async (req, res) => {
// get sub videos
if ( subscription . name && ! subscription . streamingOnly ) {
let base _path = config _api . getConfigItem ( 'ytdl_subscriptions_base_path' ) ;
let base _path = null ;
if ( user _uid )
base _path = path . join ( config _api . getConfigItem ( 'ytdl_users_base_path' ) , user _uid , 'subscriptions' ) ;
else
base _path = config _api . getConfigItem ( 'ytdl_subscriptions_base_path' ) ;
let appended _base _path = path . join ( base _path , subscription . isPlaylist ? 'playlists' : 'channels' , subscription . name , '/' ) ;
let files ;
try {
@ -2159,18 +2180,22 @@ app.post('/api/getSubscription', async (req, res) => {
}
} ) ;
app . post ( '/api/downloadVideosForSubscription' , async ( req , res ) => {
app . post ( '/api/downloadVideosForSubscription' , optionalJwt , async ( req , res ) => {
let subID = req . body . subID ;
let sub = subscriptions _api . getSubscription ( subID ) ;
subscriptions _api . getVideosForSub ( sub ) ;
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
let sub = subscriptions _api . getSubscription ( subID , user _uid ) ;
subscriptions _api . getVideosForSub ( sub , user _uid ) ;
res . send ( {
success : true
} ) ;
} ) ;
app . post ( '/api/getAllSubscriptions' , async ( req , res ) => {
app . post ( '/api/getAllSubscriptions' , optionalJwt , async ( req , res ) => {
let user _uid = req . isAuthenticated ( ) ? req . user . uid : null ;
// get subs from api
let subscriptions = subscriptions _api . getAllSubscriptions ( ) ;
let subscriptions = subscriptions _api . getAllSubscriptions ( user _uid ) ;
res . send ( {
subscriptions : subscriptions
@ -2360,7 +2385,7 @@ app.post('/api/downloadFile', optionalJwt, async (req, res) => {
let outputName = req . body . outputName ;
let fullPathProvided = req . body . fullPathProvided ;
let subscriptionName = req . body . subscriptionName ;
let subscriptionPlaylist = req . body . sub scription Playlist;
let subscriptionPlaylist = req . body . sub Playlist;
let file = null ;
if ( ! zip _mode ) {
fileNames = decodeURIComponent ( fileNames ) ;
@ -2369,14 +2394,19 @@ app.post('/api/downloadFile', optionalJwt, async (req, res) => {
const ext = is _audio ? '.mp3' : '.mp4' ;
let base _path = fileFolderPath ;
let usersFileFolder = null ;
if ( req . isAuthenticated ( ) ) {
const usersFileFolder = config _api . getConfigItem ( 'ytdl_users_base_path' ) ;
usersFileFolder = config _api . getConfigItem ( 'ytdl_users_base_path' ) ;
base _path = path . join ( usersFileFolder , req . user . uid , type ) ;
}
if ( ! subscriptionName ) {
file = path . join ( _ _dirname , base _path , fileNames + ext ) ;
} else {
let basePath = config _api . getConfigItem ( 'ytdl_subscriptions_base_path' ) ;
let basePath = null ;
if ( usersFileFolder )
basePath = path . join ( usersFileFolder , req . user . uid , 'subscriptions' ) ;
else
basePath = config _api . getConfigItem ( 'ytdl_subscriptions_base_path' ) ;
file = path . join ( _ _dirname , basePath , ( subscriptionPlaylist ? 'playlists' : 'channels' ) , subscriptionName , fileNames + '.mp4' )
}
} else {
@ -2509,7 +2539,7 @@ app.get('/api/video/:id', optionalJwt, function(req , res){
let usersFileFolder = config _api . getConfigItem ( 'ytdl_users_base_path' ) ;
if ( optionalParams [ 'subName' ] ) {
const isPlaylist = optionalParams [ 'subPlaylist' ] ;
file _path = path . join ( usersFileFolder , req . user . uid , ( isPlaylist === 'true' ? 'playlists/' : 'channels/' ) , id + '.mp4' )
file _path = path . join ( usersFileFolder , req . user . uid , 'subscriptions' , ( isPlaylist === 'true' ? 'playlists/' : 'channels/' ) , optionalParams [ 'subName' ] , id + '.mp4' )
} else {
file _path = path . join ( usersFileFolder , req . user . uid , 'video' , id + '.mp4' ) ;
}