From 8bccb69e8d9ca8d602cc6bd11980fc1003751cac Mon Sep 17 00:00:00 2001 From: None <30817148+Xiefengshang@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:02:05 +0800 Subject: [PATCH] fix(google_photo): add support for streaming video, range requests (#5905) * Update util.go Return mediaMetadata * Update driver.go Using width and height --- drivers/google_photo/driver.go | 30 +++++++++++++++++++++++++++--- drivers/google_photo/util.go | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/google_photo/driver.go b/drivers/google_photo/driver.go index b54132ef9ed..85a0520b4a5 100644 --- a/drivers/google_photo/driver.go +++ b/drivers/google_photo/driver.go @@ -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 } diff --git a/drivers/google_photo/util.go b/drivers/google_photo/util.go index fbbff9ab1cb..0fd271b9bb4 100644 --- a/drivers/google_photo/util.go +++ b/drivers/google_photo/util.go @@ -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)