From 596c3bcd088c8f5218cec3f8a6980137e5aa5195 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Mon, 21 Oct 2024 18:33:38 +0200 Subject: [PATCH] feat(lib): add missing video flags --- example/lib/main.dart | 2 +- lib/src/types/video.dart | 54 ++++++++++++++++++++++++++++++++++++-- lib/src/types/video.g.dart | 34 ++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 5f73b41..ec1bb2e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -102,7 +102,7 @@ class UploaderPageState extends State { setProgress(progress); }); log("VideoId : ${video.videoId}"); - log("Title : ${video.title}"); + log("Video : $video"); if (context.mounted) { showSuccessSnackBar( context, "Video ${video.videoId} uploaded"); diff --git a/lib/src/types/video.dart b/lib/src/types/video.dart index 533b5a3..cd9b65a 100644 --- a/lib/src/types/video.dart +++ b/lib/src/types/video.dart @@ -1,10 +1,39 @@ +import 'dart:ui'; + import 'package:json_annotation/json_annotation.dart'; + +import 'metadata.dart'; import 'video_assets.dart'; import 'video_source.dart'; -import 'metadata.dart'; part 'video.g.dart'; +/// The origin of the last update on the video's `language` attribute. +enum LanguageOrigin { + /// The language was set by the API. + @JsonValue("api") + api, + + /// The language was done automatically by the API. + @JsonValue("auto") + auto +} + +/// Json converter for [Locale] objects. +class _JsonLocaleConverter extends JsonConverter { + const _JsonLocaleConverter(); + + @override + Locale fromJson(String json) { + return Locale(json); + } + + @override + String toJson(Locale object) { + return object.toLanguageTag(); + } +} + /// A video from api.video @JsonSerializable() class Video { @@ -26,6 +55,22 @@ class Video { /// The date and time the video was updated. Date and time are provided using ISO-8601 UTC format. final DateTime? updatedAt; + /// The date and time the video was discarded. + final DateTime? discardedAt; + + /// The date and time the video will be permanently deleted. + final DateTime? deletesAt; + + /// Returns `true` for videos you discarded. + final bool? discarded; + + /// Returns the language of a video in [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) format. + @_JsonLocaleConverter() + final Locale? language; + + /// Returns the origin of the last update on the video's `language` attribute. + final LanguageOrigin? languageOrigin; + /// One array of tags (each tag is a string) in order to categorize a video. Tags may include spaces. final List? tags; @@ -52,12 +97,17 @@ class Video { final bool? mp4Support; /// Creates a [Video]. - Video(this.videoId, + const Video(this.videoId, {this.createdAt, this.title, this.description, this.publishedAt, this.updatedAt, + this.discardedAt, + this.deletesAt, + this.discarded, + this.language, + this.languageOrigin, this.tags, this.metadata, this.source, diff --git a/lib/src/types/video.g.dart b/lib/src/types/video.g.dart index 8724b5a..7ed1d64 100644 --- a/lib/src/types/video.g.dart +++ b/lib/src/types/video.g.dart @@ -17,6 +17,17 @@ Video _$VideoFromJson(Map json) => Video( updatedAt: json['updatedAt'] == null ? null : DateTime.parse(json['updatedAt'] as String), + discardedAt: json['discardedAt'] == null + ? null + : DateTime.parse(json['discardedAt'] as String), + deletesAt: json['deletesAt'] == null + ? null + : DateTime.parse(json['deletesAt'] as String), + discarded: json['discarded'] as bool?, + language: _$JsonConverterFromJson( + json['language'], const _JsonLocaleConverter().fromJson), + languageOrigin: + $enumDecodeNullable(_$LanguageOriginEnumMap, json['languageOrigin']), tags: (json['tags'] as List?)?.map((e) => e as String).toList(), metadata: (json['metadata'] as List?) ?.map((e) => Metadata.fromJson(e as Map)) @@ -40,6 +51,12 @@ Map _$VideoToJson(Video instance) => { 'description': instance.description, 'publishedAt': instance.publishedAt, 'updatedAt': instance.updatedAt?.toIso8601String(), + 'discardedAt': instance.discardedAt?.toIso8601String(), + 'deletesAt': instance.deletesAt?.toIso8601String(), + 'discarded': instance.discarded, + 'language': _$JsonConverterToJson( + instance.language, const _JsonLocaleConverter().toJson), + 'languageOrigin': _$LanguageOriginEnumMap[instance.languageOrigin], 'tags': instance.tags, 'metadata': instance.metadata, 'source': instance.source, @@ -49,3 +66,20 @@ Map _$VideoToJson(Video instance) => { 'panoramic': instance.panoramic, 'mp4Support': instance.mp4Support, }; + +Value? _$JsonConverterFromJson( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +const _$LanguageOriginEnumMap = { + LanguageOrigin.api: 'api', + LanguageOrigin.auto: 'auto', +}; + +Json? _$JsonConverterToJson( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value);