NewPipeExtractor icon indicating copy to clipboard operation
NewPipeExtractor copied to clipboard

[YouTube] Improve lockup view model metadata extraction

Open Stypox opened this issue 5 months ago • 0 comments

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 https://github.com/TeamNewPipe/NewPipeExtractor/pull/1320#discussion_r2205778179

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"
        }
      }
    ]
  }
]

Stypox avatar Jul 15 '25 21:07 Stypox