Skip to content

Commit

Permalink
video dl fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerousseau committed Oct 8, 2019
1 parent 5724267 commit ece284f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 5 additions & 3 deletions google.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ module.exports = async () => {
return new Promise((resolve, reject) => {
request
.get(url)
// .on("response", (response) => {
// log("downloaded", response.statusCode, response.statusMessage, response.headers)
// })
.on("response", (response) => {
if (response.statusCode >= 400) {
reject(new HttpError(response.statusCode, response.statusMessage))
}
})
.on("error", (error) => {
reject(error)
})
Expand Down
24 changes: 20 additions & 4 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { ALBUMS_PATH } = require("./constants")
const { log, logError, readJson, writeJson, fileExists, mkdir } = require("./utils")

const media = process.env.MEDIA || "all" // "photos" or "videos"
const extras = "url_o,media,path_alias,original_format"
const extras = "url_o,media,path_alias,original_format,icon_server"
const per_page = 500 // max

const getAlbumPath = (id) => `${ALBUMS_PATH}/${id}.json`
Expand Down Expand Up @@ -163,18 +163,34 @@ const main = async () => {
let url
let ext = `.${item.originalformat}`
if (item.media === "video") {
url = `https://www.flickr.com/photos/${item.pathalias}/${item.id}/play/orig/${item.originalsecret}/`
if (item.originalformat === "jpg") {
// Flickr inconsistency
ext = ""
const nameparts = item.title.split(".")
if (nameparts.length === 2 && nameparts[1].length === 3) {
ext = `.${nameparts[1]}`
} else {
ext = ""
}
url = `https://live.staticflickr.com/video/${item.id}/${item.secret}/orig.mp4?s=eyJpIjoxNDQ3MTU5NzkzOSwiZSI6MTU3MDU2NTcyOCwicyI6IjQwODNiNWU0NDBhZDlkZjM1YTE0NDU1NDk0NWRkNTIyMTliYjJjNDIiLCJ2IjoxfQ`
} else {
url = `https://www.flickr.com/photos/${item.pathalias}/${item.id}/play/orig/${item.originalsecret}/`
}
} else {
url = item.url_o
}

// FOR EACH PHOTO, UPLOAD TO GOOGLE PHOTOS

const uploadToken = await stream(url, `flickr_${item.id}${ext}`)
let uploadToken
try {
uploadToken = await stream(url, `flickr_${item.id}${ext}`)
} catch (err1) {
logError("Could not download source file:", err1)
}

if (!uploadToken) {
continue
}

const mediaItem = {
// https://developers.google.com/photos/library/reference/rest/v1/mediaItems/batchCreate
Expand Down

0 comments on commit ece284f

Please sign in to comment.