Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ dependencies {
exclude module: 'support-annotations'
}

implementation 'com.github.TeamNewPipe:NewPipeExtractor:bda83fe6a5b9a8a0751669fbc444fa49d72d0d2f'
implementation 'com.github.yausername:NewPipeExtractor:bbc_sounds-SNAPSHOT'

implementation "com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
implementation "org.jsoup:jsoup:1.13.1"
Expand Down Expand Up @@ -207,6 +207,7 @@ dependencies {
implementation "com.jakewharton.rxbinding2:rxbinding:2.2.0"

implementation "org.ocpsoft.prettytime:prettytime:4.0.5.Final"
implementation 'com.caverock:androidsvg-aar:1.4'
}

static String getGitWorkingBranch() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private ImageLoaderConfiguration getImageLoaderConfigurations(final int memoryCa
.memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024))
.diskCacheSize(diskCacheSizeMb * 1024 * 1024)
.imageDownloader(new ImageDownloader(getApplicationContext()))
.imageDecoder(new ImageDecoder(false))
.build();
}

Expand Down
73 changes: 73 additions & 0 deletions app/src/main/java/org/schabi/newpipe/ImageDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.schabi.newpipe;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;

import com.caverock.androidsvg.SVG;
import com.caverock.androidsvg.SVGParseException;
import com.nostra13.universalimageloader.core.decode.BaseImageDecoder;
import com.nostra13.universalimageloader.core.decode.ImageDecodingInfo;
import com.nostra13.universalimageloader.utils.IoUtils;
import com.nostra13.universalimageloader.utils.L;

import java.io.IOException;
import java.io.InputStream;

public class ImageDecoder extends BaseImageDecoder {

public ImageDecoder(final boolean loggingEnabled) {
super(loggingEnabled);
}

@Override
public Bitmap decode(final ImageDecodingInfo decodingInfo) throws IOException {
if (decodingInfo.getOriginalImageUri().endsWith("svg")) {
Bitmap decodedBitmap;
ImageFileInfo imageInfo;

InputStream imageStream = getImageStream(decodingInfo);
if (imageStream == null) {
L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey());
return null;
}
try {
imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
imageStream = resetStream(imageStream, decodingInfo);
BitmapFactory.Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize,
decodingInfo);
decodedBitmap = decodeSVG(imageStream, decodingOptions);
} finally {
IoUtils.closeSilently(imageStream);
}

if (decodedBitmap == null) {
L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
} else {
decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo,
imageInfo.exif.rotation, imageInfo.exif.flipHorizontal);
}
return decodedBitmap;
} else {
return super.decode(decodingInfo);
}
}

private Bitmap decodeSVG(final InputStream imageStream,
final BitmapFactory.Options decodingOptions) {
SVG svg;
try {
svg = SVG.getFromInputStream(imageStream);
} catch (SVGParseException e) {
return null;
}
int width = decodingOptions.outWidth != 0 ? decodingOptions.outWidth : 200;
int height = decodingOptions.outHeight != 0 ? decodingOptions.outHeight : 200;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
svg.renderToCanvas(canvas);
return bitmap;
}
}
17 changes: 14 additions & 3 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,15 @@ private void handleChoice(final String selectedChoiceKey) {
finish();
}

private Disposable downloadDisposable;

