Fix issues from Vue.js Merge

This commit is contained in:
PrestonN 2018-08-02 22:18:08 -04:00
parent 787cfb18c7
commit 015fdfae57
11 changed files with 466 additions and 468 deletions

View File

@ -57,6 +57,24 @@
"freetube"
]
}
],
"electronPackagerConfig": {
"packageManager": "yarn",
"icon": "./src/icons/iconColor.icns"
},
"electronWinstallerConfig": {
"name": "freetube",
"iconUrl": "https://raw.githubusercontent.com/FreeTubeApp/FreeTubeApp.github.io/master/images/iconColor.ico",
"setupIcon": "./src/icons/iconColor.ico"
},
"electronInstallerDebian": {
"icon": "src/icons/iconColor.png"
},
"repository": {
"type": "git",
"url": "https://github.com/FreeTubeApp/FreeTube"
}
}
},
"devDependencies": {
"electron-forge": "^5.2.2",

View File

@ -20,11 +20,22 @@
<div class="double-bounce1"></div>
<div class="double-bounce2"></div>
</div>
</div>
<div id='confirmFunction'>
<span id='confirmMessage'>Would you like to perform the function?</span>
<div class='confirmButton' id='confirmYes'>Yes</div>
<div class='confirmButton' id='confirmNo'>No</div>
</div>
<div id='toast'>
<span id='toastMessage'></span>
<i onclick='hideToast()' class="closeToast fas fa-times"></i>
</div>
<div class="topNav">
<i onclick='toggleSideNavigation()' class="fas fa-bars" id='menuButton'></i>
<div class="searchBar">
<input id='search' class="search" type="text" placeholder="Search / Go to URL">
<i onclick='parseSearchText()' class="fas fa-search searchButton" style='margin-right: -10px; cursor: pointer'></i>
</div>
<img src='icons/iconBlack.png' id='menuIcon' /> &nbsp;
<img src='icons/textBlack.png' id='menuText' />
</div>
@ -70,6 +81,7 @@
</div>
<div id='progressView'></div>
</body>
<script src="js/general.js"></script>
<script src="js/youtubeApi.js"></script>
<script src="js/updates.js"></script>
<script src="js/db.js"></script>

View File

@ -62,7 +62,7 @@ function goToChannel(channelId) {
maxResults: 50,
order: 'date',
}, function (data) {
const channelData = data.items[0];
let grabDuration = getDuration(data.items);
grabDuration.then((videoList) => {
channelView.seen = true;
@ -72,8 +72,6 @@ function goToChannel(channelId) {
videoList.items.forEach((video) => {
displayVideo(video, 'channel');
});
$('#main').html(rendered);
stopLoadingAnimation();
// Grab the channel's latest uploads. API forces a max of 50.
youtubeAPI('search', {
@ -93,4 +91,6 @@ function goToChannel(channelId) {
});
});
});
});
});
}

View File

