get static method

Future<WatchPage> get(
  1. YoutubeHttpClient httpClient,
  2. String videoId
)

Implementation

static Future<WatchPage> get(YoutubeHttpClient httpClient, String videoId) {
  final url = Uri.parse(
    'https://youtube.com/watch?v=$videoId&bpctr=9999999999&hl=en',
  );
  return retry(httpClient, () async {
    final req = await httpClient.get(url, validate: true);

    final cookies = req.headers['set-cookie']!;
    final visitorInfoLive = _visitorInfoLiveExp.firstMatch(cookies)?.group(1);
    final ysc = _yscExp.firstMatch(cookies)!.group(1)!;
    final result = WatchPage.parse(req.body, visitorInfoLive ?? '', ysc);

    if (!result.isOk) {
      throw TransientFailureException('Video watch page is broken.');
    }

    if (!result.isVideoAvailable) {
      throw VideoUnavailableException.unavailable(VideoId(videoId));
    }
    return result;
  });
}