From ece284fbf868686bd2161de1205f02fb203097b0 Mon Sep 17 00:00:00 2001 From: Antoine Rousseau Date: Tue, 8 Oct 2019 21:48:21 +0200 Subject: [PATCH] video dl fallback --- google.js | 8 +++++--- start.js | 24 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/google.js b/google.js index 6086d93..3f2012d 100644 --- a/google.js +++ b/google.js @@ -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) }) diff --git a/start.js b/start.js index a8d1d17..d037806 100755 --- a/start.js +++ b/start.js @@ -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` @@ -163,10 +163,17 @@ 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 @@ -174,7 +181,16 @@ const main = async () => { // 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