@ -1,34 +1,31 @@
/*
This file is part of FreeTube.
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.
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.
You should have received a copy of the GNU General Public License
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
This file is part of FreeTube.
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.
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.
You should have received a copy of the GNU General Public License
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* File used for functions related to video history.
*/
* File used for functions related to video history.
*/
/**
* 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) {
* 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(),
@ -37,16 +34,14 @@ function addToHistory(videoId) {
}
/**
* 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
};
* 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) => {});
}
@ -65,12 +60,13 @@ function showHistory(){
historyDb.find({}).sort({
timeWatched: -1
}).exec((err, docs) => {
if (docs.length > 49) {
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 {
}
else{
docs.forEach((video) => {
videoList = videoList + ',' + video['videoId'];
});
@ -91,4 +87,5 @@ function showHistory(){
});
});
});
});
}

View File

@ -17,19 +17,17 @@
import {
comment
} from "./comment.model";
import {comment} from "./comment.model";
/**
* Entire Comment Threads for a Video
*/
export class commentThread {
videoId;
nextPageToken;
pageInfo = {
totalResults,
resultsPerPage
videoId: ?string;
nextPageToken: ?string;
pageInfo: {
totalResults: number,
resultsPerPage: number
};
items;
items: comment[];
}

View File

@ -127,6 +127,9 @@ function playVideo(videoId) {
if (typeof(info.player_response.captions.playerCaptionsTracklistRenderer.captionTracks) === 'object') {
const videoSubtitles = info.player_response.captions.playerCaptionsTracklistRenderer.captionTracks;
videoSubtitles.forEach((subtitle) => {
let subtitleUrl = 'https://www.youtube.com/api/timedtext?lang=' + subtitle.languageCode + '&fmt=vtt&name=&v=' + videoId;
if (subtitle.kind == 'asr') {
//subtitleUrl = subtitle.baseUrl;
return;
@ -137,17 +140,12 @@ function playVideo(videoId) {
}
}
//videoHtml = videoHtml + '</video>';
}
playerView.subtitleHtml = videoHtml;
}
}
const checkSubscription = isSubscribed(playerView.channelId);
checkSubscription.then((results) => {
const subscribeButton = document.getElementById('subscribeButton');
checkSubscription.then((results) => {
if (results === false) {
if (subscribeButton != null) {
@ -181,10 +179,7 @@ function playVideo(videoId) {
});
}
window.setTimeout(checkVideoUrls, 5000, video480p, video720p);
window.setTimeout(checkVideoUrls, 5000, playerView.video480p, playerView.video720p);
});
}
@ -225,6 +220,7 @@ function openMiniPlayer() {
videoThumbnail: playerView.thumbnail,
startTime: lastTime,
});
});
}
/**

View File

@ -152,4 +152,5 @@ function showSavedVideos(){
});
});
});
});
}

View File

@ -1,18 +1,15 @@
/*
This file is part of FreeTube.
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.
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.
You should have received a copy of the GNU General Public License
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
This file is part of FreeTube.
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.
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.
You should have received a copy of the GNU General Public License
along with FreeTube. If not, see <http://www.gnu.org/licenses/>.
*/
@ -81,12 +78,10 @@ function checkDefaultSettings() {
'useTor': false
};
ft.log('Default Settings: ', settingDefaults);
console.log(settingDefaults);
for (let key in settingDefaults) {
settingsDb.find({
_id: key
}, (err, docs) => {
for (let key in settingDefaults){
settingsDb.find({_id: key}, (err, docs) => {
if (jQuery.isEmptyObject(docs)) {
newSetting = {
_id: key,
@ -134,15 +129,20 @@ function updateSettings() {
let key = document.getElementById('api-key').value;
let theme = 'light';
if (apiKeyBank.indexOf(key) == -1 && key !== '') {
settingsView.apiKey = key;
}
else{
settingsView.apiKey = apiKeyBank[Math.floor(Math.random() * apiKeyBank.length)];
}
ft.log('(Is the theme switch checked) themeSwitch: ', themeSwitch);
console.log(themeSwitch);
if (themeSwitch === true) {
theme = 'dark';
}
ft.log('Theme: ', theme);
console.log(theme);
// Update default theme
settingsDb.update({
@ -165,38 +165,12 @@ function updateSettings() {
useTor = torSwitch;
});
if (key !== '') {
settingsDb.update({
_id: 'theme'
}, {
value: theme
}, {}, function (err, numReplaced) {
ft.log('Error while updating theme: ', err);
ft.log('Number replaced: ', numReplaced);
});
// Update tor usage.
settingsDb.update({
_id: 'useTor'
}, {
value: settingsView.apiKey
}, {});
}
if (key != '') {
settingsDb.update({
_id: 'apiKey'
}, {
value: key
}, {});
} else {
// To any third party devs that fork the project, please be ethical and change the API key.
settingsDb.update({
_id: 'apiKey'
}, {
value: apiKey
value: settingsView.apiKey
}, {});
}
showToast('Settings have been saved.');
}
@ -260,14 +234,14 @@ function setTheme(option) {
}
/**
* Import Subscriptions from an OPML file.
*
* @param {string} subFile - The file location of the OPML file.
*
* @return {Void}
*/
function importOpmlSubs(json) {
if (!json[0]['folder'].includes('YouTube')) {
* Import Subscriptions from an OPML file.
*
* @param {string} subFile - The file location of the OPML file.
*
* @return {Void}
*/
function importOpmlSubs(json){
if(!json[0]['folder'].includes('YouTube')){
showToast('Invalid OPML File. Import is unsuccessful.');
return;
}
@ -283,29 +257,28 @@ function importOpmlSubs(json) {
}
/**
* Import a subscriptions file that the user provides.
*
* @return {Void}
*/
function importSubscriptions() {
* Import a subscriptions file that the user provides.
*
* @return {Void}
*/
function importSubscriptions(){
const appDatabaseFile = localDataStorage + '/subscriptions.db';
// Open user's file browser. Only show .db files.
dialog.showOpenDialog({
properties: ['openFile'],
filters: [{
name: 'Database File',
extensions: ['*']
}, ]
}, function (fileLocation) {
if (typeof (fileLocation) === 'undefined') {
ft.log('Import Aborted');
filters: [
{name: 'Database File', extensions: ['*']},
]
}, function(fileLocation){
if(typeof(fileLocation) === 'undefined'){
console.log('Import Aborted');
return;
}
ft.log('File Location: ', fileLocation);
console.log(fileLocation);
let i = fileLocation[0].lastIndexOf('.');
let fileType = (i < 0) ? '' : fileLocation[0].substr(i);
ft.log('File Type: ', fileType);
console.log(fileType);
fs.readFile(fileLocation[0], function(readErr, data){
if(readErr){
@ -313,23 +286,24 @@ function importSubscriptions() {
throw readErr;
}
if (data.includes("<opml")) {
getOpml(data, function (error, json) {
if (!error) {
if (data.includes("<opml")){
getOpml(data, function (error, json){
if (!error){
clearFile('subscriptions', false);
importOpmlSubs(json['children'][0]['children']);
}
});
return;
} else if (fileType !== '.db') {
}
else if (fileType !== '.db'){
showToast('Incorrect file type. Import unsuccessful.');
return;
}
clearFile('subscriptions', false);
fs.writeFile(appDatabaseFile, data, function (writeErr) {
if (writeErr) {
fs.writeFile(appDatabaseFile, data, function(writeErr){
if(writeErr){
showToast('Unable to create file. Please check your permissions and try again.');
throw writeErr;
}
@ -350,13 +324,13 @@ function exportSubscriptions() {
const date = new Date();
let dateMonth = date.getMonth() + 1;
if (dateMonth < 10) {
if (dateMonth < 10){
dateMonth = '0' + dateMonth;
}
let dateDay = date.getDate();
if (dateDay < 10) {
if (dateDay < 10){
dateDay = '0' + dateDay;
}
@ -370,17 +344,17 @@ function exportSubscriptions() {
name: 'Database File',
extensions: ['db']
}, ]
}, function (fileLocation) {
ft.log('File Location: ', fileLocation);
if (typeof (fileLocation) === 'undefined') {
ft.log('Export Aborted');
}, function(fileLocation) {
console.log(fileLocation);
if (typeof(fileLocation) === 'undefined') {
console.log('Export Aborted');
return;
}
fs.readFile(appDatabaseFile, function (readErr, data) {
fs.readFile(appDatabaseFile, function(readErr, data) {
if (readErr) {
throw readErr;
}
fs.writeFile(fileLocation, data, function (writeErr) {
fs.writeFile(fileLocation, data, function(writeErr) {
if (writeErr) {
throw writeErr;
}
@ -391,12 +365,12 @@ function exportSubscriptions() {
}
/**
* Clear out the data in a file.
*
* @param {string} type - The type of file to be cleared.
*/
function clearFile(type, showMessage = true) {
ft.log('File Type: ', type);
* Clear out the data in a file.
*
* @param {string} type - The type of file to be cleared.
*/
function clearFile(type, showMessage = true){
console.log(type);
let dataBaseFile;
switch (type) {
@ -415,9 +389,15 @@ function clearFile(type, showMessage = true) {
}
// Replace data with an empty string.
fs.writeFile(dataBaseFile, '', function (err) {
fs.writeFile(dataBaseFile, '', function(err) {
if (err) {
throw err;
}
if (showMessage){
showToast('File has been cleared. Restart FreeTube to see the changes');
}
})
}
checkDefaultSettings();

View File

@ -80,7 +80,7 @@ function removeSubscription(channelId) {
*
* @return {Void}
*/
function loadSubscriptions() {
function loadSubscriptions() {
if (checkSubscriptions === false && subscriptionView.videoList.length > 0){
console.log('Will not load subscriptions. Timer still on.');
loadingView.seen = false;
@ -112,14 +112,6 @@ function loadSubscriptions() {
maxResults: 15,
order: 'date',
}, (data) => {
youtubeAPI('search', {
part: 'snippet',
channelId: channelId,
type: 'video',
maxResults: 15,
order: 'date',
}, (data) => {
console.log(data);
videoList = videoList.concat(data.items);
counter++;
@ -151,13 +143,9 @@ function loadSubscriptions() {
let finishedList = [];
let firstBatchDuration = getDuration(videoList.slice(0, 49));
grabDuration.then((list) => {
list.items.forEach((video) => {
displayVideo(video);
});
stopLoadingAnimation();
});
} else {
firstBatchDuration.then((list1) => {
finishedList = finishedList.concat(list1.items);
let secondBatchDuration = getDuration(videoList.slice(50, 99));
secondBatchDuration.then((list2) => {
finishedList = finishedList.concat(list2.items);
@ -177,6 +165,8 @@ function loadSubscriptions() {
}
}
}
);
}
} else {
@ -186,7 +176,7 @@ function loadSubscriptions() {
noSubscriptions.seen = true;
}
});
}
}
/**
* Get the list of subscriptions from the user's subscription database.

View File

@ -180,6 +180,11 @@ let popularView = new Vue({
},
toggleSave: (videoId) => {
addSavedVideo(videoId);
},
copy: (site, videoId) => {
const url = 'https://' + site + '/watch?v=' + videoId;
clipboard.writeText(url);
showToast('URL has been copied to the clipboard');
}
},
template: videoListTemplate

View File

@ -220,7 +220,6 @@ function displayChannels(channels) {
}, function (data) {
ft.log('Channel Data: ', data);
let items = data['items'].reverse();
const videoListTemplate = require('./templates/channelList.html');
ft.log('Channel Items: ', items);
@ -240,6 +239,7 @@ function displayChannels(channels) {
searchView.videoList = searchView.videoList.concat(channelData);
});
});
}
function displayPlaylists(playlists) {
@ -343,6 +343,7 @@ function showVideoRecommendations(videoId) {
playerView.recommendedVideoList = playerView.recommendedVideoList.concat(data);
});
});
});
}
/**
@ -404,7 +405,7 @@ function parseSearchText(url = '') {
* @return {string} - The formated string. Ex: 12:34:56
*/
function parseVideoDuration(durationString) {
let match = durationString.match(/PT(\d+H)?(\d+M)?(\d+S)?/);
let match = durationString.match(/P.*T(\d+H)?(\d+M)?(\d+S)?/);
let duration = '';
match = match.slice(1).map(function (x) {