1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 17:59:55 +02:00

Improve add view

This commit is contained in:
DanieL 2022-10-03 12:50:23 -03:00
parent 6fe8b6a64f
commit d9a3c9a9bf
3 changed files with 185 additions and 192 deletions

View file

@ -151,7 +151,7 @@ if (!class_exists('Video')) {
return false;
}
$lastStatistic = self::getLastStatistics($this->id, User::getId());
$lastStatistic = VideoStatistic::getLastStatistics($this->id, User::getId());
if(!empty($lastStatistic)){
return false;
}

View file

@ -48,6 +48,12 @@ time.duration {
.thumbsImageContainer .thumbsImage{
border: none;
}
.thumbsImageContainer .progress{
height: 4px;
z-index: 1;
top: -4px;
}
}
.videoLink .glyphicon-play-circle {
transition: all 0.3s ease-in-out;
top: 50%;

View file

@ -480,37 +480,45 @@ var last_videos_id = 0;
var last_currentTime = -1;
var videoViewAdded = false;
var addViewBeaconTimeout;
var _addViewCheck = false;
function addView(videos_id, currentTime) {
addViewSetCookie(PHPSESSID, videos_id, currentTime, seconds_watching_video);
if(_addViewCheck){
return false;
}
if (last_videos_id == videos_id && last_currentTime == currentTime) {
return false;
}
if (currentTime > 5 && currentTime % 5 !== 0) { // only update each 5 seconds
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds
return false;
}
if (!videoViewAdded || videoViewAdded !== videos_id) {
videoViewAdded = videos_id;
_addViewCheck = true;
last_videos_id = videos_id;
last_currentTime = currentTime;
_addView(videos_id, currentTime);
}
_addView(videos_id, currentTime, seconds_watching_video);
setTimeout(function () {
_addViewCheck = false
}, 1000);
return true;
}
function _addView(videos_id, currentTime) {
function _addView(videos_id, currentTime, seconds_watching_video) {
if (typeof PHPSESSID == 'undefined') {
PHPSESSID = '';
}
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
if(empty(PHPSESSID)){
return false;
}
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
//console.log('_addView', videos_id, currentTime);
$.ajax({
url: url,
method: 'POST',
data: {
'id': videos_id,
'currentTime': currentTime
id: videos_id,
currentTime: currentTime,
seconds_watching_video: seconds_watching_video
},
success: function (response) {
$('.view-count' + videos_id).text(response.countHTML);
@ -530,23 +538,11 @@ function _addViewAsync() {
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
_addViewAsyncSent = true;
$.ajax({
url: url,
method: 'POST',
data: {
'id': mediaId,
'currentTime': playerCurrentTime,
'seconds_watching_video': seconds_watching_video
},
async: false,
success: function (response) {
//console.log('_addViewAsync', response);
_addView(mediaId, playerCurrentTime, seconds_watching_video);
setTimeout(function () {
_addViewAsyncSent = false;
}, 2000);
}
});
}
var _addViewFromCookie_addingtime = false;
async function addViewFromCookie() {
@ -575,21 +571,12 @@ async function addViewFromCookie() {
forceCurrentTime = addView_playerCurrentTime;
}
$.ajax({
url: url,
method: 'POST',
data: {
'id': addView_videos_id,
'currentTime': addView_playerCurrentTime,
'seconds_watching_video': addView_seconds_watching_video
},
async: false,
success: function (response) {
_addView(addView_videos_id, addView_playerCurrentTime, addView_seconds_watching_video)
setTimeout(function () {
_addViewFromCookie_addingtime = false;
//console.log('addViewFromCookie', response);
}, 2000);
addViewSetCookie(false, false, false, false);
}
});
}
async function addViewSetCookie(PHPSESSID, videos_id, playerCurrentTime, seconds_watching_video) {