mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-04-08 19:56:44 +00:00
[#11930] Playlist with more than 50 items
This commit is contained in:
parent
acac50a1d1
commit
b1f995a78c
@ -255,6 +255,9 @@ dependencies {
|
||||
// HTTP client
|
||||
implementation "com.squareup.okhttp3:okhttp:4.12.0"
|
||||
|
||||
// Apache Commons Collections
|
||||
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
|
||||
|
||||
// Media player
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:${exoPlayerVersion}"
|
||||
implementation "com.google.android.exoplayer:exoplayer-dash:${exoPlayerVersion}"
|
||||
|
@ -31,6 +31,7 @@ import androidx.viewbinding.ViewBinding;
|
||||
|
||||
import com.evernote.android.state.State;
|
||||
|
||||
import org.apache.commons.collections4.queue.CircularFifoQueue;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.reactivestreams.Subscription;
|
||||
import org.schabi.newpipe.NewPipeDatabase;
|
||||
@ -460,10 +461,15 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
|
||||
|
||||
static String exportAsYoutubeTempPlaylist(final Stream<StreamEntity> entityStream) {
|
||||
|
||||
final String videoIDs = entityStream
|
||||
.map(entity -> getYouTubeId(entity.getUrl()))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(","));
|
||||
final CircularFifoQueue<String> last50 = new CircularFifoQueue<>(50);
|
||||
|
||||
entityStream
|
||||
.map(entity -> getYouTubeId(entity.getUrl()))
|
||||
.filter(Objects::nonNull)
|
||||
.forEachOrdered(last50::add);
|
||||
|
||||
final String videoIDs = last50.stream()
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
return "http://www.youtube.com/watch_videos?video_ids=" + videoIDs;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.junit.Test;
|
||||
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class LocalPlaylistFragmentTest {
|
||||
@ -30,6 +31,42 @@ public class LocalPlaylistFragmentTest {
|
||||
Assert.assertEquals("http://www.youtube.com/watch_videos?video_ids=1,2,3", url);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportMoreThan50Items() {
|
||||
/*
|
||||
* Playlist has more than 50 items => take the last 50
|
||||
* (YouTube limitation)
|
||||
*/
|
||||
|
||||
final List<Integer> ids = List.of(
|
||||
|
||||
-1, 0,
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
|
||||
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50
|
||||
);
|
||||
|
||||
final Stream<StreamEntity> entityStream = ids.stream()
|
||||
.map(id -> "https://www.youtube.com/watch?v=" + id)
|
||||
.map(LocalPlaylistFragmentTest::newStreamEntity);
|
||||
|
||||
final String url = LocalPlaylistFragment.export(YOUTUBE_TEMP_PLAYLIST, entityStream, null);
|
||||
|
||||
Assert.assertEquals(
|
||||
|
||||
"http://www.youtube.com/watch_videos?video_ids="
|
||||
+ "1,2,3,4,5,6,7,8,9,10,"
|
||||
+ "11,12,13,14,15,16,17,18,19,20,"
|
||||
+ "21,22,23,24,25,26,27,28,29,30,"
|
||||
+ "31,32,33,34,35,36,37,38,39,40,"
|
||||
+ "41,42,43,44,45,46,47,48,49,50",
|
||||
|
||||
url
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exportJustUrls() {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user