Implement importing of Newpipe Subscriptions (#234)

* Implement importing of NewPIpe subscriptions

* Fix Import NewPipe subscriptions: Display channel picture instead of newpipe logo

* use addSubscription() instead of subDb

* Import subscriptions will also handle newpipe files

* Fix notification, minor code fixes
This commit is contained in:
kskarthik 2019-03-19 00:06:49 +05:30 committed by Preston
parent 3d29ce55a5
commit da327a36ce
1 changed files with 42 additions and 1 deletions

View File

@ -489,7 +489,11 @@ function importSubscriptions(){
});
return;
}
else if (fileType !== '.db'){
else if( (fileType === '.json') && (data.includes("app_version")) ) {
importNewpipeSubscriptions(data);
return;
}
else if ((fileType !== '.db') && (fileType !=='.json')) {
showToast('Incorrect file type. Import unsuccessful.');
return;
}
@ -506,7 +510,44 @@ function importSubscriptions(){
})
});
}
/**
* Import NewPipe Channel Subscriptions
* @return {Void}
*/
function importNewpipeSubscriptions(data){
progressView.seen = true;
progressView.width = 0;
showToast('Importing Newpipe Subscriptions, Please Wait.');
let newpipe, n, link, newpipesub, counter;
newpipe = JSON.parse(data);
counter = 0;
for (n in newpipe.subscriptions) {
link = newpipe.subscriptions[n].url.split("/");
invidiousAPI('channels', link[4], {}, (data)=> {
newpipesub = {
channelId: data.authorId,
channelName: data.author,
channelThumbnail: data.authorThumbnails[2].url
};
addSubscription(newpipesub, false);
counter++;
progressView.progressWidth = (counter / newpipe.subscriptions.length) * 100;
if ((counter + 1) == newpipe.subscriptions.length) {
showToast('Subscriptions have been imported!');
progressView.seen = false;
progressView.seen = 0;
return;
}
});
}
}
/**
* Export the susbcriptions database to a file.
*