|
1 | 1 | package org.schabi.newpipe.local.playlist;
|
2 | 2 |
|
3 |
| -import static com.google.common.collect.Streams.stream; |
4 |
| -import static org.apache.commons.collections4.IterableUtils.reversedIterable; |
5 | 3 | import static org.schabi.newpipe.error.ErrorUtil.showUiErrorSnackbar;
|
6 | 4 | import static org.schabi.newpipe.ktx.ViewUtils.animate;
|
| 5 | +import static org.schabi.newpipe.local.playlist.ExportPlaylist.export; |
7 | 6 | import static org.schabi.newpipe.local.playlist.PlayListShareMode.JUST_URLS;
|
8 | 7 | import static org.schabi.newpipe.local.playlist.PlayListShareMode.WITH_TITLES;
|
9 | 8 | import static org.schabi.newpipe.local.playlist.PlayListShareMode.YOUTUBE_TEMP_PLAYLIST;
|
10 | 9 | import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout;
|
11 | 10 |
|
12 |
| -import static java.util.Collections.reverse; |
13 | 11 |
|
14 | 12 | import android.content.Context;
|
15 | 13 | import android.os.Bundle;
|
|
34 | 32 | import androidx.viewbinding.ViewBinding;
|
35 | 33 |
|
36 | 34 | import com.evernote.android.state.State;
|
37 |
| -import com.google.common.collect.Streams; |
38 |
| - |
39 |
| -import org.apache.commons.collections4.IterableUtils; |
40 |
| -import org.apache.commons.collections4.queue.CircularFifoQueue; |
41 | 35 | import org.reactivestreams.Subscriber;
|
42 | 36 | import org.reactivestreams.Subscription;
|
43 | 37 | import org.schabi.newpipe.NewPipeDatabase;
|
|
72 | 66 | import java.util.ArrayList;
|
73 | 67 | import java.util.Collections;
|
74 | 68 | import java.util.List;
|
75 |
| -import java.util.Objects; |
76 | 69 | import java.util.concurrent.atomic.AtomicBoolean;
|
77 | 70 | import java.util.stream.Collectors;
|
78 |
| -import java.util.stream.Stream; |
79 | 71 |
|
80 | 72 | import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
81 | 73 | import io.reactivex.rxjava3.core.Single;
|
82 | 74 | import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
83 | 75 | import io.reactivex.rxjava3.disposables.Disposable;
|
84 | 76 | import io.reactivex.rxjava3.schedulers.Schedulers;
|
85 |
| -import okhttp3.HttpUrl; |
86 | 77 |
|
87 | 78 | public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistStreamEntry>, Void>
|
88 | 79 | implements PlaylistControlViewHolder, DebounceSavable {
|
@@ -435,70 +426,6 @@ private void sharePlaylist(final PlayListShareMode shareMode) {
|
435 | 426 | );
|
436 | 427 | }
|
437 | 428 |
|
438 |
| - static String export(final PlayListShareMode shareMode, |
439 |
| - final List<PlaylistStreamEntry> playlist, |
440 |
| - final Context context) { |
441 |
| - |
442 |
| - return switch (shareMode) { |
443 |
| - |
444 |
| - case WITH_TITLES -> exportWithTitles(playlist, context); |
445 |
| - case JUST_URLS -> exportJustUrls(playlist); |
446 |
| - case YOUTUBE_TEMP_PLAYLIST -> exportAsYoutubeTempPlaylist(playlist); |
447 |
| - }; |
448 |
| - } |
449 |
| - |
450 |
| - static String exportWithTitles(final List<PlaylistStreamEntry> playlist, final Context context) { |
451 |
| - |
452 |
| - return playlist.stream() |
453 |
| - .map(PlaylistStreamEntry::getStreamEntity) |
454 |
| - .map(entity -> context.getString(R.string.video_details_list_item, |
455 |
| - entity.getTitle(), |
456 |
| - entity.getUrl() |
457 |
| - ) |
458 |
| - ) |
459 |
| - .collect(Collectors.joining("\n")); |
460 |
| - } |
461 |
| - |
462 |
| - static String exportJustUrls(final List<PlaylistStreamEntry> playlist) { |
463 |
| - |
464 |
| - return playlist.stream() |
465 |
| - .map(PlaylistStreamEntry::getStreamEntity) |
466 |
| - .map(StreamEntity::getUrl) |
467 |
| - .collect(Collectors.joining("\n")); |
468 |
| - } |
469 |
| - |
470 |
| - static String exportAsYoutubeTempPlaylist(final List<PlaylistStreamEntry> playlist) { |
471 |
| - |
472 |
| - final List<String> videoIDs = |
473 |
| - stream(reversedIterable(playlist)) |
474 |
| - .map(PlaylistStreamEntry::getStreamEntity) |
475 |
| - .map(entity -> getYouTubeId(entity.getUrl())) |
476 |
| - .filter(Objects::nonNull) |
477 |
| - .limit(50) |
478 |
| - .collect(Collectors.toList()); |
479 |
| - |
480 |
| - reverse(videoIDs); |
481 |
| - |
482 |
| - final String commaSeparatedVideoIDs = videoIDs.stream() |
483 |
| - .collect(Collectors.joining(",")); |
484 |
| - |
485 |
| - return "http://www.youtube.com/watch_videos?video_ids=" + commaSeparatedVideoIDs; |
486 |
| - } |
487 |
| - |
488 |
| - /** |
489 |
| - * Gets the video id from a YouTube URL. |
490 |
| - * |
491 |
| - * @param url YouTube URL |
492 |
| - * @return the video id |
493 |
| - */ |
494 |
| - static String getYouTubeId(final String url) { |
495 |
| - |
496 |
| - final HttpUrl httpUrl = HttpUrl.parse(url); |
497 |
| - |
498 |
| - return httpUrl == null ? null |
499 |
| - : httpUrl.queryParameter("v"); |
500 |
| - } |
501 |
| - |
502 | 429 | public void removeWatchedStreams(final boolean removePartiallyWatched) {
|
503 | 430 | if (isRewritingPlaylist) {
|
504 | 431 | return;
|
|
0 commit comments