fromJsonVideoWithoutAuth static method

Future<VimeoVideo> fromJsonVideoWithoutAuth(
  1. Map<String, dynamic> json
)

Implementation

static Future<VimeoVideo> fromJsonVideoWithoutAuth(
    Map<String, dynamic> json) async {
  if (json.keys.contains("message")) {
    throw VimeoError.fromJsonNoneAuth(json);
  }
  late var files;
  bool isLive = json['video']['live_event'] != null;
  if (isLive) {
    var hls = json['request']['files']['hls'];
    var response = jsonDecode(
        (await http.get(Uri.parse(hls['cdns']['fastly_live']['json_url'])))
            .body);
    Uri url = Uri.parse(response['url'] as String);
    files = [
      _VimeoQualityFile(
          quality: 'hls',
          file: VimeoSource(
              height: json['video']['height'],
              width: json['video']['width'],
              fps: json['video']['fps'],
              url: url))
    ];
  } else {
    files = List<_VimeoQualityFile?>.from(json['request']['files']
    ['progressive']
        .map<_VimeoQualityFile?>((element) {
      return _VimeoQualityFile(
        quality: element['quality'],
        file: VimeoSource(
          width: element['width'],
          height: element['height'],
          fps: element['fps'] is double
              ? element['fps']
              : (element['fps'] as int).toDouble(),
          url: Uri.parse(element['url']),
        ),
      );
    })).toList();
  }
  return VimeoVideo(
      liveEvent: isLive,
      width: json['video']['width'],
      height: json['video']['height'],
      sources: files);
}