fromJsonVideoWithAuth static method

Future<VimeoVideo> fromJsonVideoWithAuth({
  1. required String videoId,
  2. required String accessKey,
  3. required Map<String, dynamic> json,
})

Implementation

static Future<VimeoVideo> fromJsonVideoWithAuth({
  required String videoId,
  required String accessKey,
  required Map<String, dynamic> json,
}) async {
  if (json.keys.contains("error")) {
    throw VimeoError.fromJsonAuth(json);
  }

  if (json['embed']?['badges']['live']['streaming'] ?? false) {
    Uri uri =
    Uri.parse("https://api.vimeo.com/me/videos/$videoId/m3u8_playback");
    var response =
    await http.get(uri, headers: {"Authorization": "Bearer $accessKey"});
    var body = jsonDecode(response.body);

    return VimeoVideo(
        width: json['width'],
        height: json['height'],
        liveEvent: true,
        sources: [
          _VimeoQualityFile(
            quality: _VimeoQualityFile.hls,
            file: VimeoSource(
              height: json['height'],
              width: json['width'],
              url: Uri.parse(body['m3u8_playback_url']),
            ),
          )
        ]);
  }

  var jsonFiles = (json['files']) as List<dynamic>;
  List<_VimeoQualityFile?> files = List<_VimeoQualityFile?>.from(
      jsonFiles.map<_VimeoQualityFile?>((element) {
        if (element['quality'] != null &&
            element['quality'] != _VimeoQualityFile.hls) {
          return _VimeoQualityFile(
            quality: element['quality'],
            file: VimeoSource(
              height: element['height'],
              width: element['width'],
              fps: element['fps'] is double
                  ? element['fps']
                  : (element['fps'] as int).toDouble(),
              url: Uri.tryParse(element['link'] as String)!,
            ),
          );
        }
        return null;
      })).toList();
  return VimeoVideo(
    liveEvent: json['embed']['badges']['live']['streaming'],
    width: json['width'],
    height: json['height'],
    sources: files,
  );
}