Skip to content

Instantly share code, notes, and snippets.

@hallahan

hallahan/gaiadl.js Secret

Created May 18, 2020
Embed
What would you like to do?
const fs = require('fs')
const axios = require('axios')
const headers = {
cookie: '<insert cookie contents from your request headers once loged into site here>'
}
const PHOTOS_URL = 'https://www.gaiagps.com/api/objects/photo/?count=50000&page=1&routepoints=false&show_archived=true&show_filed=true&sort_direction=desc&sort_field=create_date'
const TRACKS_URL = 'https://www.gaiagps.com/api/objects/track?count=50000&page=1&routepoints=false&show_archived=true&show_filed=true&sort_direction=desc&sort_field=create_date'
const photoQueue = []
const photoTs = new Set()
getPhotos()
function getPhotos() {
axios({
method: 'GET',
url: PHOTOS_URL,
headers
}).then(response => {
const photos = response.data
for (let photo of photos) {
const fileName = `${photo.time_created}_${photo.id}.jpg`
const photoUrl = `https://www.gaiagps.com/api/objects/photo/${photo.id}/image/full/`
// lots of duplicates
if (!photoTs.has(photo.time_created)) {
photoQueue.push({ fileName, photoUrl })
photoTs.add(photo.time_created)
}
}
dlPhotos()
}).catch(err => {
console.error([`photos err`, err])
})
}
function dlPhotos() {
if (photoQueue.length === 0) {
console.log('done dl photos')
return
}
const { fileName, photoUrl } = photoQueue.pop()
const path = `${__dirname}/photos/${fileName}`
if (fs.existsSync(path)) {
console.log(`Photo exists: ${path}`)
dlPhotos()
return
}
axios({
method: 'GET',
url: photoUrl,
headers,
responseType: 'stream'
}).then(r => {
r.data.pipe(fs.createWriteStream(path))
console.log(`Saving photo: ${path}`)
dlPhotos()
}).catch(err => {
console.error([`photo err`, err])
dlPhotos()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.