From ff6009916b2476343e6219b8f01ce3f4d550ee88 Mon Sep 17 00:00:00 2001 From: Nulo Date: Thu, 23 Feb 2023 17:09:32 -0300 Subject: [PATCH] instagram: no crashear con posts sin captions --- instagram/instagram.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/instagram/instagram.go b/instagram/instagram.go index dd28eeb..bb29734 100644 --- a/instagram/instagram.go +++ b/instagram/instagram.go @@ -63,9 +63,13 @@ func (r *Instagram) lookup(urlSrc string) (lookupResponse, error) { if response.Data.ShortcodeMedia.Type != "GraphVideo" { return lookupResponse{}, errors.New("Esto no es un video.") } + var text string + if len(response.Data.ShortcodeMedia.EdgeMediaToCaption.Edges) > 0 { + text = response.Data.ShortcodeMedia.EdgeMediaToCaption.Edges[0].Node.Text + } return lookupResponse{ VideoUrl: response.Data.ShortcodeMedia.VideoUrl, Author: response.Data.ShortcodeMedia.Owner.Username, - Text: response.Data.ShortcodeMedia.EdgeMediaToCaption.Edges[0].Node.Text, + Text: text, }, nil }