First, thanks for building this tool. I think many users would like to back up their Google Photos in original quality, and this might be the way to go.
I played a bit with gphotosdl and found that live photos that normally are downloaded as a zip archive from the web UI are incorrectly named to a picture file format like .jpg, .heic, etc. For example, photos.zip (containing img_123.jpg and img_123.mov) is named to img_123.JPG.
A possible solution is to first check if the file is a zip archive and then unzip it and serve the matching file.
|
func (g *Gphotos) getID(w http.ResponseWriter, r *http.Request) { |
|
photoID := r.PathValue("photoID") |
|
slog.Info("got photo request", "id", photoID) |
|
path, err := g.Download(photoID) |
|
if err != nil { |
|
slog.Error("Download image failed", "id", photoID, "err", err) |
|
var h httpError |
|
if errors.As(err, &h) { |
|
w.WriteHeader(int(h)) |
|
} else { |
|
w.WriteHeader(http.StatusInternalServerError) |
|
} |
|
return |
|
} |
|
slog.Info("Downloaded photo", "id", photoID, "path", path) |
|
|
|
// Remove the file after it has been served |
|
defer func() { |
|
err := os.Remove(path) |
|
if err == nil { |
|
slog.Debug("Removed downloaded photo", "id", photoID, "path", path) |
|
} else { |
|
slog.Error("Failed to remove download directory", "id", photoID, "path", path, "err", err) |
|
} |
|
}() |
|
|
|
http.ServeFile(w, r, path) |
First, thanks for building this tool. I think many users would like to back up their Google Photos in original quality, and this might be the way to go.
I played a bit with gphotosdl and found that live photos that normally are downloaded as a zip archive from the web UI are incorrectly named to a picture file format like
.jpg,.heic, etc. For example,photos.zip(containingimg_123.jpgandimg_123.mov) is named toimg_123.JPG.A possible solution is to first check if the file is a zip archive and then unzip it and serve the matching file.
gphotosdl/main.go
Lines 275 to 301 in 8d9e256