Files
PiliPlus/lib/models_new/sponsor_block/segment_item.dart
My-Responsitories 2be13e7283 refa: sb & feat: sb portVideo (WIP) (#1751)
* refa: sb

* feat: sb portVideo (WIP)

* fix: keep-alive

* revert: ua version

* fix

* tweak [skip ci]

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>

---------

Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
2025-11-19 09:30:04 +08:00

54 lines
1.4 KiB
Dart

import 'package:PiliPlus/models/common/sponsor_block/segment_type.dart';
class SegmentItemModel {
String? cid;
String category;
String? actionType;
List<int> segment;
String uuid;
num? videoDuration;
int votes;
SegmentItemModel({
this.cid,
required this.category,
this.actionType,
required this.segment,
required this.uuid,
this.videoDuration,
this.votes = 0,
});
factory SegmentItemModel.fromJson(Map<String, dynamic> json) =>
SegmentItemModel(
cid: json["cid"],
category: json["category"],
actionType: json["actionType"],
segment: (json["segment"] as List)
.map((e) => ((e as num) * 1000).round())
.toList(),
uuid: json["UUID"],
videoDuration: json["videoDuration"] == null
? null
: (json["videoDuration"] as num) * 1000,
votes: json["votes"],
);
factory SegmentItemModel.fromPgcJson(
Map<String, dynamic> json,
num? videoDuration,
) => SegmentItemModel(
category: switch (json['clipType']) {
'CLIP_TYPE_OP' => SegmentType.intro.name,
'CLIP_TYPE_ED' => SegmentType.outro.name,
_ => SegmentType.sponsor.name,
},
segment: [
((json['start'] as num) * 1000).round(),
((json['end'] as num) * 1000).round(),
],
uuid: '',
videoDuration: videoDuration,
);
}