2018-04-21 23:10:01 +02:00
|
|
|
package org.schabi.newpipe.player.playqueue;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2019-10-04 14:59:08 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2023-05-01 23:11:48 +02:00
|
|
|
import org.schabi.newpipe.extractor.Image;
|
2017-09-04 19:23:56 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2018-01-22 04:32:49 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
2017-09-04 19:23:56 +02:00
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
import java.io.Serializable;
|
2023-05-01 23:11:48 +02:00
|
|
|
import java.util.List;
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.core.Single;
|
|
|
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
public class PlayQueueItem implements Serializable {
|
2020-03-31 19:20:15 +02:00
|
|
|
public static final long RECOVERY_UNSET = Long.MIN_VALUE;
|
|
|
|
private static final String EMPTY_STRING = "";
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
@NonNull
|
|
|
|
private final String title;
|
|
|
|
@NonNull
|
|
|
|
private final String url;
|
|
|
|
private final int serviceId;
|
|
|
|
private final long duration;
|
|
|
|
@NonNull
|
2023-05-01 23:11:48 +02:00
|
|
|
private final List<Image> thumbnails;
|
2020-03-31 19:20:15 +02:00
|
|
|
@NonNull
|
|
|
|
private final String uploader;
|
2021-08-16 02:08:50 +02:00
|
|
|
private final String uploaderUrl;
|
2020-03-31 19:20:15 +02:00
|
|
|
@NonNull
|
|
|
|
private final StreamType streamType;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2018-11-11 11:54:49 +01:00
|
|
|
private boolean isAutoQueued;
|
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
private long recoveryPosition;
|
2017-08-29 02:38:37 +02:00
|
|
|
private Throwable error;
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
PlayQueueItem(@NonNull final StreamInfo info) {
|
2018-01-22 04:32:49 +01:00
|
|
|
this(info.getName(), info.getUrl(), info.getServiceId(), info.getDuration(),
|
2023-05-01 23:11:48 +02:00
|
|
|
info.getThumbnails(), info.getUploaderName(),
|
2021-08-16 02:08:50 +02:00
|
|
|
info.getUploaderUrl(), info.getStreamType());
|
2018-04-06 05:47:20 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (info.getStartPosition() > 0) {
|
2018-04-06 05:47:20 +02:00
|
|
|
setRecoveryPosition(info.getStartPosition() * 1000);
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2017-10-22 21:43:49 +02:00
|
|
|
}
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
PlayQueueItem(@NonNull final StreamInfoItem item) {
|
2018-01-22 04:32:49 +01:00
|
|
|
this(item.getName(), item.getUrl(), item.getServiceId(), item.getDuration(),
|
2023-05-01 23:11:48 +02:00
|
|
|
item.getThumbnails(), item.getUploaderName(),
|
2021-08-16 02:08:50 +02:00
|
|
|
item.getUploaderUrl(), item.getStreamType());
|
2017-09-05 21:27:12 +02:00
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2022-03-18 23:57:11 +01:00
|
|
|
@SuppressWarnings("ParameterNumber")
|
2018-03-18 00:04:02 +01:00
|
|
|
private PlayQueueItem(@Nullable final String name, @Nullable final String url,
|
|
|
|
final int serviceId, final long duration,
|
2023-05-01 23:11:48 +02:00
|
|
|
final List<Image> thumbnails, @Nullable final String uploader,
|
2021-08-16 02:08:50 +02:00
|
|
|
final String uploaderUrl, @NonNull final StreamType streamType) {
|
2018-03-18 00:04:02 +01:00
|
|
|
this.title = name != null ? name : EMPTY_STRING;
|
|
|
|
this.url = url != null ? url : EMPTY_STRING;
|
2017-10-22 21:43:49 +02:00
|
|
|
this.serviceId = serviceId;
|
|
|
|
this.duration = duration;
|
2023-05-01 23:11:48 +02:00
|
|
|
this.thumbnails = thumbnails;
|
2018-03-18 00:04:02 +01:00
|
|
|
this.uploader = uploader != null ? uploader : EMPTY_STRING;
|
2021-08-16 02:08:50 +02:00
|
|
|
this.uploaderUrl = uploaderUrl;
|
2018-01-22 04:32:49 +01:00
|
|
|
this.streamType = streamType;
|
2017-10-22 21:43:49 +02:00
|
|
|
|
2017-10-23 03:58:01 +02:00
|
|
|
this.recoveryPosition = RECOVERY_UNSET;
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getServiceId() {
|
|
|
|
return serviceId;
|
|
|
|
}
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
public long getDuration() {
|
2017-08-29 02:38:37 +02:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2017-10-23 03:58:01 +02:00
|
|
|
@NonNull
|
2023-05-01 23:11:48 +02:00
|
|
|
public List<Image> getThumbnails() {
|
|
|
|
return thumbnails;
|
2017-10-03 08:38:46 +02:00
|
|
|
}
|
|
|
|
|
2017-10-23 03:58:01 +02:00
|
|
|
@NonNull
|
2017-10-03 08:38:46 +02:00
|
|
|
public String getUploader() {
|
|
|
|
return uploader;
|
|
|
|
}
|
|
|
|
|
2021-08-16 02:08:50 +02:00
|
|
|
public String getUploaderUrl() {
|
|
|
|
return uploaderUrl;
|
|
|
|
}
|
|
|
|
|
2018-03-18 00:04:02 +01:00
|
|
|
@NonNull
|
2018-01-22 04:32:49 +01:00
|
|
|
public StreamType getStreamType() {
|
|
|
|
return streamType;
|
|
|
|
}
|
|
|
|
|
2017-10-23 03:58:01 +02:00
|
|
|
public long getRecoveryPosition() {
|
|
|
|
return recoveryPosition;
|
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
/*package-private*/ void setRecoveryPosition(final long recoveryPosition) {
|
|
|
|
this.recoveryPosition = recoveryPosition;
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:38:37 +02:00
|
|
|
@Nullable
|
|
|
|
public Throwable getError() {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 19:23:56 +02:00
|
|
|
public Single<StreamInfo> getStream() {
|
2018-04-06 05:47:20 +02:00
|
|
|
return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false)
|
2017-08-29 02:38:37 +02:00
|
|
|
.subscribeOn(Schedulers.io())
|
2018-02-17 20:55:45 +01:00
|
|
|
.doOnError(throwable -> error = throwable);
|
2017-09-03 04:30:34 +02:00
|
|
|
}
|
2017-10-22 21:43:49 +02:00
|
|
|
|
2018-11-11 11:54:49 +01:00
|
|
|
public boolean isAutoQueued() {
|
|
|
|
return isAutoQueued;
|
|
|
|
}
|
|
|
|
|
2017-10-22 21:43:49 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2017-10-23 03:58:01 +02:00
|
|
|
// Item States, keep external access out
|
2017-10-22 21:43:49 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public void setAutoQueued(final boolean autoQueued) {
|
|
|
|
isAutoQueued = autoQueued;
|
2017-10-22 21:43:49 +02:00
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|