mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 11:41:28 +03:00
Player component now remembers previously set volume
Updated name of updatePlaylist->updatePlaylistFiles for clarity and added updatePlaylist route Added smarter safe download override, will auto activate if subtitle args are included.
This commit is contained in:
@@ -1858,7 +1858,8 @@ app.post('/api/tomp3', optionalJwt, async function(req, res) {
|
|||||||
user: req.isAuthenticated() ? req.user.uid : null
|
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');
|
const is_playlist = url.includes('playlist');
|
||||||
|
|
||||||
let result_obj = null;
|
let result_obj = null;
|
||||||
@@ -1888,7 +1889,8 @@ app.post('/api/tomp4', optionalJwt, async function(req, res) {
|
|||||||
user: req.isAuthenticated() ? req.user.uid : null
|
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');
|
const is_playlist = url.includes('playlist');
|
||||||
|
|
||||||
let result_obj = null;
|
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 playlistID = req.body.playlistID;
|
||||||
let fileNames = req.body.fileNames;
|
let fileNames = req.body.fileNames;
|
||||||
let type = req.body.type;
|
let type = req.body.type;
|
||||||
@@ -2362,7 +2364,7 @@ app.post('/api/updatePlaylist', optionalJwt, async (req, res) => {
|
|||||||
let success = false;
|
let success = false;
|
||||||
try {
|
try {
|
||||||
if (req.isAuthenticated()) {
|
if (req.isAuthenticated()) {
|
||||||
auth_api.updatePlaylist(req.user.uid, playlistID, fileNames, type);
|
auth_api.updatePlaylistFiles(req.user.uid, playlistID, fileNames, type);
|
||||||
} else {
|
} else {
|
||||||
db.get(`playlists.${type}`)
|
db.get(`playlists.${type}`)
|
||||||
.find({id: playlistID})
|
.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) => {
|
app.post('/api/deletePlaylist', optionalJwt, async (req, res) => {
|
||||||
let playlistID = req.body.playlistID;
|
let playlistID = req.body.playlistID;
|
||||||
let type = req.body.type;
|
let type = req.body.type;
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ exports.addPlaylist = function(user_uid, new_playlist, type) {
|
|||||||
return true;
|
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});
|
users_db.get('users').find({uid: user_uid}).get(`playlists.${type}`).find({id: playlistID}).assign({fileNames: new_filenames});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,13 @@ function setConfigItems(items) {
|
|||||||
return success;
|
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 = {
|
module.exports = {
|
||||||
getConfigItem: getConfigItem,
|
getConfigItem: getConfigItem,
|
||||||
setConfigItem: setConfigItem,
|
setConfigItem: setConfigItem,
|
||||||
@@ -164,7 +171,8 @@ module.exports = {
|
|||||||
configExistsCheck: configExistsCheck,
|
configExistsCheck: configExistsCheck,
|
||||||
CONFIG_ITEMS: CONFIG_ITEMS,
|
CONFIG_ITEMS: CONFIG_ITEMS,
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
descriptors: {}
|
descriptors: {},
|
||||||
|
globalArgsRequiresSafeDownload: globalArgsRequiresSafeDownload
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
|
|||||||
@@ -93,11 +93,25 @@ function generateFileObject(id, type, customPath = null, sub = null) {
|
|||||||
return file_obj;
|
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) {
|
function getAppendedBasePathSub(sub, base_path) {
|
||||||
return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name);
|
return path.join(base_path, (sub.isPlaylist ? 'playlists/' : 'channels/'), sub.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
registerFileDB: registerFileDB
|
registerFileDB: registerFileDB,
|
||||||
|
updatePlaylist: updatePlaylist
|
||||||
}
|
}
|
||||||
@@ -62,6 +62,8 @@ export class PlayerComponent implements OnInit {
|
|||||||
|
|
||||||
downloading = false;
|
downloading = false;
|
||||||
|
|
||||||
|
original_volume = null;
|
||||||
|
|
||||||
@HostListener('window:resize', ['$event'])
|
@HostListener('window:resize', ['$event'])
|
||||||
onResize(event) {
|
onResize(event) {
|
||||||
this.innerWidth = window.innerWidth;
|
this.innerWidth = window.innerWidth;
|
||||||
@@ -235,6 +237,12 @@ export class PlayerComponent implements OnInit {
|
|||||||
onPlayerReady(api: VgAPI) {
|
onPlayerReady(api: VgAPI) {
|
||||||
this.api = api;
|
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.loadedMetadata.subscribe(this.playVideo.bind(this));
|
||||||
this.api.getDefaultMedia().subscriptions.ended.subscribe(this.nextVideo.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() {
|
nextVideo() {
|
||||||
if (this.currentIndex === this.playlist.length - 1) {
|
if (this.currentIndex === this.playlist.length - 1) {
|
||||||
// dont continue playing
|
// dont continue playing
|
||||||
@@ -374,7 +389,7 @@ export class PlayerComponent implements OnInit {
|
|||||||
updatePlaylist() {
|
updatePlaylist() {
|
||||||
const fileNames = this.getFileNames();
|
const fileNames = this.getFileNames();
|
||||||
this.playlist_updating = true;
|
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;
|
this.playlist_updating = false;
|
||||||
if (res['success']) {
|
if (res['success']) {
|
||||||
const fileNamesEncoded = fileNames.join('|nvr|');
|
const fileNamesEncoded = fileNames.join('|nvr|');
|
||||||
|
|||||||
@@ -274,8 +274,12 @@ export class PostsService implements CanActivate {
|
|||||||
type: type, uuid: uuid}, this.httpOptions);
|
type: type, uuid: uuid}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePlaylist(playlistID, fileNames, type) {
|
updatePlaylist(playlist) {
|
||||||
return this.http.post(this.path + 'updatePlaylist', {playlistID: playlistID,
|
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,
|
fileNames: fileNames,
|
||||||
type: type}, this.httpOptions);
|
type: type}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user