Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live photos are downloaded with the wrong extension #1

Open
dvdkruk opened this issue Nov 13, 2024 · 0 comments
Open

Live photos are downloaded with the wrong extension #1

dvdkruk opened this issue Nov 13, 2024 · 0 comments

Comments

@dvdkruk
Copy link

dvdkruk commented Nov 13, 2024

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.

gphotosdl/main.go

Lines 275 to 301 in 8d9e256

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant