getUser method

Future<JsonMap> getUser(
  1. String channelId
)

Retrieve a user's page. A user may own videos or playlists.

Use getUserPlaylists to retrieve all playlists:

final result = getUser(channelId);
getUserPlaylists(channelId, result['playlists']['params']);

Similarly, use getUserVideos to retrieve all videos:

getUserVideos(channelId, result['videos']['params']);
  • channelId channelId of the user.

Returns Map with information about a user.

Example:

{
  "name": "4Tune - No Copyright Music",
  "videos": {
    "browseId": "UC44hbeRoCZVVMVg5z0FfIww",
    "results": [
      {
        "title": "Epic Music Soundtracks 2019",
        "videoId": "bJonJjgS2mM",
        "playlistId": "RDAMVMbJonJjgS2mM",
        "thumbnails": [
          {
            "url": "https://i.ytimg.com/vi/bJon...",
            "width": 800,
            "height": 450
          }
        ],
        "views": "19K"
      }
    ]
  },
  "playlists": {
    "browseId": "UC44hbeRoCZVVMVg5z0FfIww",
    "results": [
      {
        "title": "♚ Machinimasound | Playlist",
        "playlistId": "PLRm766YvPiO9ZqkBuEzSTt6Bk4eWIr3gB",
        "thumbnails": [
          {
            "url": "https://i.ytimg.com/vi/...",
            "width": 400,
            "height": 225
          }
        ]
      }
    ],
    "params": "6gO3AUNvWU..."
  }
}

Implementation

Future<JsonMap> getUser(String channelId) async {
  const endpoint = 'browse';
  final body = <String, dynamic>{'browseId': channelId};
  final response = await sendRequest(endpoint, body);

  final user = {
    'name': nav(response, [...HEADER_MUSIC_VISUAL, ...TITLE_TEXT]),
  };
  final results = nav(response, [...SINGLE_COLUMN_TAB, ...SECTION_LIST]);
  user.addAll(
    parser.parseChannelContents(List<JsonMap>.from(results as List)),
  );
  return user;
}