2019-09-28 21:11:05 +00:00
|
|
|
package us.shandian.giga.get;
|
|
|
|
|
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2019-10-10 02:49:23 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2019-09-28 21:11:05 +00:00
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.Stream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
|
|
public class MissionRecoveryInfo implements Serializable, Parcelable {
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
|
2019-10-01 02:52:49 +00:00
|
|
|
MediaFormat format;
|
2019-09-28 21:11:05 +00:00
|
|
|
String desired;
|
|
|
|
boolean desired2;
|
|
|
|
int desiredBitrate;
|
2019-10-01 02:52:49 +00:00
|
|
|
byte kind;
|
|
|
|
String validateCondition = null;
|
2019-09-28 21:11:05 +00:00
|
|
|
|
|
|
|
public MissionRecoveryInfo(@NonNull Stream stream) {
|
|
|
|
if (stream instanceof AudioStream) {
|
|
|
|
desiredBitrate = ((AudioStream) stream).average_bitrate;
|
|
|
|
desired2 = false;
|
2019-10-01 02:52:49 +00:00
|
|
|
kind = 'a';
|
2019-09-28 21:11:05 +00:00
|
|
|
} else if (stream instanceof VideoStream) {
|
|
|
|
desired = ((VideoStream) stream).getResolution();
|
|
|
|
desired2 = ((VideoStream) stream).isVideoOnly();
|
2019-10-01 02:52:49 +00:00
|
|
|
kind = 'v';
|
2019-09-28 21:11:05 +00:00
|
|
|
} else if (stream instanceof SubtitlesStream) {
|
|
|
|
desired = ((SubtitlesStream) stream).getLanguageTag();
|
|
|
|
desired2 = ((SubtitlesStream) stream).isAutoGenerated();
|
2019-10-01 02:52:49 +00:00
|
|
|
kind = 's';
|
2019-09-28 21:11:05 +00:00
|
|
|
} else {
|
|
|
|
throw new RuntimeException("Unknown stream kind");
|
|
|
|
}
|
|
|
|
|
|
|
|
format = stream.getFormat();
|
|
|
|
if (format == null) throw new NullPointerException("Stream format cannot be null");
|
|
|
|
}
|
|
|
|
|
2019-10-01 02:52:49 +00:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
String info;
|
|
|
|
StringBuilder str = new StringBuilder();
|
2019-10-10 02:49:23 +00:00
|
|
|
str.append("{type=");
|
2019-10-01 02:52:49 +00:00
|
|
|
switch (kind) {
|
|
|
|
case 'a':
|
|
|
|
str.append("audio");
|
|
|
|
info = "bitrate=" + desiredBitrate;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
str.append("video");
|
|
|
|
info = "quality=" + desired + " videoOnly=" + desired2;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
str.append("subtitles");
|
|
|
|
info = "language=" + desired + " autoGenerated=" + desired2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info = "";
|
|
|
|
str.append("other");
|
|
|
|
}
|
|
|
|
|
|
|
|
str.append(" format=")
|
|
|
|
.append(format.getName())
|
|
|
|
.append(' ')
|
2019-10-10 02:49:23 +00:00
|
|
|
.append(info)
|
|
|
|
.append('}');
|
2019-10-01 02:52:49 +00:00
|
|
|
|
|
|
|
return str.toString();
|
|
|
|
}
|
|
|
|
|
2019-09-28 21:11:05 +00:00
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel parcel, int flags) {
|
|
|
|
parcel.writeInt(this.format.ordinal());
|
|
|
|
parcel.writeString(this.desired);
|
|
|
|
parcel.writeInt(this.desired2 ? 0x01 : 0x00);
|
|
|
|
parcel.writeInt(this.desiredBitrate);
|
2019-10-01 02:52:49 +00:00
|
|
|
parcel.writeByte(this.kind);
|
2019-09-28 21:11:05 +00:00
|
|
|
parcel.writeString(this.validateCondition);
|
|
|
|
}
|
|
|
|
|
|
|
|
private MissionRecoveryInfo(Parcel parcel) {
|
|
|
|
this.format = MediaFormat.values()[parcel.readInt()];
|
|
|
|
this.desired = parcel.readString();
|
|
|
|
this.desired2 = parcel.readInt() != 0x00;
|
|
|
|
this.desiredBitrate = parcel.readInt();
|
2019-10-01 02:52:49 +00:00
|
|
|
this.kind = parcel.readByte();
|
2019-09-28 21:11:05 +00:00
|
|
|
this.validateCondition = parcel.readString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final Parcelable.Creator<MissionRecoveryInfo> CREATOR = new Parcelable.Creator<MissionRecoveryInfo>() {
|
|
|
|
@Override
|
|
|
|
public MissionRecoveryInfo createFromParcel(Parcel source) {
|
|
|
|
return new MissionRecoveryInfo(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MissionRecoveryInfo[] newArray(int size) {
|
|
|
|
return new MissionRecoveryInfo[size];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|