Skip to content

Commit 5f1985f

Browse files
committed
Prefer Instagram display names in video titles
1 parent fcfcf4a commit 5f1985f

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

internal/brightdata/instagram.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ func instagramVideoTitle(record map[string]any) string {
412412
if len(entries) != 1 || !entries[0].isVideo() {
413413
return ""
414414
}
415+
// The posts dataset's accessibility text starts with the display-name
416+
// title Instagram itself exposes ("Video by Anna Codes on August 19, ...").
417+
// Keep only that title prefix; the rest is an accessibility description,
418+
// not part of the title.
419+
if alt := strings.TrimSpace(stringField(record, "alt_text")); strings.HasPrefix(alt, "Video by ") {
420+
if end := strings.Index(alt, " on "); end > len("Video by ") {
421+
return alt[:end]
422+
}
423+
}
415424
author := stringField(record, "user_posted", "username", "owner_username")
416425
if author == "" {
417426
return ""

internal/brightdata/instagram_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func TestInstagramGalleryFallbackRecordsVideoIntrinsics(t *testing.T) {
177177
"url": targetURL,
178178
"content_type": "Reel",
179179
"user_posted": "anna.codes.stuff",
180+
"alt_text": "Video by Anna Codes on August 19, 2026. May be an image of text.",
180181
"description": "A fixture caption",
181182
"likes": float64(177),
182183
"num_comments": float64(5),
@@ -213,7 +214,7 @@ func TestInstagramGalleryFallbackRecordsVideoIntrinsics(t *testing.T) {
213214
if meta.Likes == nil || *meta.Likes != 177 || meta.Comments == nil || *meta.Comments != 5 {
214215
t.Errorf("engagement = likes %v, comments %v; want 177/5", meta.Likes, meta.Comments)
215216
}
216-
if meta.Title != "Video by anna.codes.stuff" {
217+
if meta.Title != "Video by Anna Codes" {
217218
t.Errorf("title = %q; want a stable single-video title", meta.Title)
218219
}
219220
}

0 commit comments

Comments
 (0)