implement chapters in media information object, fixes #196
parent
eee5917746
commit
a7fe2d4b66
@ -0,0 +1,131 @@ |
||||
/* |
||||
* Copyright (c) 2021 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
package com.arthenica.ffmpegkit; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
public class Chapter { |
||||
|
||||
/* KEYS */ |
||||
public static final String KEY_ID = "id"; |
||||
public static final String KEY_TIME_BASE = "time_base"; |
||||
public static final String KEY_START = "start"; |
||||
public static final String KEY_START_TIME = "start_time"; |
||||
public static final String KEY_END = "end"; |
||||
public static final String KEY_END_TIME = "end_time"; |
||||
public static final String KEY_TAGS = "tags"; |
||||
|
||||
private final JSONObject jsonObject; |
||||
|
||||
public Chapter(JSONObject jsonObject) { |
||||
this.jsonObject = jsonObject; |
||||
} |
||||
|
||||
public Long getId() { |
||||
return getNumberProperty(KEY_ID); |
||||
} |
||||
|
||||
public String getTimeBase() { |
||||
return getStringProperty(KEY_TIME_BASE); |
||||
} |
||||
|
||||
public Long getStart() { |
||||
return getNumberProperty(KEY_START); |
||||
} |
||||
|
||||
public String getStartTime() { |
||||
return getStringProperty(KEY_START_TIME); |
||||
} |
||||
|
||||
public Long getEnd() { |
||||
return getNumberProperty(KEY_END); |
||||
} |
||||
|
||||
public String getEndTime() { |
||||
return getStringProperty(KEY_END_TIME); |
||||
} |
||||
|
||||
public JSONObject getTags() { |
||||
return getProperties(KEY_TAGS); |
||||
} |
||||
|
||||
/** |
||||
* Returns the chapter property associated with the key. |
||||
* |
||||
* @param key property key |
||||
* @return chapter property as string or null if the key is not found |
||||
*/ |
||||
public String getStringProperty(final String key) { |
||||
JSONObject chapterProperties = getAllProperties(); |
||||
if (chapterProperties == null) { |
||||
return null; |
||||
} |
||||
|
||||
if (chapterProperties.has(key)) { |
||||
return chapterProperties.optString(key); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the chapter property associated with the key. |
||||
* |
||||
* @param key property key |
||||
* @return chapter property as Long or null if the key is not found |
||||
*/ |
||||
public Long getNumberProperty(String key) { |
||||
JSONObject chapterProperties = getAllProperties(); |
||||
if (chapterProperties == null) { |
||||
return null; |
||||
} |
||||
|
||||
if (chapterProperties.has(key)) { |
||||
return chapterProperties.optLong(key); |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the chapter properties associated with the key. |
||||
* |
||||
* @param key properties key |
||||
* @return chapter properties as a JSONObject or null if the key is not found |
||||
*/ |
||||
public JSONObject getProperties(String key) { |
||||
JSONObject chapterProperties = getAllProperties(); |
||||
if (chapterProperties == null) { |
||||
return null; |
||||
} |
||||
|
||||
return chapterProperties.optJSONObject(key); |
||||
} |
||||
|
||||
/** |
||||
* Returns all chapter properties defined. |
||||
* |
||||
* @return all chapter properties as a JSONObject or null if no properties are defined |
||||
*/ |
||||
public JSONObject getAllProperties() { |
||||
return jsonObject; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,84 @@ |
||||
/*
|
||||
* Copyright (c) 2021 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef FFMPEG_KIT_CHAPTER_H |
||||
#define FFMPEG_KIT_CHAPTER_H |
||||
|
||||
#import <Foundation/Foundation.h> |
||||
|
||||
extern NSString* const ChapterKeyId; |
||||
extern NSString* const ChapterKeyTimeBase; |
||||
extern NSString* const ChapterKeyStart; |
||||
extern NSString* const ChapterKeyStartTime; |
||||
extern NSString* const ChapterKeyEnd; |
||||
extern NSString* const ChapterKeyEndTime; |
||||
extern NSString* const ChapterKeyTags; |
||||
|
||||
/**
|
||||
* Chapter class. |
||||
*/ |
||||
@interface Chapter : NSObject |
||||
|
||||
- (instancetype)init:(NSDictionary*)chapterDictionary; |
||||
|
||||
- (NSNumber*)getId; |
||||
|
||||
- (NSString*)getTimeBase; |
||||
|
||||
- (NSNumber*)getStart; |
||||
|
||||
- (NSString*)getStartTime; |
||||
|
||||
- (NSNumber*)getEnd; |
||||
|
||||
- (NSString*)getEndTime; |
||||
|
||||
- (NSDictionary*)getTags; |
||||
|
||||
/**
|
||||
* Returns the chapter property associated with the key. |
||||
* |
||||
* @return chapter property as string or nil if the key is not found |
||||
*/ |
||||
- (NSString*)getStringProperty:(NSString*)key; |
||||
|
||||
/**
|
||||
* Returns the chapter property associated with the key. |
||||
* |
||||
* @return chapter property as number or nil if the key is not found |
||||
*/ |
||||
- (NSNumber*)getNumberProperty:(NSString*)key; |
||||
|
||||
/**
|
||||
* Returns the chapter properties associated with the key. |
||||
* |
||||
* @return chapter properties in a dictionary or nil if the key is not found |
||||
*/ |
||||
- (NSDictionary*)getProperties:(NSString*)key; |
||||
|
||||
/**
|
||||
* Returns all chapter properties defined. |
||||
* |
||||
* @return all chapter properties in a dictionary or nil if no properties are defined |
||||
*/ |
||||
- (NSDictionary*)getAllProperties; |
||||
|
||||
@end |
||||
|
||||
#endif // FFMPEG_KIT_CHAPTER_H
|
@ -0,0 +1,107 @@ |
||||
/* |
||||
* Copyright (c) 2021 Taner Sener |
||||
* |
||||
* This file is part of FFmpegKit. |
||||
* |
||||
* FFmpegKit is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Lesser General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* FFmpegKit is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Lesser General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Lesser General Public License |
||||
* along with FFmpegKit. If not, see <http://www.gnu.org/licenses/>. |
||||
*/ |
||||
|
||||
#import "Chapter.h" |
||||
|
||||
NSString* const ChapterKeyId = @"id"; |
||||
NSString* const ChapterKeyTimeBase = @"time_base"; |
||||
NSString* const ChapterKeyStart = @"start"; |
||||
NSString* const ChapterKeyStartTime = @"start_time"; |
||||
NSString* const ChapterKeyEnd = @"end"; |
||||
NSString* const ChapterKeyEndTime = @"end_time"; |
||||
NSString* const ChapterKeyTags = @"tags"; |
||||
|
||||
@implementation Chapter { |
||||
|
||||
/** |
||||
* Stores all properties. |
||||
*/ |
||||
NSDictionary *dictionary; |
||||
|
||||
} |
||||
|
||||
- (instancetype)init:(NSDictionary*)chapterDictionary { |
||||
self = [super init]; |
||||
if (self) { |
||||
dictionary = chapterDictionary; |
||||
} |
||||
|
||||
return self; |
||||
} |
||||
|
||||
- (NSNumber*)getId { |
||||
return [self getNumberProperty:ChapterKeyId]; |
||||
} |
||||
|
||||
- (NSString*)getTimeBase { |
||||
return [self getStringProperty:ChapterKeyTimeBase]; |
||||
} |
||||
|
||||
- (NSNumber*)getStart { |
||||
return [self getNumberProperty:ChapterKeyStart]; |
||||
} |
||||
|
||||
- (NSString*)getStartTime { |
||||
return [self getStringProperty:ChapterKeyStartTime]; |
||||
} |
||||
|
||||
- (NSNumber*)getEnd { |
||||
return [self getNumberProperty:ChapterKeyEnd]; |
||||
} |
||||
|
||||
- (NSString*)getEndTime { |
||||
return [self getStringProperty:ChapterKeyEndTime]; |
||||
} |
||||
|
||||
- (NSDictionary*)getTags { |
||||
return [self getProperties:ChapterKeyTags]; |
||||
} |
||||
|
||||
- (NSString*)getStringProperty:(NSString*)key { |
||||
NSDictionary* allProperties = [self getAllProperties]; |
||||
if (allProperties == nil) { |
||||
return nil; |
||||
} |
||||
|
||||
return allProperties[key]; |
||||
} |
||||
|
||||
- (NSNumber*)getNumberProperty:(NSString*)key { |
||||
NSDictionary* mediaProperties = [self getAllProperties]; |
||||
if (mediaProperties == nil) { |
||||
return nil; |
||||
} |
||||
|
||||
return mediaProperties[key]; |
||||
} |
||||
|
||||
- (NSDictionary*)getProperties:(NSString*)key { |
||||
NSDictionary* allProperties = [self getAllProperties]; |
||||
if (allProperties == nil) { |
||||
return nil; |
||||
} |
||||
|
||||
return allProperties[key]; |
||||
} |
||||
|
||||
- (NSDictionary*)getAllProperties { |
||||
return dictionary; |
||||
} |
||||
|
||||
@end |
Loading…
Reference in new issue