mirror of
https://github.com/pikami/tiktok-dl.git
synced 2024-11-27 18:25:42 +00:00
Updated scraper.js
This commit is contained in:
parent
e9715c0d40
commit
7a25f521cb
48
scraper.js
48
scraper.js
@ -1,17 +1,15 @@
|
|||||||
optStrings = {
|
optStrings = {
|
||||||
selectors: {
|
selectors: {
|
||||||
feedLoading: 'div.tiktok-loading.feed-loading',
|
feedLoading: '.tiktok-ui-loading-container',
|
||||||
modalArrowRight: 'div.video-card-modal > div > img.arrow-right',
|
modalArrowRight: 'div > div.video-card-container > img.arrow-right',
|
||||||
modalClose: '.video-card-modal > div > div.close',
|
modalClose: 'div > div.video-card-container > img.control-icon.close',
|
||||||
modalPlayer: 'div > div > main > div.video-card-modal > div > div.video-card-big > div.video-card-container > div > div > video',
|
modalPlayer: 'div.video-card-container > div.video-card-browse > video',
|
||||||
modalShareInput: '.copy-link-container > input',
|
modalCaption: 'div.content-container > div.video-infos-container > h1',
|
||||||
modalCaption: 'div.video-card-big > div.content-container > div.video-meta-info > h1',
|
modalSoundLink: 'div.content-container > div.video-infos-container > h2.music-info > a',
|
||||||
modalSoundLink: 'div.content-container > div.video-meta-info > h2.music-info > a',
|
|
||||||
modalUploader: '.user-username',
|
modalUploader: '.user-username',
|
||||||
videoPlayer: 'div.video-card-container > div > div > video',
|
videoPlayer: 'div.video-card-container > div > video',
|
||||||
videoShareInput: 'div.content-container.border > div.copy-link-container > input',
|
videoCaption: 'div.content-container > div.video-infos-container > h1',
|
||||||
videoCaption: 'div.content-container.border > div.video-meta-info > h1',
|
videoSoundLink: 'div.content-container > div.video-infos-container > h2 > a',
|
||||||
videoSoundLink: 'div.content-container.border > div.video-meta-info > h2.music-info > a',
|
|
||||||
videoUploader: '.user-username',
|
videoUploader: '.user-username',
|
||||||
},
|
},
|
||||||
classes: {
|
classes: {
|
||||||
@ -41,7 +39,7 @@ currentState = {
|
|||||||
|
|
||||||
checkForErrors = function () {
|
checkForErrors = function () {
|
||||||
var titles = document.getElementsByClassName(optStrings.classes.titleMessage);
|
var titles = document.getElementsByClassName(optStrings.classes.titleMessage);
|
||||||
debugger;
|
//debugger;
|
||||||
if (titles && titles.length) {
|
if (titles && titles.length) {
|
||||||
var error = Array.from(titles).find(x => optStrings.tiktokMessages.includes(x.textContent)).textContent;
|
var error = Array.from(titles).find(x => optStrings.tiktokMessages.includes(x.textContent)).textContent;
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -74,7 +72,7 @@ buldVidUrlArray = function(finishCallback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var arrowRight = document.querySelectorAll(optStrings.selectors.modalArrowRight)[0];
|
var arrowRight = document.querySelectorAll(optStrings.selectors.modalArrowRight)[0];
|
||||||
if (arrowRight.classList.contains(optStrings.classes.modalCloseDisabled)) {
|
if (!arrowRight || arrowRight.classList.contains(optStrings.classes.modalCloseDisabled)) {
|
||||||
window.clearInterval(intervalID);
|
window.clearInterval(intervalID);
|
||||||
document.querySelector(optStrings.selectors.modalClose).click();
|
document.querySelector(optStrings.selectors.modalClose).click();
|
||||||
finishCallback(videoArray);
|
finishCallback(videoArray);
|
||||||
@ -87,12 +85,12 @@ buldVidUrlArray = function(finishCallback) {
|
|||||||
getCurrentModalVideo = function () {
|
getCurrentModalVideo = function () {
|
||||||
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
var modalPlayer = document.querySelector(optStrings.selectors.modalPlayer);
|
||||||
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
var vidUrl = modalPlayer.getAttribute(optStrings.attributes.src);
|
||||||
var shareLink = document.querySelector(optStrings.selectors.modalShareInput).value;
|
var shareLink = window.location.href;
|
||||||
var caption = document.querySelector(optStrings.selectors.modalCaption).textContent;
|
var caption = document.querySelector(optStrings.selectors.modalCaption).textContent;
|
||||||
var soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
var soundLink = document.querySelector(optStrings.selectors.modalSoundLink);
|
||||||
var uploader = document.querySelector(optStrings.selectors.modalUploader).textContent;
|
var uploader = document.querySelector(optStrings.selectors.modalUploader).textContent;
|
||||||
var soundHref = soundLink.getAttribute("href");
|
var soundHref = soundLink ? soundLink.getAttribute("href") : '';
|
||||||
var soundText = soundLink.text;
|
var soundText = soundLink ? soundLink.text : '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
@ -107,15 +105,16 @@ getCurrentModalVideo = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getCurrentVideo = function () {
|
getCurrentVideo = function () {
|
||||||
|
//debugger;
|
||||||
if (checkForErrors()) return;
|
if (checkForErrors()) return;
|
||||||
var player = document.querySelector(optStrings.selectors.videoPlayer);
|
var player = document.querySelector(optStrings.selectors.videoPlayer);
|
||||||
var vidUrl = player.getAttribute(optStrings.attributes.src);
|
var vidUrl = player.getAttribute(optStrings.attributes.src);
|
||||||
var shareLink = document.querySelector(optStrings.selectors.videoShareInput).value;
|
var shareLink = window.location.href;
|
||||||
var caption = document.querySelector(optStrings.selectors.videoCaption).textContent;
|
var caption = document.querySelector(optStrings.selectors.videoCaption).textContent;
|
||||||
var soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
var soundLink = document.querySelector(optStrings.selectors.videoSoundLink);
|
||||||
var uploader = document.querySelector(optStrings.selectors.videoUploader).textContent;
|
var uploader = document.querySelector(optStrings.selectors.videoUploader).textContent;
|
||||||
var soundHref = soundLink.getAttribute("href");
|
var soundHref = soundLink ? soundLink.getAttribute("href") : '';
|
||||||
var soundText = soundLink.text;
|
var soundText = soundLink ? soundLink.text : '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: vidUrl,
|
url: vidUrl,
|
||||||
@ -132,7 +131,9 @@ getCurrentVideo = function() {
|
|||||||
scrollBottom = () => window.scrollTo(0, document.body.scrollHeight);
|
scrollBottom = () => window.scrollTo(0, document.body.scrollHeight);
|
||||||
|
|
||||||
scrollWhileNew = function (finishCallback) {
|
scrollWhileNew = function (finishCallback) {
|
||||||
var state = { count: 0 };
|
var state = {
|
||||||
|
count: 0
|
||||||
|
};
|
||||||
var intervalID = window.setInterval(x => {
|
var intervalID = window.setInterval(x => {
|
||||||
scrollBottom();
|
scrollBottom();
|
||||||
var oldCount = state.count;
|
var oldCount = state.count;
|
||||||
@ -152,7 +153,7 @@ scrollWhileNew = function(finishCallback) {
|
|||||||
if (oldCount !== state.count) {
|
if (oldCount !== state.count) {
|
||||||
currentState.preloadCount = state.count;
|
currentState.preloadCount = state.count;
|
||||||
} else {
|
} else {
|
||||||
if (document.querySelector(optStrings.selectors.feedLoading)) {
|
if (isLoading()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.clearInterval(intervalID);
|
window.clearInterval(intervalID);
|
||||||
@ -161,6 +162,11 @@ scrollWhileNew = function(finishCallback) {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
isLoading = function () {
|
||||||
|
var loadingElement = document.querySelector(optStrings.selectors.feedLoading);
|
||||||
|
return loadingElement && loadingElement.getClientRects().length != 0;
|
||||||
|
}
|
||||||
|
|
||||||
bootstrapIteratingVideos = function (limit) {
|
bootstrapIteratingVideos = function (limit) {
|
||||||
currentState.limit = limit;
|
currentState.limit = limit;
|
||||||
scrollWhileNew(buldVidUrlArray);
|
scrollWhileNew(buldVidUrlArray);
|
||||||
|
Loading…
Reference in New Issue
Block a user