Merge branch 'master' into dev

This commit is contained in:
TobiGr 2026-01-11 22:53:11 +01:00
commit 4ed2b9748f
12 changed files with 126 additions and 30 deletions

View file

@ -1133,7 +1133,7 @@ public class DownloadDialog extends DialogFragment
}
DownloadManagerService.startMission(context, urls, storage, kind, threads,
currentInfo.getUrl(), psName, psArgs, nearLength, new ArrayList<>(recoveryInfo));
currentInfo, psName, psArgs, nearLength, new ArrayList<>(recoveryInfo));
Toast.makeText(context, getString(R.string.download_has_started),
Toast.LENGTH_SHORT).show();

View file

@ -1,6 +1,7 @@
package org.schabi.newpipe.local.bookmark;
import static org.schabi.newpipe.local.bookmark.MergedPlaylistManager.getMergedOrderedPlaylists;
import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;
import android.content.DialogInterface;
import android.os.Bundle;
@ -417,10 +418,11 @@ public final class BookmarkFragment extends BaseLocalListFragment<List<PlaylistL
}
private ItemTouchHelper.SimpleCallback getItemTouchCallback() {
// if adding grid layout, also include ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT
// with an `if (shouldUseGridLayout()) ...`
return new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
ItemTouchHelper.ACTION_STATE_IDLE) {
int directions = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
if (shouldUseGridLayout(requireContext())) {
directions |= ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
}
return new ItemTouchHelper.SimpleCallback(directions, ItemTouchHelper.ACTION_STATE_IDLE) {
@Override
public int interpolateOutOfBoundsScroll(@NonNull final RecyclerView recyclerView,
final int viewSize,

View file

@ -22,7 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
import io.reactivex.rxjava3.subjects.PublishSubject;
/**
* PlayQueue is responsible for keeping track of a list of streams and the index of
@ -45,7 +45,7 @@ public abstract class PlayQueue implements Serializable {
private List<PlayQueueItem> backup;
private List<PlayQueueItem> streams;
private transient BehaviorSubject<PlayQueueEvent> eventBroadcast;
private transient PublishSubject<PlayQueueEvent> eventBroadcast;
private transient Flowable<PlayQueueEvent> broadcastReceiver;
private transient boolean disposed = false;
@ -70,7 +70,7 @@ public abstract class PlayQueue implements Serializable {
* </p>
*/
public void init() {
eventBroadcast = BehaviorSubject.create();
eventBroadcast = PublishSubject.create();
broadcastReceiver = eventBroadcast.toFlowable(BackpressureStrategy.BUFFER)
.observeOn(AndroidSchedulers.mainThread())

View file

@ -1,8 +1,14 @@
package org.schabi.newpipe.streams;
import static org.schabi.newpipe.MainActivity.DEBUG;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.streams.WebMReader.Cluster;
import org.schabi.newpipe.streams.WebMReader.Segment;
import org.schabi.newpipe.streams.WebMReader.SimpleBlock;
@ -13,6 +19,10 @@ import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author kapodamy
@ -52,8 +62,10 @@ public class OggFromWebMWriter implements Closeable {
private long segmentTableNextTimestamp = TIME_SCALE_NS;
private final int[] crc32Table = new int[256];
private final StreamInfo streamInfo;
public OggFromWebMWriter(@NonNull final SharpStream source, @NonNull final SharpStream target) {
public OggFromWebMWriter(@NonNull final SharpStream source, @NonNull final SharpStream target,
@Nullable final StreamInfo streamInfo) {
if (!source.canRead() || !source.canRewind()) {
throw new IllegalArgumentException("source stream must be readable and allows seeking");
}
@ -63,6 +75,7 @@ public class OggFromWebMWriter implements Closeable {
this.source = source;
this.output = target;
this.streamInfo = streamInfo;
this.streamId = (int) System.currentTimeMillis();
@ -271,12 +284,31 @@ public class OggFromWebMWriter implements Closeable {
@Nullable
private byte[] makeMetadata() {
if (DEBUG) {
Log.d("OggFromWebMWriter", "Downloading media with codec ID " + webmTrack.codecId);
}
if ("A_OPUS".equals(webmTrack.codecId)) {
return new byte[]{
0x4F, 0x70, 0x75, 0x73, 0x54, 0x61, 0x67, 0x73, // "OpusTags" binary string
0x00, 0x00, 0x00, 0x00, // writing application string size (not present)
0x00, 0x00, 0x00, 0x00 // additional tags count (zero means no tags)
};
final var metadata = new ArrayList<Pair<String, String>>();
if (streamInfo != null) {
metadata.add(Pair.create("COMMENT", streamInfo.getUrl()));
metadata.add(Pair.create("GENRE", streamInfo.getCategory()));
metadata.add(Pair.create("ARTIST", streamInfo.getUploaderName()));
metadata.add(Pair.create("TITLE", streamInfo.getName()));
metadata.add(Pair.create("DATE", streamInfo
.getUploadDate()
.getLocalDateTime()
.format(DateTimeFormatter.ISO_DATE)));
}
if (DEBUG) {
Log.d("OggFromWebMWriter", "Creating metadata header with this data:");
metadata.forEach(p -> {
Log.d("OggFromWebMWriter", p.first + "=" + p.second);
});
}
return makeOpusTagsHeader(metadata);
} else if ("A_VORBIS".equals(webmTrack.codecId)) {
return new byte[]{
0x03, // ¿¿¿???
@ -290,6 +322,59 @@ public class OggFromWebMWriter implements Closeable {
return null;
}
/**
* This creates a single metadata tag for use in opus metadata headers. It contains the four
* byte string length field and includes the string as-is. This cannot be used independently,
* but must follow a proper "OpusTags" header.
*
* @param pair A key-value pair in the format "KEY=some value"
* @return The binary data of the encoded metadata tag
*/
private static byte[] makeOpusMetadataTag(final Pair<String, String> pair) {
final var keyValue = pair.first.toUpperCase() + "=" + pair.second.trim();
final var bytes = keyValue.getBytes();
final var buf = ByteBuffer.allocate(4 + bytes.length);
buf.order(ByteOrder.LITTLE_ENDIAN);
buf.putInt(bytes.length);
buf.put(bytes);
return buf.array();
}
/**
* This returns a complete "OpusTags" header, created from the provided metadata tags.
* <p>
* You probably want to use makeOpusMetadata(), which uses this function to create
* a header with sensible metadata filled in.
*
* @param keyValueLines A list of pairs of the tags. This can also be though of as a mapping
* from one key to multiple values.
* @return The binary header
*/
private static byte[] makeOpusTagsHeader(final List<Pair<String, String>> keyValueLines) {
final var tags = keyValueLines
.stream()
.filter(p -> !p.second.isBlank())
.map(OggFromWebMWriter::makeOpusMetadataTag)
.collect(Collectors.toUnmodifiableList());
final var tagsBytes = tags.stream().collect(Collectors.summingInt(arr -> arr.length));
// Fixed header fields + dynamic fields
final var byteCount = 16 + tagsBytes;
final var head = ByteBuffer.allocate(byteCount);
head.order(ByteOrder.LITTLE_ENDIAN);
head.put(new byte[]{
0x4F, 0x70, 0x75, 0x73, 0x54, 0x61, 0x67, 0x73, // "OpusTags" binary string
0x00, 0x00, 0x00, 0x00, // vendor (aka. Encoder) string of length 0
});
head.putInt(tags.size()); // 4 bytes for tag count
tags.forEach(head::put); // dynamic amount of tag bytes
return head.array();
}
private void write(final ByteBuffer buffer) throws IOException {
output.write(buffer.array(), 0, buffer.position());
buffer.position(0);

View file

@ -806,7 +806,7 @@ public final class ListHelper {
final Locale preferredLanguage = Localization.getPreferredLocale(context);
final boolean preferOriginalAudio =
preferences.getBoolean(context.getString(R.string.prefer_original_audio_key),
false);
true);
final boolean preferDescriptiveAudio =
preferences.getBoolean(context.getString(R.string.prefer_descriptive_audio_key),
false);