Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit aed46e9

Browse files
committed
updates chapters in media information object, improves #196
1 parent dcabec5 commit aed46e9

File tree

4 files changed

+56
-33
lines changed

4 files changed

+56
-33
lines changed

flutter/flutter/lib/chapter.dart

+45-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2021 Taner Sener
2+
* Copyright (c) 2021 Taner Sener
33
*
44
* This file is part of FFmpegKit.
55
*
@@ -17,21 +17,51 @@
1717
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20+
/// Chapter class.
2021
class Chapter {
21-
int id;
22-
String timeBase;
23-
int start;
24-
int end;
25-
String startTime;
26-
String endTime;
27-
Tags tags;
28-
29-
Chapter(this.id, this.timeBase, this.start, this.end, this.startTime,
30-
this.endTime, this.tags);
31-
}
22+
static const keyId = "id";
23+
static const keyTimeBase = "time_base";
24+
static const keyStart = "start";
25+
static const keyStartTime = "start_time";
26+
static const keyEnd = "end";
27+
static const keyEndTime = "end_time";
28+
static const keyTags = "tags";
29+
30+
Map<dynamic, dynamic>? _allProperties;
31+
32+
/// Creates a new [Chapter] instance
33+
Chapter(this._allProperties);
34+
35+
/// Returns id.
36+
int? getId() => this.getNumberProperty(Chapter.keyId)?.toInt();
37+
38+
/// Returns time base.
39+
String? getTimeBase() => this.getStringProperty(Chapter.keyTimeBase);
40+
41+
/// Returns start.
42+
int? getStart() => this.getNumberProperty(Chapter.keyStart)?.toInt();
43+
44+
/// Returns start time.
45+
String? getStartTime() => this.getStringProperty(Chapter.keyStartTime);
46+
47+
/// Returns end.
48+
int? getEnd() => this.getNumberProperty(Chapter.keyEnd)?.toInt();
49+
50+
/// Returns end time.
51+
String? getEndTime() => this.getStringProperty(Chapter.keyEndTime);
52+
53+
/// Returns all tags.
54+
Map<dynamic, dynamic>? getTags() => this.getProperties(Chapter.keyTags);
55+
56+
/// Returns the chapter property associated with the key.
57+
String? getStringProperty(String key) => this._allProperties?[key];
58+
59+
/// Returns the chapter property associated with the key.
60+
num? getNumberProperty(String key) => this._allProperties?[key];
3261

33-
class Tags {
34-
String title;
62+
/// Returns the chapter properties associated with the key.
63+
dynamic getProperties(String key) => this._allProperties?[key];
3564

36-
Tags(this.title);
65+
/// Returns all properties found.
66+
Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
3767
}

flutter/flutter/lib/ffprobe_kit.dart

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class FFprobeKit {
7676
"json",
7777
"-show_format",
7878
"-show_streams",
79+
"-show_chapters",
7980
"-i",
8081
path
8182
];

flutter/flutter/lib/media_information.dart

+9-17
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,17 @@ class MediaInformation {
8888
return list;
8989
}
9090

91-
/// Returns all chapters
91+
/// Returns all chapters found as a list.
9292
List<Chapter> getChapters() {
9393
final List<Chapter> list = List<Chapter>.empty(growable: true);
94-
List<Chapter> chapters = List.empty(growable: true);
95-
if (_allProperties?["chapters"] != null) {
96-
chapters = <Chapter>[];
97-
_allProperties!['chapters'].forEach((dynamic chapter) {
98-
final int id = chapter['id'];
99-
final String timeBase = chapter['time_base'];
100-
final int start = chapter['start'];
101-
final int end = chapter['end'];
102-
final String startTime = chapter['start_time'];
103-
final String endTime = chapter['end_time'];
104-
final Tags tags = Tags(chapter['tags']['title'] ?? "");
105-
chapters.add(
106-
new Chapter(id, timeBase, start, end, startTime, endTime, tags));
107-
});
108-
}
109-
list.addAll(chapters);
94+
95+
dynamic createChapter(Map<dynamic, dynamic> chapterProperties) =>
96+
list.add(new Chapter(chapterProperties));
97+
98+
this._allProperties?["chapters"]?.forEach((Object? chapter) {
99+
createChapter(chapter as Map<dynamic, dynamic>);
100+
});
101+
110102
return list;
111103
}
112104

flutter/flutter/lib/stream_information.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ class StreamInformation {
119119
/// Returns the stream properties associated with the key.
120120
dynamic getProperties(String key) => this._allProperties?[key];
121121

122-
/// Returns all properties found.d
122+
/// Returns all properties found.
123123
Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
124124
}

0 commit comments

Comments
 (0)