2018-03-02 04:48:12 +01:00
|
|
|
/*
|
2018-07-24 03:11:56 +02:00
|
|
|
This file is part of FreeTube.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
FreeTube is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
FreeTube is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
|
2018-03-02 04:48:12 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-07-24 03:11:56 +02:00
|
|
|
* File used for functions related to video history.
|
|
|
|
*/
|
2018-03-02 04:48:12 +01:00
|
|
|
|
|
|
|
/**
|
2018-07-24 03:11:56 +02:00
|
|
|
* Add a video to the history database file
|
|
|
|
*
|
|
|
|
* @param {string} videoId - The video ID of the video to be saved.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function addToHistory(videoId) {
|
|
|
|
const data = {
|
|
|
|
videoId: videoId,
|
|
|
|
timeWatched: new Date().getTime(),
|
|
|
|
};
|
|
|
|
historyDb.insert(data, (err, newDoc) => {});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-07-24 03:11:56 +02:00
|
|
|
* Remove a video from the history database file
|
|
|
|
*
|
|
|
|
* @param {string} videoId - The video ID of the video to be removed.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function removeFromHistory(videoId) {
|
|
|
|
const data = {
|
|
|
|
videoId: videoId
|
|
|
|
};
|
|
|
|
historyDb.remove(data, {}, (err, numRemoved) => {});
|
2018-03-02 04:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the videos within the history database.
|
|
|
|
*
|
|
|
|
* @return {Void}
|
|
|
|
*/
|
|
|
|
function showHistory(){
|
2018-06-25 22:04:11 +02:00
|
|
|
//clearMainContainer();
|
|
|
|
//startLoadingAnimation();
|
2018-03-02 04:48:12 +01:00
|
|
|
console.log('checking history');
|
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
let videoList = '';
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-07-24 03:11:56 +02:00
|
|
|
historyDb.find({}).sort({
|
|
|
|
timeWatched: -1
|
|
|
|
}).exec((err, docs) => {
|
|
|
|
if (docs.length > 49) {
|
|
|
|
// The YouTube API limits the search to 50 videos, so grab 50 most recent.
|
|
|
|
for (let i = 0; i < 49; i++) {
|
|
|
|
videoList = videoList + ',' + docs[i]['videoId'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
docs.forEach((video) => {
|
|
|
|
videoList = videoList + ',' + video['videoId'];
|
|
|
|
});
|
|
|
|
}
|
2018-03-02 04:48:12 +01:00
|
|
|
|
2018-03-10 22:03:32 +01:00
|
|
|
youtubeAPI('videos', {
|
2018-03-02 04:48:12 +01:00
|
|
|
part: 'snippet',
|
|
|
|
id: videoList,
|
|
|
|
maxResults: 50,
|
2018-03-10 22:03:32 +01:00
|
|
|
}, function (data) {
|
2018-03-15 15:59:50 +01:00
|
|
|
let grabDuration = getDuration(data.items);
|
|
|
|
|
|
|
|
grabDuration.then((videoList) => {
|
2018-06-25 22:04:11 +02:00
|
|
|
historyView.videoList = [];
|
|
|
|
loadingView.seen = false;
|
2018-03-15 15:59:50 +01:00
|
|
|
videoList.items.forEach((video) => {
|
|
|
|
displayVideo(video, 'history');
|
|
|
|
});
|
2018-03-02 04:48:12 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-24 03:11:56 +02:00
|
|
|
}
|