2017-03-01 18:47:52 +01:00
|
|
|
package org.schabi.newpipe.extractor;
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/*
|
2017-03-01 18:47:52 +01:00
|
|
|
* Created by Adam Howard on 08/11/15.
|
|
|
|
*
|
|
|
|
* Copyright (c) Christian Schabesberger <chris.schabesberger@mailbox.org>
|
|
|
|
* and Adam Howard <achdisposable1@gmail.com> 2015
|
|
|
|
*
|
|
|
|
* MediaFormat.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-03-17 16:05:43 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/**
|
2017-11-11 01:21:43 +01:00
|
|
|
* Static data about various media formats support by NewPipe, eg mime type, extension
|
2017-06-29 20:12:55 +02:00
|
|
|
*/
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2022-03-19 00:02:57 +01:00
|
|
|
@SuppressWarnings("MethodParamPad") // we want the media format table below to be aligned
|
2017-03-01 18:47:52 +01:00
|
|
|
public enum MediaFormat {
|
2022-03-17 16:14:58 +01:00
|
|
|
// @formatter:off
|
2017-03-01 18:47:52 +01:00
|
|
|
//video and audio combined formats
|
2022-03-17 16:14:58 +01:00
|
|
|
// id name suffix mimeType
|
|
|
|
MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"),
|
|
|
|
v3GPP (0x10, "3GPP", "3gp", "video/3gpp"),
|
|
|
|
WEBM (0x20, "WebM", "webm", "video/webm"),
|
2017-03-01 18:47:52 +01:00
|
|
|
// audio formats
|
2022-03-17 16:14:58 +01:00
|
|
|
M4A (0x100, "m4a", "m4a", "audio/mp4"),
|
|
|
|
WEBMA (0x200, "WebM", "webm", "audio/webm"),
|
|
|
|
MP3 (0x300, "MP3", "mp3", "audio/mpeg"),
|
|
|
|
OPUS (0x400, "opus", "opus", "audio/opus"),
|
|
|
|
OGG (0x500, "ogg", "ogg", "audio/ogg"),
|
|
|
|
WEBMA_OPUS(0x200, "WebM Opus", "webm", "audio/webm"),
|
2018-09-24 21:04:22 +02:00
|
|
|
// subtitles formats
|
2022-03-17 16:14:58 +01:00
|
|
|
VTT (0x1000, "WebVTT", "vtt", "text/vtt"),
|
|
|
|
TTML (0x2000, "Timed Text Markup Language", "ttml", "application/ttml+xml"),
|
|
|
|
TRANSCRIPT1(0x3000, "TranScript v1", "srv1", "text/xml"),
|
|
|
|
TRANSCRIPT2(0x4000, "TranScript v2", "srv2", "text/xml"),
|
|
|
|
TRANSCRIPT3(0x5000, "TranScript v3", "srv3", "text/xml"),
|
|
|
|
SRT (0x6000, "SubRip file format", "srt", "text/srt");
|
|
|
|
// @formatter:on
|
2017-03-01 18:47:52 +01:00
|
|
|
|
|
|
|
public final int id;
|
|
|
|
public final String name;
|
|
|
|
public final String suffix;
|
|
|
|
public final String mimeType;
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
MediaFormat(final int id, final String name, final String suffix, final String mimeType) {
|
2017-03-01 18:47:52 +01:00
|
|
|
this.id = id;
|
|
|
|
this.name = name;
|
|
|
|
this.suffix = suffix;
|
|
|
|
this.mimeType = mimeType;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:05:43 +01:00
|
|
|
private static <T> T getById(final int id,
|
|
|
|
final Function<MediaFormat, T> field,
|
|
|
|
final T orElse) {
|
|
|
|
return Arrays.stream(MediaFormat.values())
|
|
|
|
.filter(mediaFormat -> mediaFormat.id == id)
|
|
|
|
.map(field)
|
|
|
|
.findFirst()
|
|
|
|
.orElse(orElse);
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/**
|
|
|
|
* Return the friendly name of the media format with the supplied id
|
|
|
|
*
|
2022-03-17 16:05:43 +01:00
|
|
|
* @param id the id of the media format. Currently an arbitrary, NewPipe-specific number.
|
2017-03-01 18:47:52 +01:00
|
|
|
* @return the friendly name of the MediaFormat associated with this ids,
|
2017-06-29 20:12:55 +02:00
|
|
|
* or an empty String if none match it.
|
|
|
|
*/
|
2022-03-17 16:05:43 +01:00
|
|
|
public static String getNameById(final int id) {
|
|
|
|
return getById(id, MediaFormat::getName, "");
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/**
|
|
|
|
* Return the file extension of the media format with the supplied id
|
|
|
|
*
|
2022-03-17 16:05:43 +01:00
|
|
|
* @param id the id of the media format. Currently an arbitrary, NewPipe-specific number.
|
2017-03-01 18:47:52 +01:00
|
|
|
* @return the file extension of the MediaFormat associated with this ids,
|
2017-06-29 20:12:55 +02:00
|
|
|
* or an empty String if none match it.
|
|
|
|
*/
|
2022-03-17 16:05:43 +01:00
|
|
|
public static String getSuffixById(final int id) {
|
|
|
|
return getById(id, MediaFormat::getSuffix, "");
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/**
|
|
|
|
* Return the MIME type of the media format with the supplied id
|
|
|
|
*
|
2022-03-17 16:05:43 +01:00
|
|
|
* @param id the id of the media format. Currently an arbitrary, NewPipe-specific number.
|
2017-03-01 18:47:52 +01:00
|
|
|
* @return the MIME type of the MediaFormat associated with this ids,
|
2017-06-29 20:12:55 +02:00
|
|
|
* or an empty String if none match it.
|
|
|
|
*/
|
2022-03-17 16:05:43 +01:00
|
|
|
public static String getMimeById(final int id) {
|
|
|
|
return getById(id, MediaFormat::getMimeType, null);
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-07-11 05:08:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the MediaFormat with the supplied mime type
|
|
|
|
*
|
|
|
|
* @return MediaFormat associated with this mime type,
|
|
|
|
* or null if none match it.
|
|
|
|
*/
|
2022-03-17 16:05:43 +01:00
|
|
|
public static MediaFormat getFromMimeType(final String mimeType) {
|
|
|
|
return Arrays.stream(MediaFormat.values())
|
|
|
|
.filter(mediaFormat -> mediaFormat.mimeType.equals(mimeType))
|
|
|
|
.findFirst()
|
|
|
|
.orElse(null);
|
2017-07-11 05:08:03 +02:00
|
|
|
}
|
2017-11-11 01:21:43 +01:00
|
|
|
|
|
|
|
/**
|
2020-02-10 09:50:19 +01:00
|
|
|
* Get the media format by its id.
|
2020-02-08 23:58:46 +01:00
|
|
|
*
|
2017-11-11 01:21:43 +01:00
|
|
|
* @param id the id
|
|
|
|
* @return the id of the media format or null.
|
|
|
|
*/
|
2022-03-17 16:05:43 +01:00
|
|
|
public static MediaFormat getFormatById(final int id) {
|
|
|
|
return getById(id, mediaFormat -> mediaFormat, null);
|
2017-11-11 01:21:43 +01:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:05:43 +01:00
|
|
|
public static MediaFormat getFromSuffix(final String suffix) {
|
|
|
|
return Arrays.stream(MediaFormat.values())
|
|
|
|
.filter(mediaFormat -> mediaFormat.suffix.equals(suffix))
|
|
|
|
.findFirst()
|
|
|
|
.orElse(null);
|
2018-10-11 21:10:22 +02:00
|
|
|
}
|
2020-02-08 23:58:46 +01:00
|
|
|
|
2017-11-11 01:21:43 +01:00
|
|
|
/**
|
|
|
|
* Get the name of the format
|
2020-02-08 23:58:46 +01:00
|
|
|
*
|
2017-11-11 01:21:43 +01:00
|
|
|
* @return the name of the format
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the filename extension
|
2020-02-08 23:58:46 +01:00
|
|
|
*
|
2017-11-11 01:21:43 +01:00
|
|
|
* @return the filename extension
|
|
|
|
*/
|
|
|
|
public String getSuffix() {
|
|
|
|
return suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mime type
|
2020-02-08 23:58:46 +01:00
|
|
|
*
|
2017-11-11 01:21:43 +01:00
|
|
|
* @return the mime type
|
|
|
|
*/
|
|
|
|
public String getMimeType() {
|
|
|
|
return mimeType;
|
|
|
|
}
|
2020-02-08 23:58:46 +01:00
|
|
|
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|