Skip to content

Commit

Permalink
fix(google_photo): add support for streaming video, range requests (#…
Browse files Browse the repository at this point in the history
…5905)

* Update util.go

Return mediaMetadata

* Update driver.go

Using width and height
  • Loading branch information
Xiefengshang authored Jan 19, 2024
1 parent 0f29a81 commit 8bccb69
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions drivers/google_photo/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,33 @@ func (d *GooglePhoto) Link(ctx context.Context, file model.Obj, args model.LinkA
URL: f.BaseURL + "=d",
}, nil
} else if strings.Contains(f.MimeType, "video/") {
return &model.Link{
URL: f.BaseURL + "=dv",
}, nil
var width, height int

fmt.Sscanf(f.MediaMetadata.Width, "%d", &width)
fmt.Sscanf(f.MediaMetadata.Height, "%d", &height)

switch {
// 1080P
case width == 1920 && height == 1080:
return &model.Link{
URL: f.BaseURL + "=m37",
}, nil
// 720P
case width == 1280 && height == 720:
return &model.Link{
URL: f.BaseURL + "=m22",
}, nil
// 360P
case width == 640 && height == 360:
return &model.Link{
URL: f.BaseURL + "=m18",
}, nil
default:
return &model.Link{
URL: f.BaseURL + "=dv",
}, nil
}

}
return &model.Link{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/google_photo/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (d *GooglePhoto) getMedia(id string) (MediaItem, error) {
var resp MediaItem

query := map[string]string{
"fields": "baseUrl,mimeType",
"fields": "mediaMetadata,baseUrl,mimeType",
}
_, err := d.request(fmt.Sprintf("https://photoslibrary.googleapis.com/v1/mediaItems/%s", id), http.MethodGet, func(req *resty.Request) {
req.SetQueryParams(query)
Expand Down

0 comments on commit 8bccb69

Please sign in to comment.