Skip to content

Commit

Permalink
Add download option to long-press menu
Browse files Browse the repository at this point in the history
  • Loading branch information
notaLonelyDay committed May 13, 2022
1 parent 2dd4f8b commit caf0eef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ public Builder addDefaultBeginningEntries() {
*/
public Builder addDefaultEndEntries() {
addAllEntries(
StreamDialogDefaultEntry.DOWNLOAD,
StreamDialogDefaultEntry.APPEND_PLAYLIST,
StreamDialogDefaultEntry.SHARE,
StreamDialogDefaultEntry.OPEN_IN_BROWSER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,22 @@

import org.schabi.newpipe.R;
import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
import org.schabi.newpipe.local.dialog.PlaylistDialog;
import org.schabi.newpipe.local.history.HistoryRecordManager;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;

import java.util.ArrayList;
import java.util.Collections;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* <p>
Expand Down Expand Up @@ -110,6 +116,35 @@ public enum StreamDialogDefaultEntry {
ShareUtils.shareText(fragment.requireContext(), item.getName(), item.getUrl(),
item.getThumbnailUrl())),

DOWNLOAD(R.string.download, (fragment, item) -> ExtractorHelper.getStreamInfo(
item.getServiceId(),
item.getUrl(),
false
)
.subscribeOn(Schedulers.io())
.subscribe((info) -> {
final ArrayList<VideoStream> sortedVideoStreamsList = new ArrayList<>(
ListHelper.getSortedStreamVideosList(fragment.requireContext(),
info.getVideoStreams(), null, false, false));
final int index = ListHelper.getDefaultResolutionIndex(
fragment.requireContext(), sortedVideoStreamsList);

final DownloadDialog downloadDialog =
DownloadDialog.newInstance(info);
downloadDialog.setVideoStreams(sortedVideoStreamsList);
downloadDialog.setSelectedAudioStream(index);
downloadDialog.setAudioStreams(info.getAudioStreams());
downloadDialog.setSubtitleStreams(info.getSubtitles());
downloadDialog.show(
fragment.getChildFragmentManager(),
"downloadDialog"
);
},
throwable -> {
}
)
),

OPEN_IN_BROWSER(R.string.open_in_browser, (fragment, item) ->
ShareUtils.openUrlInBrowser(fragment.requireContext(), item.getUrl())),

Expand Down

0 comments on commit caf0eef

Please sign in to comment.