fix: extraction of metadata_parts in fundraiser videos (#6181)

Videos that have fundraiser in their data contain a `badges` element
with their badge data as the last item of the metadata_rows, `row.dig()`
tried to read `badges` but since it doensn't match `metadataParts` it
just fails.

using `dig?()` fixes it because it just skips `badges` as it should be.

This is how the structure of metadataRows looks like in a fundraiser
video

```
"metadataRows": [
  {
    "metadataParts": [
      {
        "text": {
          "content": "NPR Music",
          "commandRuns": [
            {
              "startIndex": 0,
              "length": 9,
              "onTap": {
                "innertubeCommand": {
                  "clickTrackingParams": "CI0IENTEDBgAIhMI_OOy14-nmAMVykO4BB0ZvzDGygEEcKuVmA==",
                  "commandMetadata": {
                    "webCommandMetadata": {
                      "url": "/@nprmusic",
                      "webPageType": "WEB_PAGE_TYPE_CHANNEL",
                      "rootVe": 3611,
                      "apiUrl": "/youtubei/v1/browse"
                    }
                  },
                  "browseEndpoint": {
                    "browseId": "UC4eYXhJI4-7wSWc8UNRwD4A",
                    "canonicalBaseUrl": "/@nprmusic"
                  }
                }
              }
            }
          ],
          "styleRuns": [
            {
              "startIndex": 0,
              "length": 9,
              "weightLabel": "FONT_WEIGHT_NORMAL"
            },
            {
              "startIndex": 9,
              "styleRunExtensions": {
                "styleRunColorMapExtension": {
                  "colorMap": [
                    {
                      "key": "USER_INTERFACE_THEME_LIGHT",
                      "value": 4284506208
                    },
                    {
                      "key": "USER_INTERFACE_THEME_DARK",
                      "value": 4289374890
                    }
                  ]
                }
              }
            }
          ],
          "attachmentRuns": [
            {
              "startIndex": 9,
              "length": 0,
              "element": {
                "type": {
                  "imageType": {
                    "image": {
                      "sources": [
                        {
                          "clientResource": {
                            "imageName": "CHECK_CIRCLE_FILLED"
                          },
                          "width": 14,
                          "height": 14
                        }
                      ]
                    }
                  }
                },
                "properties": {
                  "layoutProperties": {
                    "height": {
                      "value": 14,
                      "unit": "DIMENSION_UNIT_POINT"
                    },
                    "width": {
                      "value": 14,
                      "unit": "DIMENSION_UNIT_POINT"
                    },
                    "margin": {
                      "left": {
                        "value": 4,
                        "unit": "DIMENSION_UNIT_POINT"
                      }
                    }
                  }
                }
              },
              "alignment": "ALIGNMENT_VERTICAL_CENTER"
            }
          ]
        }
      }
    ]
  },
  {
    "metadataParts": [
      {
        "text": {
          "content": "521K views"
        }
      },
      {
        "text": {
          "content": "1 day ago"
        },
        "accessibilityLabel": "1 day ago"
      }
    ]
  },
  {
    "badges": [
      {
        "badgeViewModel": {
          "badgeText": "Fundraiser",
          "badgeStyle": "BADGE_COMMERCE",
          "trackingParams": "CI0IENTEDBgAIhMI_OOy14-nmAMVykO4BB0ZvzDG"
        }
      }
    ]
  }
],
```
This commit is contained in:
Fijxu
2026-11-27 00:36:19 -03:00
committed by GitHub
parent 8be586f386
commit d8c00579d0

View File

@@ -723,7 +723,7 @@ private module Parsers
next
end
metadata_parts = row.dig("metadataParts").try &.as_a
metadata_parts = row.dig?("metadataParts").try &.as_a
if view_count_text.nil?
view_count_text = metadata_parts.try &.find { |item| item["icon"]?.nil? && item.dig?("text", "content").try &.as_s.includes?("views") }