updates chapters in media information object, improves #196
This commit is contained in:
parent
dcabec5f65
commit
aed46e9bd7
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2021 Taner Sener
|
||||
* Copyright (c) 2021 Taner Sener
|
||||
*
|
||||
* This file is part of FFmpegKit.
|
||||
*
|
||||
|
@ -17,21 +17,51 @@
|
|||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// Chapter class.
|
||||
class Chapter {
|
||||
int id;
|
||||
String timeBase;
|
||||
int start;
|
||||
int end;
|
||||
String startTime;
|
||||
String endTime;
|
||||
Tags tags;
|
||||
static const keyId = "id";
|
||||
static const keyTimeBase = "time_base";
|
||||
static const keyStart = "start";
|
||||
static const keyStartTime = "start_time";
|
||||
static const keyEnd = "end";
|
||||
static const keyEndTime = "end_time";
|
||||
static const keyTags = "tags";
|
||||
|
||||
Chapter(this.id, this.timeBase, this.start, this.end, this.startTime,
|
||||
this.endTime, this.tags);
|
||||
}
|
||||
|
||||
class Tags {
|
||||
String title;
|
||||
|
||||
Tags(this.title);
|
||||
Map<dynamic, dynamic>? _allProperties;
|
||||
|
||||
/// Creates a new [Chapter] instance
|
||||
Chapter(this._allProperties);
|
||||
|
||||
/// Returns id.
|
||||
int? getId() => this.getNumberProperty(Chapter.keyId)?.toInt();
|
||||
|
||||
/// Returns time base.
|
||||
String? getTimeBase() => this.getStringProperty(Chapter.keyTimeBase);
|
||||
|
||||
/// Returns start.
|
||||
int? getStart() => this.getNumberProperty(Chapter.keyStart)?.toInt();
|
||||
|
||||
/// Returns start time.
|
||||
String? getStartTime() => this.getStringProperty(Chapter.keyStartTime);
|
||||
|
||||
/// Returns end.
|
||||
int? getEnd() => this.getNumberProperty(Chapter.keyEnd)?.toInt();
|
||||
|
||||
/// Returns end time.
|
||||
String? getEndTime() => this.getStringProperty(Chapter.keyEndTime);
|
||||
|
||||
/// Returns all tags.
|
||||
Map<dynamic, dynamic>? getTags() => this.getProperties(Chapter.keyTags);
|
||||
|
||||
/// Returns the chapter property associated with the key.
|
||||
String? getStringProperty(String key) => this._allProperties?[key];
|
||||
|
||||
/// Returns the chapter property associated with the key.
|
||||
num? getNumberProperty(String key) => this._allProperties?[key];
|
||||
|
||||
/// Returns the chapter properties associated with the key.
|
||||
dynamic getProperties(String key) => this._allProperties?[key];
|
||||
|
||||
/// Returns all properties found.
|
||||
Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
|
||||
}
|
||||
|
|
|
@ -76,6 +76,7 @@ class FFprobeKit {
|
|||
"json",
|
||||
"-show_format",
|
||||
"-show_streams",
|
||||
"-show_chapters",
|
||||
"-i",
|
||||
path
|
||||
];
|
||||
|
|
|
@ -88,25 +88,17 @@ class MediaInformation {
|
|||
return list;
|
||||
}
|
||||
|
||||
/// Returns all chapters
|
||||
/// Returns all chapters found as a list.
|
||||
List<Chapter> getChapters() {
|
||||
final List<Chapter> list = List<Chapter>.empty(growable: true);
|
||||
List<Chapter> chapters = List.empty(growable: true);
|
||||
if (_allProperties?["chapters"] != null) {
|
||||
chapters = <Chapter>[];
|
||||
_allProperties!['chapters'].forEach((dynamic chapter) {
|
||||
final int id = chapter['id'];
|
||||
final String timeBase = chapter['time_base'];
|
||||
final int start = chapter['start'];
|
||||
final int end = chapter['end'];
|
||||
final String startTime = chapter['start_time'];
|
||||
final String endTime = chapter['end_time'];
|
||||
final Tags tags = Tags(chapter['tags']['title'] ?? "");
|
||||
chapters.add(
|
||||
new Chapter(id, timeBase, start, end, startTime, endTime, tags));
|
||||
});
|
||||
}
|
||||
list.addAll(chapters);
|
||||
|
||||
dynamic createChapter(Map<dynamic, dynamic> chapterProperties) =>
|
||||
list.add(new Chapter(chapterProperties));
|
||||
|
||||
this._allProperties?["chapters"]?.forEach((Object? chapter) {
|
||||
createChapter(chapter as Map<dynamic, dynamic>);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,6 @@ class StreamInformation {
|
|||
/// Returns the stream properties associated with the key.
|
||||
dynamic getProperties(String key) => this._allProperties?[key];
|
||||
|
||||
/// Returns all properties found.d
|
||||
/// Returns all properties found.
|
||||
Map<dynamic, dynamic>? getAllProperties() => this._allProperties;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user