@SuppressLint("CheckResult")
private void openDownloadDialog() {
ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
if (downloadDisposable != null) {
return;
}

downloadDisposable = ExtractorHelper.getStreamInfo(currentServiceId, currentUrl, true)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((@NonNull StreamInfo result) -> {
Expand All @@ -492,9 +498,14 @@ private void openDownloadDialog() {
downloadDialog.setSelectedVideoStream(selectedVideoStreamIndex);
downloadDialog.show(fm, "downloadDialog");
fm.executePendingTransactions();
downloadDialog.getDialog().setOnDismissListener(dialog -> {
// TODO: Improve this dialog dismiss logic
if (downloadDialog.getDialog() != null) {
downloadDialog.getDialog().setOnDismissListener(dialog -> {
finish();
});
} else {
finish();
});
}
}, (@NonNull Throwable throwable) -> {
onError();
});
Expand Down
78 changes: 66 additions & 12 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.DeliveryFormat;
import org.schabi.newpipe.extractor.stream.Stream;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
Expand All @@ -64,6 +65,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -149,15 +151,59 @@ private void setInfo(final StreamInfo info) {
}

public void setAudioStreams(final List<AudioStream> audioStreams) {
setAudioStreams(new StreamSizeWrapper<>(audioStreams, getContext()));
// TODO: Remove this when the downloader support other types of stream deliveries
final List<AudioStream> listAudioStreams = new ArrayList<>(audioStreams);
wasSomeStreamRemoved = removeNotDirectStreams(listAudioStreams) || wasSomeStreamRemoved;

setAudioStreams(new StreamSizeWrapper<>(listAudioStreams, getContext()));
}

public void setAudioStreams(final StreamSizeWrapper<AudioStream> was) {
this.wrappedAudioStreams = was;
}

public void setVideoStreams(final List<VideoStream> videoStreams) {
setVideoStreams(new StreamSizeWrapper<>(videoStreams, getContext()));
// TODO: Remove this when the downloader support other types of stream deliveries
final List<VideoStream> listVideoStreams = new ArrayList<>(videoStreams);
wasSomeStreamRemoved = removeNotDirectStreams(listVideoStreams) || wasSomeStreamRemoved;

setVideoStreams(new StreamSizeWrapper<>(listVideoStreams, getContext()));
}

public void setSubtitleStreams(final List<SubtitlesStream> subtitleStreams) {
// TODO: Remove this when the downloader support other types of stream deliveries
final List<SubtitlesStream> listSubtitleStreams = new ArrayList<>(subtitleStreams);
wasSomeStreamRemoved = removeNotDirectStreams(listSubtitleStreams) || wasSomeStreamRemoved;

setSubtitleStreams(new StreamSizeWrapper<>(listSubtitleStreams, getContext()));
}

private Toast removedStreamToast = null;
boolean wasSomeStreamRemoved = false;

private void showIfStreamsWereRemovedMessage() {
if (wasSomeStreamRemoved && removedStreamToast == null) {
removedStreamToast = Toast.makeText(
requireContext(),
R.string.streams_hidden_download_not_supported_yet,
Toast.LENGTH_LONG
);
removedStreamToast.show();
}
}

private static boolean removeNotDirectStreams(final List<? extends Stream> streamList) {
boolean wasSomeStreamRemoved = false;
final Iterator<? extends Stream> streamIterator = streamList.iterator();
while (streamIterator.hasNext()) {
final Stream stream = streamIterator.next();
if (!(stream.getDeliveryFormat() instanceof DeliveryFormat.Direct)) {
streamIterator.remove();
wasSomeStreamRemoved = true;
}
}

return wasSomeStreamRemoved;
}

/*//////////////////////////////////////////////////////////////////////////
Expand All @@ -168,10 +214,6 @@ public void setVideoStreams(final StreamSizeWrapper<VideoStream> wvs) {
this.wrappedVideoStreams = wvs;
}

public void setSubtitleStreams(final List<SubtitlesStream> subtitleStreams) {
setSubtitleStreams(new StreamSizeWrapper<>(subtitleStreams, getContext()));
}

public void setSubtitleStreams(
final StreamSizeWrapper<SubtitlesStream> wss) {
this.wrappedSubtitleStreams = wss;
Expand Down Expand Up @@ -199,11 +241,12 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {

if (!PermissionHelper.checkStoragePermissions(getActivity(),
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
getDialog().dismiss();
dismiss();
return;
}

context = getContext();
showIfStreamsWereRemovedMessage();

setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
Icepick.restoreInstanceState(this, savedInstanceState);
Expand Down Expand Up @@ -277,8 +320,10 @@ public void onViewCreated(@NonNull final View view, @Nullable final Bundle saved
super.onViewCreated(view, savedInstanceState);
nameEditText = view.findViewById(R.id.file_name);
nameEditText.setText(FilenameUtils.createFilename(getContext(), currentInfo.getName()));
selectedAudioIndex = ListHelper
.getDefaultAudioFormat(getContext(), currentInfo.getAudioStreams());
selectedAudioIndex = ListHelper.getDefaultAudioFormat(getContext(),
wrappedAudioStreams.getStreamsList());
final int videoStreamListSize = wrappedVideoStreams.getStreamsList().size();
selectedVideoIndex = Math.max(0, Math.min(selectedVideoIndex, videoStreamListSize - 1));

selectedSubtitleIndex = getSubtitleIndexBy(subtitleStreamsAdapter.getAll());

Expand Down Expand Up @@ -527,7 +572,7 @@ protected void setupDownloadOptions() {
} else {
Toast.makeText(getContext(), R.string.no_streams_available_download,
Toast.LENGTH_SHORT).show();
getDialog().dismiss();
dismiss();
}
}

Expand Down Expand Up @@ -898,16 +943,25 @@ private void continueSelectedDownload(@NonNull final StoredFileHelper storage) {
return;
}

if (!(selectedStream.getDeliveryFormat() instanceof DeliveryFormat.Direct)) {
throw new IllegalArgumentException("Unsupported stream delivery format");
}

if (secondaryStream == null) {
urls = new String[]{
selectedStream.getUrl()
((DeliveryFormat.Direct) selectedStream.getDeliveryFormat()).getUrl()
};
recoveryInfo = new MissionRecoveryInfo[]{
new MissionRecoveryInfo(selectedStream)
};
} else {
if (!(secondaryStream.getDeliveryFormat() instanceof DeliveryFormat.Direct)) {
throw new IllegalArgumentException("Unsupported stream delivery format");
}

urls = new String[]{
selectedStream.getUrl(), secondaryStream.getUrl()
((DeliveryFormat.Direct) selectedStream.getDeliveryFormat()).getUrl(),
((DeliveryFormat.Direct) secondaryStream.getDeliveryFormat()).getUrl()
};
recoveryInfo = new MissionRecoveryInfo[]{new MissionRecoveryInfo(selectedStream),
new MissionRecoveryInfo(secondaryStream)};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ public void onLoadingFailed(final String imageUri, final View view,
if (!TextUtils.isEmpty(info.getUploaderAvatarUrl())) {
IMAGE_LOADER.displayImage(info.getUploaderAvatarUrl(), uploaderThumb,
ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS);

}
}

Expand Down Expand Up @@ -1227,7 +1228,8 @@ public void handleResult(@NonNull final StreamInfo info) {
detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.duration_background_color));
animateView(detailDurationView, true, 100);
} else if (info.getStreamType() == StreamType.LIVE_STREAM) {
} else if (info.getStreamType() == StreamType.LIVE_STREAM
|| info.getStreamType() == StreamType.AUDIO_LIVE_STREAM) {
detailDurationView.setText(R.string.duration_live);
detailDurationView.setBackgroundColor(
ContextCompat.getColor(activity, R.color.live_duration_background_color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ public void handleResult(@NonNull final ChannelInfo result) {
headerRootLayout.setVisibility(View.VISIBLE);
IMAGE_LOADER.displayImage(result.getBannerUrl(), headerChannelBanner,
ImageDisplayConstants.DISPLAY_BANNER_OPTIONS);

IMAGE_LOADER.displayImage(result.getAvatarUrl(), headerAvatarView,
ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS);
IMAGE_LOADER.displayImage(result.getParentChannelAvatarUrl(), headerSubChannelAvatarView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public void updateFromItem(final InfoItem infoItem,
} else {
itemProgressView.setVisibility(View.GONE);
}
} else if (item.getStreamType() == StreamType.LIVE_STREAM) {
} else if (item.getStreamType() == StreamType.LIVE_STREAM
|| item.getStreamType() == StreamType.AUDIO_LIVE_STREAM) {
itemDurationView.setText(R.string.duration_live);
itemDurationView.setBackgroundColor(ContextCompat.getColor(itemBuilder.getContext(),
R.color.live_duration_background_color));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public MediaSource resolve(@NonNull final StreamInfo info) {

final AudioStream audio = info.getAudioStreams().get(index);
final MediaSourceTag tag = new MediaSourceTag(info);
return buildMediaSource(dataSource, audio.getUrl(), PlayerHelper.cacheKeyOf(info, audio),
return buildMediaSource(dataSource, audio, PlayerHelper.cacheKeyOf(info, audio),
MediaFormat.getSuffixById(audio.getFormatId()), tag);
}
}
Loading