mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-12 15:41:29 +03:00
Fixed bug where sharing didn't work for some videos
View count now increments on each play unless the video is shared
This commit is contained in:
@@ -2233,6 +2233,27 @@ app.post('/api/disableSharing', optionalJwt, function(req, res) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/api/incrementViewCount', optionalJwt, async (req, res) => {
|
||||||
|
let file_uid = req.body.file_uid;
|
||||||
|
let sub_id = req.body.sub_id;
|
||||||
|
let uuid = req.body.uuid;
|
||||||
|
|
||||||
|
if (!uuid && req.isAuthenticated()) {
|
||||||
|
uuid = req.user.uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file_obj = await db_api.getVideo(file_uid, uuid, sub_id);
|
||||||
|
|
||||||
|
const current_view_count = file_obj && file_obj['local_view_count'] ? file_obj['local_view_count'] : 0;
|
||||||
|
const new_view_count = current_view_count + 1;
|
||||||
|
|
||||||
|
await db_api.setVideoProperty(file_uid, {local_view_count: new_view_count}, uuid, sub_id);
|
||||||
|
|
||||||
|
res.send({
|
||||||
|
success: true
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// categories
|
// categories
|
||||||
|
|
||||||
app.post('/api/getAllCategories', optionalJwt, async (req, res) => {
|
app.post('/api/getAllCategories', optionalJwt, async (req, res) => {
|
||||||
@@ -2759,7 +2780,7 @@ app.get('/api/stream/:id', optionalJwt, (req, res) => {
|
|||||||
var head;
|
var head;
|
||||||
let optionalParams = url_api.parse(req.url,true).query;
|
let optionalParams = url_api.parse(req.url,true).query;
|
||||||
let id = decodeURIComponent(req.params.id);
|
let id = decodeURIComponent(req.params.id);
|
||||||
let file_path = req.query.file_path ? decodeURIComponent(req.query.file_path) : null;
|
let file_path = req.query.file_path ? decodeURIComponent(req.query.file_path.split('?')[0]) : null;
|
||||||
if (!file_path && (req.isAuthenticated() || req.can_watch)) {
|
if (!file_path && (req.isAuthenticated() || req.can_watch)) {
|
||||||
let usersFileFolder = config_api.getConfigItem('ytdl_users_base_path');
|
let usersFileFolder = config_api.getConfigItem('ytdl_users_base_path');
|
||||||
if (optionalParams['subName']) {
|
if (optionalParams['subName']) {
|
||||||
|
|||||||
@@ -205,10 +205,28 @@ async function importUnregisteredFiles() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getVideo(file_uid, uuid, sub_id) {
|
||||||
|
const base_db_path = uuid ? users_db.get('users').find({uid: uuid}) : db;
|
||||||
|
const sub_db_path = sub_id ? base_db_path.get('subscriptions').find({id: sub_id}).get('videos') : base_db_path.get('files');
|
||||||
|
return sub_db_path.find({uid: file_uid}).value();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setVideoProperty(file_uid, assignment_obj, uuid, sub_id) {
|
||||||
|
const base_db_path = uuid ? users_db.get('users').find({uid: uuid}) : db;
|
||||||
|
const sub_db_path = sub_id ? base_db_path.get('subscriptions').find({id: sub_id}).get('videos') : base_db_path.get('files');
|
||||||
|
const file_db_path = sub_db_path.find({uid: file_uid});
|
||||||
|
if (!(file_db_path.value())) {
|
||||||
|
logger.error(`Failed to find file with uid ${file_uid}`);
|
||||||
|
}
|
||||||
|
sub_db_path.find({uid: file_uid}).assign(assignment_obj).write();
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
registerFileDB: registerFileDB,
|
registerFileDB: registerFileDB,
|
||||||
updatePlaylist: updatePlaylist,
|
updatePlaylist: updatePlaylist,
|
||||||
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
getFileDirectoriesAndDBs: getFileDirectoriesAndDBs,
|
||||||
importUnregisteredFiles: importUnregisteredFiles
|
importUnregisteredFiles: importUnregisteredFiles,
|
||||||
|
getVideo: getVideo,
|
||||||
|
setVideoProperty: setVideoProperty
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-2 col-lg-1">
|
<div class="col-2 col-lg-1">
|
||||||
<ng-container *ngIf="db_file">{{db_file['local_view_count'] ? db_file['local_view_count'] : 0}} <ng-container i18n="View count label">views</ng-container></ng-container>
|
<ng-container *ngIf="db_file">{{db_file['local_view_count'] ? db_file['local_view_count']+1 : 1}} <ng-container i18n="View count label">views</ng-container></ng-container>
|
||||||
</div>
|
</div>
|
||||||
<div style="white-space: pre-line;" class="col-9 col-lg-10">
|
<div style="white-space: pre-line;" class="col-9 col-lg-10">
|
||||||
<ng-container *ngIf="db_file && db_file['description']">
|
<ng-container *ngIf="db_file && db_file['description']">
|
||||||
|
|||||||
@@ -160,6 +160,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.openSnackBar('Failed to get file information from the server.', 'Dismiss');
|
this.openSnackBar('Failed to get file information from the server.', 'Dismiss');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.postsService.incrementViewCount(this.db_file['uid'], null, this.uuid).subscribe(res => {}, err => {
|
||||||
|
console.error('Failed to increment view count');
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
this.sharingEnabled = this.db_file.sharingEnabled;
|
this.sharingEnabled = this.db_file.sharingEnabled;
|
||||||
if (!this.fileNames) {
|
if (!this.fileNames) {
|
||||||
// means it's a shared video
|
// means it's a shared video
|
||||||
@@ -186,6 +190,10 @@ export class PlayerComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
subscription.videos.forEach(video => {
|
subscription.videos.forEach(video => {
|
||||||
if (video['id'] === this.fileNames[0]) {
|
if (video['id'] === this.fileNames[0]) {
|
||||||
this.db_file = video;
|
this.db_file = video;
|
||||||
|
this.postsService.incrementViewCount(this.db_file['uid'], this.subscription['id'], this.uuid).subscribe(res => {}, err => {
|
||||||
|
console.error('Failed to increment view count');
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
this.show_player = true;
|
this.show_player = true;
|
||||||
this.parseFileNames();
|
this.parseFileNames();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,6 +286,10 @@ export class PostsService implements CanActivate {
|
|||||||
return this.http.post(this.path + 'enableSharing', {uid: uid, type: type, is_playlist: is_playlist}, this.httpOptions);
|
return this.http.post(this.path + 'enableSharing', {uid: uid, type: type, is_playlist: is_playlist}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
incrementViewCount(file_uid, sub_id, uuid) {
|
||||||
|
return this.http.post(this.path + 'incrementViewCount', {file_uid: file_uid, sub_id: sub_id, uuid: uuid}, this.httpOptions);
|
||||||
|
}
|
||||||
|
|
||||||
disableSharing(uid, type, is_playlist) {
|
disableSharing(uid, type, is_playlist) {
|
||||||
return this.http.post(this.path + 'disableSharing', {uid: uid, type: type, is_playlist: is_playlist}, this.httpOptions);
|
return this.http.post(this.path + 'disableSharing', {uid: uid, type: type, is_playlist: is_playlist}, this.httpOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user