getByUsername static method

Future<ChannelPage> getByUsername(
  1. YoutubeHttpClient httpClient,
  2. String username
)

Implementation

static Future<ChannelPage> getByUsername(
  YoutubeHttpClient httpClient,
  String username,
) {
  var url = 'https://www.youtube.com/user/$username?hl=en';

  return retry(httpClient, () async {
    try {
      final raw = await httpClient.getString(url);
      final result = ChannelPage.parse(raw);

      if (!result.isOk) {
        throw TransientFailureException('Channel page is broken');
      }
      return result;
    } on FatalFailureException catch (e) {
      if (e.statusCode != 404) {
        rethrow;
      }
      url = 'https://www.youtube.com/c/$username?hl=en';
    }
    throw FatalFailureException('', 0);
  });
}