diff --git a/backend/app.js b/backend/app.js index 95b36b6..0eb367a 100644 --- a/backend/app.js +++ b/backend/app.js @@ -1858,7 +1858,8 @@ app.post('/api/tomp3', optionalJwt, async function(req, res) { user: req.isAuthenticated() ? req.user.uid : null } - const safeDownloadOverride = config_api.getConfigItem('ytdl_safe_download_override'); + const safeDownloadOverride = config_api.getConfigItem('ytdl_safe_download_override') || config_api.globalArgsRequiresSafeDownload(); + if (safeDownloadOverride) logger.verbose('Download is running with the safe download override.'); const is_playlist = url.includes('playlist'); let result_obj = null; @@ -1888,7 +1889,8 @@ app.post('/api/tomp4', optionalJwt, async function(req, res) { user: req.isAuthenticated() ? req.user.uid : null } - const safeDownloadOverride = config_api.getConfigItem('ytdl_safe_download_override'); + const safeDownloadOverride = config_api.getConfigItem('ytdl_safe_download_override') || config_api.globalArgsRequiresSafeDownload(); + if (safeDownloadOverride) logger.verbose('Download is running with the safe download override.'); const is_playlist = url.includes('playlist'); let result_obj = null; @@ -2354,7 +2356,7 @@ app.post('/api/getPlaylist', optionalJwt, async (req, res) => { }); }); -app.post('/api/updatePlaylist', optionalJwt, async (req, res) => { +app.post('/api/updatePlaylistFiles', optionalJwt, async (req, res) => { let playlistID = req.body.playlistID; let fileNames = req.body.fileNames; let type = req.body.type; @@ -2362,7 +2364,7 @@ app.post('/api/updatePlaylist', optionalJwt, async (req, res) => { let success = false; try { if (req.isAuthenticated()) { - auth_api.updatePlaylist(req.user.uid, playlistID, fileNames, type); + auth_api.updatePlaylistFiles(req.user.uid, playlistID, fileNames, type); } else { db.get(`playlists.${type}`) .find({id: playlistID}) @@ -2380,6 +2382,14 @@ app.post('/api/updatePlaylist', optionalJwt, async (req, res) => { }) }); +app.post('/api/updatePlaylist', optionalJwt, async (req, res) => { + let playlist = req.body.playlist; + let success = db_api.updatePlaylist(playlist, req.user && req.user.uid); + res.send({ + success: success + }); +}); + app.post('/api/deletePlaylist', optionalJwt, async (req, res) => { let playlistID = req.body.playlistID; let type = req.body.type; diff --git a/backend/authentication/auth.js b/backend/authentication/auth.js index 0373215..297b047 100644 --- a/backend/authentication/auth.js +++ b/backend/authentication/auth.js @@ -331,7 +331,7 @@ exports.addPlaylist = function(user_uid, new_playlist, type) { return true; } -exports.updatePlaylist = function(user_uid, playlistID, new_filenames, type) { +exports.updatePlaylistFiles = function(user_uid, playlistID, new_filenames, type) { users_db.get('users').find({uid: user_uid}).get(`playlists.${type}`).find({id: playlistID}).assign({fileNames: new_filenames}); return true; } diff --git a/backend/config.js b/backend/config.js index 6f29cb8..0737cd2 100644 --- a/backend/config.js +++ b/backend/config.js @@ -155,6 +155,13 @@ function setConfigItems(items) { return success; } +function globalArgsRequiresSafeDownload() { + const globalArgs = config_api.getConfigItem('ytdl_custom_args'); + const argsThatRequireSafeDownload = ['--write-sub', '--write-srt']; + const failedArgs = globalArgs.filter(arg => argsThatRequireSafeDownload.includes(arg)); + return failedArgs && failedArgs.length > 0; +} + module.exports = { getConfigItem: getConfigItem, setConfigItem: setConfigItem, @@ -164,7 +171,8 @@ module.exports = { configExistsCheck: configExistsCheck, CONFIG_ITEMS: CONFIG_ITEMS, initialize: initialize, - descriptors: {} + descriptors: {}, + globalArgsRequiresSafeDownload: globalArgsRequiresSafeDownload } DEFAULT_CONFIG = { diff --git a/backend/db.js b/backend/db.js index 4bf2ba8..3f8e9aa 100644 --- a/backend/db.js +++ b/backend/db.js @@ -93,11 +93,25 @@ function generateFileObject(id, type, customPath = null, sub = null) { return file_obj; } +function updatePlaylist(playlist, user_uid) { + let playlistID = playlist.id; + let type = playlist.type; + let db_loc = null; + if (user_uid) { + db_loc = users_db.get('users').find({uid: user_uid}).get(`playlists.${type}`).find({id: playlistID}); + } else { + db_loc = db.get(`playlists.${type}`).find({id: playlistID}); + } + db_loc.assign(playlist).write(); + return true; +} + function getAppendedBasePathSub(sub, base_path) { return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name); } module.exports = { initialize: initialize, - registerFileDB: registerFileDB + registerFileDB: registerFileDB, + updatePlaylist: updatePlaylist } \ No newline at end of file diff --git a/src/app/player/player.component.ts b/src/app/player/player.component.ts index 7547362..2939852 100644 --- a/src/app/player/player.component.ts +++ b/src/app/player/player.component.ts @@ -62,6 +62,8 @@ export class PlayerComponent implements OnInit { downloading = false; + original_volume = null; + @HostListener('window:resize', ['$event']) onResize(event) { this.innerWidth = window.innerWidth; @@ -235,6 +237,12 @@ export class PlayerComponent implements OnInit { onPlayerReady(api: VgAPI) { this.api = api; + // checks if volume has been previously set. if so, use that as default + if (localStorage.getItem('player_volume')) { + this.api.volume = parseFloat(localStorage.getItem('player_volume')); + } + setInterval(() => this.saveVolume(this.api), 2000) + this.api.getDefaultMedia().subscriptions.loadedMetadata.subscribe(this.playVideo.bind(this)); this.api.getDefaultMedia().subscriptions.ended.subscribe(this.nextVideo.bind(this)); @@ -243,6 +251,13 @@ export class PlayerComponent implements OnInit { } } + saveVolume(api) { + if (this.original_volume !== api.volume) { + localStorage.setItem('player_volume', api.volume) + this.original_volume = api.volume; + } + } + nextVideo() { if (this.currentIndex === this.playlist.length - 1) { // dont continue playing @@ -374,7 +389,7 @@ export class PlayerComponent implements OnInit { updatePlaylist() { const fileNames = this.getFileNames(); this.playlist_updating = true; - this.postsService.updatePlaylist(this.id, fileNames, this.type).subscribe(res => { + this.postsService.updatePlaylistFiles(this.id, fileNames, this.type).subscribe(res => { this.playlist_updating = false; if (res['success']) { const fileNamesEncoded = fileNames.join('|nvr|'); diff --git a/src/app/posts.services.ts b/src/app/posts.services.ts index 479944d..4e8b20a 100644 --- a/src/app/posts.services.ts +++ b/src/app/posts.services.ts @@ -274,8 +274,12 @@ export class PostsService implements CanActivate { type: type, uuid: uuid}, this.httpOptions); } - updatePlaylist(playlistID, fileNames, type) { - return this.http.post(this.path + 'updatePlaylist', {playlistID: playlistID, + updatePlaylist(playlist) { + return this.http.post(this.path + 'updatePlaylist', {playlist: playlist}, this.httpOptions); + } + + updatePlaylistFiles(playlistID, fileNames, type) { + return this.http.post(this.path + 'updatePlaylistFiles', {playlistID: playlistID, fileNames: fileNames, type: type}, this.httpOptions); }