Improved movie counting
This commit is contained in:
parent
6a947adf89
commit
4f8531e240
|
@ -2338,10 +2338,6 @@ docker_restore() {
|
|||
LATEST_DIR=${2:-latest}
|
||||
RCS=$(rclone config show 2>/dev/null | grep "CINEMAPRESS")
|
||||
if [ "${RCS}" = "" ]; then exit 0; fi
|
||||
if [ -f "/home/${CP_DOMAIN}/log/movies.pid" ]; then
|
||||
pkill -P "$(cat "/home/${CP_DOMAIN}/log/movies.pid")" >/dev/null
|
||||
rm -f "/home/${CP_DOMAIN}/log/movies.pid" >/dev/null
|
||||
fi
|
||||
docker_stop
|
||||
rm -rf /var/mega/new && mkdir -p /var/mega/new
|
||||
mkdir -p /home/"${CP_DOMAIN}"/config/custom
|
||||
|
@ -2393,10 +2389,6 @@ docker_restore() {
|
|||
docker_backup() {
|
||||
RCS=$(rclone config show 2>/dev/null | grep "CINEMAPRESS")
|
||||
if [ "${RCS}" = "" ]; then exit 0; fi
|
||||
if [ -f "/home/${CP_DOMAIN}/log/movies.pid" ]; then
|
||||
pkill -P "$(cat "/home/${CP_DOMAIN}/log/movies.pid")" >/dev/null
|
||||
rm -f "/home/${CP_DOMAIN}/log/movies.pid" >/dev/null
|
||||
fi
|
||||
BACKUP_DAY=$(date +%d)
|
||||
BACKUP_NOW=$(date +%Y-%m-%d)
|
||||
BACKUP_DELETE=$(date +%Y-%m-%d -d "@$(($(date +%s) - 864000))")
|
||||
|
|
132
lib/CP_get.js
132
lib/CP_get.js
|
@ -842,56 +842,33 @@ function countMoviesGet(query, sorting, callback) {
|
|||
q._where = createWhere() + q._where;
|
||||
}
|
||||
|
||||
q._limit = 1;
|
||||
q._option = 'max_matches=500';
|
||||
q._limit = 0;
|
||||
|
||||
var queryString =
|
||||
'' +
|
||||
(q._select ? ' SELECT ' + q._select : '') +
|
||||
(q._from ? ' FROM ' + q._from : '') +
|
||||
(q._where ? ' WHERE ' + q._where : '') +
|
||||
(q._limit ? ' LIMIT ' + q._limit : '') +
|
||||
(typeof q._limit !== 'undefined' ? ' LIMIT ' + q._limit : '') +
|
||||
(q._option ? ' OPTION ' + q._option : '') +
|
||||
'; SHOW META';
|
||||
|
||||
CP_sphinx.query(queryString, function(err, count) {
|
||||
CP_sphinx.query(queryString, function(err, count_movies) {
|
||||
if (err) return callback(err);
|
||||
if (
|
||||
count &&
|
||||
count.length &&
|
||||
count[1] &&
|
||||
count[1].length &&
|
||||
count[1][1] &&
|
||||
count[1][1]['Value'] &&
|
||||
parseInt(count[1][1]['Value'])
|
||||
count_movies &&
|
||||
count_movies.length &&
|
||||
count_movies[1] &&
|
||||
count_movies[1].length &&
|
||||
count_movies[1][1] &&
|
||||
count_movies[1][1]['Value'] &&
|
||||
parseInt(count_movies[1][1]['Value'])
|
||||
) {
|
||||
if (query.query_id) return callback(null, count[1][1]['Value']);
|
||||
if (parseInt(count[1][1]['Value']) < 500)
|
||||
return callback(null, count[1][1]['Value']);
|
||||
queryString = queryString.replace(
|
||||
'max_matches=500',
|
||||
'max_matches=' + count[1][1]['Value']
|
||||
);
|
||||
CP_sphinx.query(queryString, function(err, count2) {
|
||||
if (err) return callback(err);
|
||||
if (
|
||||
count2 &&
|
||||
count2.length &&
|
||||
count2[1] &&
|
||||
count2[1].length &&
|
||||
count2[1][1] &&
|
||||
count2[1][1]['Value'] &&
|
||||
parseInt(count[1][1]['Value'])
|
||||
) {
|
||||
count2 = count2[1][1]['Value'];
|
||||
} else {
|
||||
count2 = 0;
|
||||
}
|
||||
callback(null, count2);
|
||||
});
|
||||
count_movies = count_movies[1][1]['Value'];
|
||||
} else {
|
||||
callback(null, 0);
|
||||
count_movies = 0;
|
||||
}
|
||||
callback(null, count_movies);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -924,6 +901,9 @@ function countMoviesGet(query, sorting, callback) {
|
|||
|
||||
for (var attribute in query) {
|
||||
if (query.hasOwnProperty(attribute) && query[attribute]) {
|
||||
if (attribute === 'search' && (query[attribute] + '').length === 1) {
|
||||
continue;
|
||||
}
|
||||
var search = CP_regexp.str(query[attribute]).toLowerCase();
|
||||
if (attribute.indexOf('custom.') + 1) {
|
||||
where.push('' + attribute + " = '" + search + "'");
|
||||
|
@ -955,9 +935,85 @@ function countMoviesGet(query, sorting, callback) {
|
|||
) {
|
||||
match.push('@' + attribute + ' ("' + search + '")');
|
||||
} else if (attribute === 'search' && search !== '!_empty') {
|
||||
match.push('@' + attribute + ' ("' + search + '")');
|
||||
match.push('@' + attribute + ' (' + search + ')');
|
||||
var str_search = search;
|
||||
if (/[^0-9]+\s+[0-9]{4}$/.test(search)) {
|
||||
match.push(
|
||||
'MAYBE @year (' + search.substr(search.length - 4) + ')'
|
||||
);
|
||||
str_search = search.substring(0, search.length - 4);
|
||||
}
|
||||
match.push('@' + attribute + ' ("' + str_search + '")');
|
||||
match.push('@' + attribute + ' (' + str_search + ')');
|
||||
} else if (attribute === 'year' && search.indexOf('-') + 1) {
|
||||
var year_begin = search.split('-')[0];
|
||||
var year_end = search.split('-')[1];
|
||||
var year_begin_date = Math.floor(
|
||||
new Date(year_begin + '-01-01').getTime() / 1000 / 60 / 60 / 24 +
|
||||
719528
|
||||
);
|
||||
var year_end_date = Math.floor(
|
||||
new Date(year_end + '-12-31').getTime() / 1000 / 60 / 60 / 24 +
|
||||
719528
|
||||
);
|
||||
if (year_begin_date) {
|
||||
where.push('`premiere` >= ' + year_begin_date);
|
||||
}
|
||||
if (year_end_date) {
|
||||
where.push('`premiere` <= ' + year_end_date);
|
||||
}
|
||||
} else if (attribute === 'kp_rating' && search.indexOf('-') + 1) {
|
||||
var kp_rating_begin = parseFloat(
|
||||
search.split('-')[0].replace(/[^0-9,.]/g, '') || '0'
|
||||
);
|
||||
var kp_rating_end = parseFloat(
|
||||
search.split('-')[1].replace(/[^0-9,.]/g, '') || '0'
|
||||
);
|
||||
kp_rating_begin =
|
||||
kp_rating_begin < 10
|
||||
? parseInt(kp_rating_begin * 10 + '')
|
||||
: parseInt(kp_rating_begin + '');
|
||||
kp_rating_end =
|
||||
kp_rating_end < 10
|
||||
? parseInt(kp_rating_end * 10 + '')
|
||||
: parseInt(kp_rating_end + '');
|
||||
if (kp_rating_begin) {
|
||||
where.push('`kp_rating` >= ' + kp_rating_begin);
|
||||
}
|
||||
if (kp_rating_end) {
|
||||
where.push('`kp_rating` <= ' + kp_rating_end);
|
||||
}
|
||||
} else if (attribute === 'imdb_rating' && search.indexOf('-') + 1) {
|
||||
var imdb_rating_begin = parseInt(
|
||||
search.split('-')[0].replace(/[^0-9]/g, '') || '0'
|
||||
);
|
||||
var imdb_rating_end = parseInt(
|
||||
search.split('-')[1].replace(/[^0-9]/g, '') || '0'
|
||||
);
|
||||
imdb_rating_begin =
|
||||
imdb_rating_begin < 10
|
||||
? parseInt(imdb_rating_begin * 10 + '')
|
||||
: parseInt(imdb_rating_begin + '');
|
||||
imdb_rating_end =
|
||||
imdb_rating_end < 10
|
||||
? parseInt(imdb_rating_end * 10 + '')
|
||||
: parseInt(imdb_rating_end + '');
|
||||
if (imdb_rating_begin) {
|
||||
where.push('`imdb_rating` >= ' + imdb_rating_begin);
|
||||
}
|
||||
if (imdb_rating_end) {
|
||||
where.push('`imdb_rating` <= ' + imdb_rating_end);
|
||||
}
|
||||
} else {
|
||||
if (attribute === 'genre') {
|
||||
match = match.filter(function(m) {
|
||||
return !(m.indexOf('@genre') + 1 && m.indexOf('!') + 1);
|
||||
});
|
||||
}
|
||||
if (attribute === 'all_movies') {
|
||||
match = match.filter(function(m) {
|
||||
return m.indexOf('@all_movies') === -1;
|
||||
});
|
||||
}
|
||||
match.push('@' + attribute + ' (' + search + ')');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1421,7 +1421,11 @@
|
|||
<tr>
|
||||
<th class="table-settings"></th>
|
||||
<th class="table-content table-content-head">
|
||||
<%= __('Фильмы') %> <% if (typeof count_movies != 'undefined') { %>(<code><% if (typeof uniq_movies != 'undefined') { %><%- uniq_movies %><span style="color:#666"> / </span><% } %><span style="color:#666"><%- count_movies %></span></code>)<% } %>
|
||||
<% if (config.urls.noindex) { %>
|
||||
<%= __('Фильмы') %> <% if (typeof count_movies != 'undefined') { %>(<code><% if (typeof uniq_movies != 'undefined') { %><%- uniq_movies %><span style="color:#666"> / </span><% } %><span style="color:#666"><%- count_movies %></span></code>)<% } %>
|
||||
<% } else { %>
|
||||
<%= __('Фильмы') %> <% if (typeof count_movies != 'undefined') { %>(<code><%- count_movies %></code>)<% } %>
|
||||
<% } %>
|
||||
</th>
|
||||
<th class="table-settings"></th>
|
||||
<th class="table-settings"></th>
|
||||
|
|
Loading…
Reference in a new issue