Skip to content

[YouTube] Improve lockup view model metadata extraction #1336

@Stypox

Description

@Stypox

The metadata in the lockup view model is distributed across 2/3 rows and possibly there are multiple items per row. As of #1320 the YouTubeStreamInfoItemLockupExtractor accesses specific rows and columns by index, expecting to always find the same piece of data (uploader name, view count, upload date) in the same place.

The following was originally posted by @Stypox in #1320 (comment)

Can we trust the indices to be stable? I guess we can't do much better anyway, so let's try like this for now. If it creates problems, we can always use other ways to detect the right metadata parts in the future, e.g.:

  • the uploader name object has "attachmentRuns" and "styleRuns" attached to it, which view count and upload date don't have
  • the view count contains the "views" string or the "watching" string (for lives)
  • the remaining item is the upload date
See here
[
  {
    "metadataParts": [
      {
        "text": {
          "content": "Justin Bieber",
          "styleRuns": [
            {
              "startIndex": 13,
              "styleRunExtensions": {
                "styleRunColorMapExtension": {
                  "colorMap": [
                    {
                      "key": "USER_INTERFACE_THEME_LIGHT",
                      "value": 4284506208
                    },
                    {
                      "key": "USER_INTERFACE_THEME_DARK",
                      "value": 4289374890
                    }
                  ]
                }
              }
            }
          ],
          "attachmentRuns": [
            {
              "startIndex": 13,
              "length": 0,
              "element": {
                "type": {
                  "imageType": {
                    "image": {
                      "sources": [
                        {
                          "clientResource": {
                            "imageName": "AUDIO_BADGE"
                          },
                          "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": "157M views"
        }
      },
      {
        "text": {
          "content": "5 years ago"
        }
      }
    ]
  },
  {
    "badges": [
      {
        "badgeViewModel": {
          "badgeText": "Free with ads",
          "badgeStyle": "BADGE_COMMERCE",
          "trackingParams": "COcBENTEDBgBIhMIs6r8_ZS9jgMVOxYGAB1LCied"
        }
      },
      {
        "badgeViewModel": {
          "badgeText": "T",
          "badgeStyle": "BADGE_DEFAULT",
          "trackingParams": "COcBENTEDBgBIhMIs6r8_ZS9jgMVOxYGAB1LCied"
        }
      }
    ]
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    codequalityImprovements to the codebase to improve the code qualityenhancementNew feature or requestgood first issueEasy/simple issues perfect for newcomers to get involved in the projectyoutubeservice, https://www.youtube.com/

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions