mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-17 02:00:56 +03:00
Updated video playing/sharing logic to support sharing of playlists in multi user mode and when multi user mode is disabled
Fixed bug that caused normal archive to be used in multi-user mode Updated login logic when username is not found or user file is missing Fixed bug that prevented playlist sharing from working Added ability to use timestamps when sharing videos
This commit is contained in:
@@ -9,6 +9,12 @@
|
||||
<div>
|
||||
<mat-checkbox [checked]="sharing_enabled" (change)="sharingChanged($event)"><ng-container i18n="Enable sharing checkbox">Enable sharing</ng-container></mat-checkbox>
|
||||
</div>
|
||||
<div>
|
||||
<mat-checkbox style="margin-right: 15px;" (change)="useTimestampChanged()" [(ngModel)]="timestamp_enabled">Use timestamp</mat-checkbox>
|
||||
<mat-form-field>
|
||||
<input matInput type="number" [(ngModel)]="current_timestamp" [disabled]="!timestamp_enabled" (change)="timestampInputChanged($event)" placeholder="Seconds" i18n-placeholder="Seconds">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div>
|
||||
<mat-form-field style="width: 100%">
|
||||
<input matInput [disabled]="!sharing_enabled" [readonly]="true" [value]="share_url">
|
||||
|
||||
@@ -15,8 +15,11 @@ export class ShareMediaDialogComponent implements OnInit {
|
||||
uid = null;
|
||||
uuid = null;
|
||||
share_url = null;
|
||||
default_share_url = null;
|
||||
sharing_enabled = null;
|
||||
is_playlist = null;
|
||||
current_timestamp = null
|
||||
timestamp_enabled = false;
|
||||
|
||||
constructor(@Inject(MAT_DIALOG_DATA) public data: any, public router: Router, private snackBar: MatSnackBar,
|
||||
private postsService: PostsService) { }
|
||||
@@ -28,15 +31,34 @@ export class ShareMediaDialogComponent implements OnInit {
|
||||
this.uuid = this.data.uuid;
|
||||
this.sharing_enabled = this.data.sharing_enabled;
|
||||
this.is_playlist = this.data.is_playlist;
|
||||
this.current_timestamp = (this.data.current_timestamp / 1000).toFixed(2);
|
||||
|
||||
const arg = (this.is_playlist ? ';id=' : ';uid=');
|
||||
this.share_url = window.location.href.split(';')[0] + arg + this.uid;
|
||||
this.default_share_url = window.location.href.split(';')[0] + arg + this.uid;
|
||||
if (this.uuid) {
|
||||
this.share_url += ';uuid=' + this.uuid;
|
||||
this.default_share_url += ';uuid=' + this.uuid;
|
||||
}
|
||||
this.share_url = this.default_share_url;
|
||||
}
|
||||
}
|
||||
|
||||
timestampInputChanged(change) {
|
||||
if (!this.timestamp_enabled) {
|
||||
this.share_url = this.default_share_url;
|
||||
return;
|
||||
}
|
||||
const new_val = change.target.value;
|
||||
if (new_val > 0) {
|
||||
this.share_url = this.default_share_url + ';timestamp=' + new_val;
|
||||
} else {
|
||||
this.share_url = this.default_share_url;
|
||||
}
|
||||
}
|
||||
|
||||
useTimestampChanged() {
|
||||
this.timestampInputChanged({target: {value: this.current_timestamp}})
|
||||
}
|
||||
|
||||
copiedToClipboard() {
|
||||
this.openSnackBar('Copied to clipboard!');
|
||||
}
|
||||
|
||||
@@ -491,7 +491,7 @@ export class MainComponent implements OnInit {
|
||||
if (is_playlist) {
|
||||
this.router.navigate(['/player', {fileNames: name.join('|nvr|'), type: 'audio'}]);
|
||||
} else {
|
||||
this.router.navigate(['/player', {fileNames: name, type: 'audio', uid: uid}]);
|
||||
this.router.navigate(['/player', {type: 'audio', uid: uid}]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -528,7 +528,7 @@ export class MainComponent implements OnInit {
|
||||
if (is_playlist) {
|
||||
this.router.navigate(['/player', {fileNames: name.join('|nvr|'), type: 'video'}]);
|
||||
} else {
|
||||
this.router.navigate(['/player', {fileNames: name, type: 'video', uid: uid}]);
|
||||
this.router.navigate(['/player', {type: 'video', uid: uid}]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ export class PlayerComponent implements OnInit {
|
||||
subscriptionName = null;
|
||||
subPlaylist = null;
|
||||
uuid = null; // used for sharing in multi-user mode, uuid is the user that downloaded the video
|
||||
timestamp = null;
|
||||
|
||||
is_shared = false;
|
||||
|
||||
@@ -77,6 +78,7 @@ export class PlayerComponent implements OnInit {
|
||||
this.url = this.route.snapshot.paramMap.get('url');
|
||||
this.name = this.route.snapshot.paramMap.get('name');
|
||||
this.uuid = this.route.snapshot.paramMap.get('uuid');
|
||||
this.timestamp = this.route.snapshot.paramMap.get('timestamp');
|
||||
|
||||
// loading config
|
||||
if (this.postsService.initialized) {
|
||||
@@ -102,7 +104,7 @@ export class PlayerComponent implements OnInit {
|
||||
this.subscriptionFolderPath = this.postsService.config['Subscriptions']['subscriptions_base_path'];
|
||||
this.fileNames = this.route.snapshot.paramMap.get('fileNames') ? this.route.snapshot.paramMap.get('fileNames').split('|nvr|') : null;
|
||||
|
||||
if (!this.fileNames) {
|
||||
if (!this.fileNames && !this.type) {
|
||||
this.is_shared = true;
|
||||
}
|
||||
|
||||
@@ -149,7 +151,7 @@ export class PlayerComponent implements OnInit {
|
||||
if (!already_has_filenames) { this.parseFileNames(); }
|
||||
}
|
||||
}
|
||||
if (this.db_file['sharingEnabled']) {
|
||||
if (this.db_file['sharingEnabled'] || !this.uuid) {
|
||||
this.show_player = true;
|
||||
} else if (!already_has_filenames) {
|
||||
this.openSnackBar('Error: Sharing has been disabled for this video!', 'Dismiss');
|
||||
@@ -158,12 +160,18 @@ export class PlayerComponent implements OnInit {
|
||||
}
|
||||
|
||||
getPlaylistFiles() {
|
||||
this.postsService.getPlaylist(this.id, null).subscribe(res => {
|
||||
this.db_playlist = res['playlist'];
|
||||
this.fileNames = this.db_playlist['fileNames'];
|
||||
this.type = res['type'];
|
||||
this.show_player = true;
|
||||
this.parseFileNames();
|
||||
this.postsService.getPlaylist(this.id, null, this.uuid).subscribe(res => {
|
||||
if (res['playlist']) {
|
||||
this.db_playlist = res['playlist'];
|
||||
this.fileNames = this.db_playlist['fileNames'];
|
||||
this.type = res['type'];
|
||||
this.show_player = true;
|
||||
this.parseFileNames();
|
||||
} else {
|
||||
this.openSnackBar('Failed to load playlist!', '');
|
||||
}
|
||||
}, err => {
|
||||
this.openSnackBar('Failed to load playlist!', '');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,11 +204,15 @@ export class PlayerComponent implements OnInit {
|
||||
}
|
||||
|
||||
// adds user token if in multi-user-mode
|
||||
const uuid_str = this.uuid ? `&uuid=${this.uuid}` : '';
|
||||
const uid_str = (this.id || !this.db_file) ? '' : `&uid=${this.db_file.uid}`;
|
||||
const type_str = (this.id || !this.db_file) ? '' : `&type=${this.db_file.type}`
|
||||
const id_str = this.id ? `&id=${this.id}` : '';
|
||||
if (this.postsService.isLoggedIn) {
|
||||
fullLocation += (this.subscriptionName ? '&' : '?') + `jwt=${this.postsService.token}`;
|
||||
if (this.is_shared) { fullLocation += `&uuid=${this.uuid}&uid=${this.db_file.uid}&type=${this.db_file.type}`; }
|
||||
if (this.is_shared) { fullLocation += `${uuid_str}${uid_str}${type_str}${id_str}`; }
|
||||
} else if (this.is_shared) {
|
||||
fullLocation += (this.subscriptionName ? '&' : '?') + `uuid=${this.uuid}&uid=${this.db_file.uid}&type=${this.db_file.type}`;
|
||||
fullLocation += (this.subscriptionName ? '&' : '?') + `test=test${uuid_str}${uid_str}${type_str}${id_str}`;
|
||||
}
|
||||
// if it has a slash (meaning it's in a directory), only get the file name for the label
|
||||
let label = null;
|
||||
@@ -228,6 +240,10 @@ export class PlayerComponent implements OnInit {
|
||||
|
||||
this.api.getDefaultMedia().subscriptions.loadedMetadata.subscribe(this.playVideo.bind(this));
|
||||
this.api.getDefaultMedia().subscriptions.ended.subscribe(this.nextVideo.bind(this));
|
||||
|
||||
if (this.timestamp) {
|
||||
this.api.seekTime(+this.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
nextVideo() {
|
||||
@@ -381,7 +397,8 @@ export class PlayerComponent implements OnInit {
|
||||
type: this.type,
|
||||
sharing_enabled: this.id ? this.db_playlist.sharingEnabled : this.db_file.sharingEnabled,
|
||||
is_playlist: !!this.id,
|
||||
uuid: this.postsService.isLoggedIn ? this.postsService.user.uid : null
|
||||
uuid: this.postsService.isLoggedIn ? this.postsService.user.uid : null,
|
||||
current_timestamp: this.api.time.current
|
||||
},
|
||||
width: '60vw'
|
||||
});
|
||||
|
||||
@@ -258,9 +258,9 @@ export class PostsService implements CanActivate {
|
||||
thumbnailURL: thumbnailURL}, this.httpOptions);
|
||||
}
|
||||
|
||||
getPlaylist(playlistID, type) {
|
||||
getPlaylist(playlistID, type, uuid = null) {
|
||||
return this.http.post(this.path + 'getPlaylist', {playlistID: playlistID,
|
||||
type: type}, this.httpOptions);
|
||||
type: type, uuid: uuid}, this.httpOptions);
|
||||
}
|
||||
|
||||
updatePlaylist(playlistID, fileNames, type) {
|
||||
@@ -335,6 +335,7 @@ export class PostsService implements CanActivate {
|
||||
this.permissions = permissions;
|
||||
this.available_permissions = available_permissions;
|
||||
this.token = token;
|
||||
this.setInitialized();
|
||||
|
||||
localStorage.setItem('jwt_token', this.token);
|
||||
|
||||
@@ -365,7 +366,6 @@ export class PostsService implements CanActivate {
|
||||
call.subscribe(res => {
|
||||
if (res['token']) {
|
||||
this.afterLogin(res['user'], res['token'], res['permissions'], res['available_permissions']);
|
||||
this.setInitialized();
|
||||
}
|
||||
}, err => {
|
||||
if (err.status === 401) {
|
||||
|
||||
Reference in New Issue
Block a user