Skip to content

Instantly share code, notes, and snippets.

@judge2020
Last active April 16, 2024 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judge2020/159d877f71ac028ca7e3af59d82ab9dd to your computer and use it in GitHub Desktop.
Save judge2020/159d877f71ac028ca7e3af59d82ab9dd to your computer and use it in GitHub Desktop.
Download TikTok Favorites

Setup

  1. Sign into https://tiktok.com and go to your profile
  2. Click favorites or likes
  3. scroll down till all your videos load
  4. paste the script in console and run it
  5. Script will download the file containing newline-delimited links
  6. download via yt-dlp like so:
yt-dlp -a faves_03.30.24.txt --download-archive done.txt --min-sleep-interval 1 --max-sleep-interval 2 --restrict-filenames --trim-filenames 160 --write-info-json

Second pass for the videos with unsupported characters in names:

yt-dlp -a faves_03.30.24.txt --download-archive done.txt --min-sleep-interval 1 --max-sleep-interval 2 --restrict-filenames --trim-filenames 160 --write-info-json -o "%(uploader_id)s %(id)s.%(ext)s"
let hrefs = [];
let selectr = '[data-e2e="favorites-item-list"]';
let fname = 'faves';
function save(filename, data) {
const blob = new Blob([data], {type: 'text/csv'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
}
function getCurrentDateFormatted() {
const today = new Date();
let month = (today.getMonth() + 1).toString();
let day = today.getDate().toString();
let year = today.getFullYear().toString().substr(-2);
month = month.length < 2 ? '0' + month : month;
day = day.length < 2 ? '0' + day : day;
return month + '.' + day + '.' + year;
}
const element = document.querySelector(selectr);
for(let i=0; i<element.children.length; i++) {
let aElement = element.children[i].getElementsByTagName('a')[0];
if(aElement) {
hrefs.push(aElement.getAttribute('href'));
}
}
console.log(hrefs); //This will print out the href values.
let hrefsString = hrefs.join('\n'); // Join the array elements into a newline delimited string
save(`${fname}_${getCurrentDateFormatted()}.txt`, hrefsString);
let hrefs = [];
let selectr = '[data-e2e="user-liked-item-list"]';
function save(filename, data) {
const blob = new Blob([data], {type: 'text/csv'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
}
function getCurrentDateFormatted() {
const today = new Date();
let month = (today.getMonth() + 1).toString();
let day = today.getDate().toString();
let year = today.getFullYear().toString().substr(-2);
month = month.length < 2 ? '0' + month : month;
day = day.length < 2 ? '0' + day : day;
return month + '.' + day + '.' + year;
}
const element = document.querySelector(selectr);
for(let i=0; i<element.children.length; i++) {
let aElement = element.children[i].getElementsByTagName('a')[0];
if(aElement) {
hrefs.push(aElement.getAttribute('href'));
}
}
console.log(hrefs); //This will print out the href values.
let hrefsString = hrefs.join('\n'); // Join the array elements into a newline delimited string
save(`${fname}_${getCurrentDateFormatted()}.txt`, hrefsString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment