Last active
August 4, 2021 03:08
-
-
Save J-Swift/297589de141ee5a7c139159428b9b8dc to your computer and use it in GitHub Desktop.
Download all photos from facebook album
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delay(delayInms) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(); | |
}, delayInms); | |
}); | |
} | |
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 waitFor(predicate) { | |
return new Promise(async (resolve, reject) => { | |
for (let i =0; i<10; i++) { | |
let result = predicate(); | |
if (result != null && result.length > 0) { | |
resolve(result); | |
return; | |
} | |
await delay(25*i+1); | |
} | |
reject("Max retries reached"); | |
}); | |
} | |
console.clear(); (async () => { | |
console.log('starting'); | |
let totalDLedAlready = 0; | |
let _urls = []; | |
// TODO(jpr): verify classes | |
let els = document.querySelectorAll('i.hu5pjgll.eb18blue') | |
try { | |
// TODO(jpr): verify page offset | |
for (let i =2 + totalDLedAlready; i < els.length; i++) { | |
let el = els[i]; | |
el.scrollIntoView(); | |
el.click(); | |
await delay(100); | |
let links = await waitFor(() => document.querySelectorAll('a[href*=scontent]')); | |
_urls.push(links[links.length-1].getAttribute('href')); | |
el.click(); | |
await delay(100); | |
} | |
console.log("SUCCESSFUL FINISHED"); | |
} catch (e) { | |
console.error("FAILED with "+ _urls.length +" urls read"); | |
} | |
let s = _urls.reduce((memo, it) => memo + "\n" + it, "") | |
save('urls.txt', s); | |
})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while read -r line; do | |
fn=$( echo "${line}" | grep -Eo "[^/]+\.jpg") | |
curl "${line}" > "${fn}" | |
done < <(cat urls_combined.txt | sed 's/&dl=1$//g') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment