2016-03-25 19:01:22 +01:00
|
|
|
package org.schabi.newpipe.download;
|
2015-09-21 21:12:48 +02:00
|
|
|
|
2022-07-10 14:19:58 +02:00
|
|
|
import static org.schabi.newpipe.extractor.stream.DeliveryMethod.PROGRESSIVE_HTTP;
|
|
|
|
import static org.schabi.newpipe.util.ListHelper.getStreamsOfSpecifiedDelivery;
|
|
|
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.ComponentName;
|
2018-04-08 13:08:19 +02:00
|
|
|
import android.content.Context;
|
2021-07-19 10:42:24 +02:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.DialogInterface.OnDismissListener;
|
2019-04-05 19:45:39 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.ServiceConnection;
|
2018-09-23 20:12:23 +02:00
|
|
|
import android.content.SharedPreferences;
|
2019-04-05 19:45:39 +02:00
|
|
|
import android.net.Uri;
|
2015-09-21 21:12:48 +02:00
|
|
|
import android.os.Bundle;
|
2019-08-15 04:00:11 +02:00
|
|
|
import android.os.Environment;
|
2019-04-05 19:45:39 +02:00
|
|
|
import android.os.IBinder;
|
2015-09-21 21:12:48 +02:00
|
|
|
import android.util.Log;
|
2016-04-29 12:40:03 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-05-15 05:57:57 +02:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.RadioGroup;
|
2016-04-29 12:40:03 +02:00
|
|
|
import android.widget.SeekBar;
|
2018-04-08 13:08:19 +02:00
|
|
|
import android.widget.Toast;
|
2015-09-21 21:12:48 +02:00
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
import androidx.activity.result.ActivityResult;
|
|
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult;
|
2020-01-31 22:49:43 +01:00
|
|
|
import androidx.annotation.IdRes;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
import androidx.appcompat.view.menu.ActionMenuItemView;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2022-11-22 14:01:58 +01:00
|
|
|
import androidx.collection.SparseArrayCompat;
|
2020-01-31 22:49:43 +01:00
|
|
|
import androidx.documentfile.provider.DocumentFile;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2020-10-31 21:55:45 +01:00
|
|
|
import androidx.preference.PreferenceManager;
|
2020-01-31 22:49:43 +01:00
|
|
|
|
2019-08-15 04:00:11 +02:00
|
|
|
import com.nononsenseapps.filepicker.Utils;
|
|
|
|
|
2017-05-15 05:57:57 +02:00
|
|
|
import org.schabi.newpipe.MainActivity;
|
2016-03-25 19:01:22 +01:00
|
|
|
import org.schabi.newpipe.R;
|
2020-11-03 05:30:12 +01:00
|
|
|
import org.schabi.newpipe.databinding.DownloadDialogBinding;
|
2020-12-11 15:07:18 +01:00
|
|
|
import org.schabi.newpipe.error.ErrorInfo;
|
2021-12-01 09:43:24 +01:00
|
|
|
import org.schabi.newpipe.error.ErrorUtil;
|
2020-12-11 15:07:18 +01:00
|
|
|
import org.schabi.newpipe.error.UserAction;
|
2018-09-23 20:12:23 +02:00
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2019-10-28 03:35:51 +01:00
|
|
|
import org.schabi.newpipe.extractor.localization.Localization;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
2018-04-08 13:08:19 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.Stream;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
2018-09-23 20:12:23 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
2019-08-15 03:15:42 +02:00
|
|
|
import org.schabi.newpipe.settings.NewPipeSettings;
|
2021-11-28 14:07:45 +01:00
|
|
|
import org.schabi.newpipe.streams.io.NoFileManagerSafeGuard;
|
2020-06-14 19:37:45 +02:00
|
|
|
import org.schabi.newpipe.streams.io.StoredDirectoryHelper;
|
|
|
|
import org.schabi.newpipe.streams.io.StoredFileHelper;
|
2019-08-15 03:15:42 +02:00
|
|
|
import org.schabi.newpipe.util.FilePickerActivityHelper;
|
2017-07-19 16:27:40 +02:00
|
|
|
import org.schabi.newpipe.util.FilenameUtils;
|
2017-09-03 08:04:18 +02:00
|
|
|
import org.schabi.newpipe.util.ListHelper;
|
2019-08-15 04:00:11 +02:00
|
|
|
import org.schabi.newpipe.util.PermissionHelper;
|
2018-11-20 23:10:50 +01:00
|
|
|
import org.schabi.newpipe.util.SecondaryStreamHelper;
|
2022-03-18 02:49:04 +01:00
|
|
|
import org.schabi.newpipe.util.SimpleOnSeekBarChangeListener;
|
2018-04-08 13:08:19 +02:00
|
|
|
import org.schabi.newpipe.util.StreamItemAdapter;
|
|
|
|
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
|
2023-03-20 14:12:08 +01:00
|
|
|
import org.schabi.newpipe.util.AudioTrackAdapter;
|
|
|
|
import org.schabi.newpipe.util.AudioTrackAdapter.AudioTracksWrapper;
|
2017-04-26 21:32:04 +02:00
|
|
|
import org.schabi.newpipe.util.ThemeHelper;
|
2016-03-25 19:01:22 +01:00
|
|
|
|
2019-08-15 03:15:42 +02:00
|
|
|
import java.io.File;
|
2019-04-05 19:45:39 +02:00
|
|
|
import java.io.IOException;
|
2016-01-07 14:22:55 +01:00
|
|
|
import java.util.List;
|
2018-09-23 20:12:23 +02:00
|
|
|
import java.util.Locale;
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
import java.util.Objects;
|
2023-01-11 19:45:55 +01:00
|
|
|
import java.util.Optional;
|
2015-09-21 21:12:48 +02:00
|
|
|
|
2018-04-08 13:08:19 +02:00
|
|
|
import icepick.Icepick;
|
|
|
|
import icepick.State;
|
2020-10-31 21:55:45 +01:00
|
|
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
2019-09-28 23:11:05 +02:00
|
|
|
import us.shandian.giga.get.MissionRecoveryInfo;
|
2018-09-23 20:12:23 +02:00
|
|
|
import us.shandian.giga.postprocessing.Postprocessing;
|
2019-04-05 19:45:39 +02:00
|
|
|
import us.shandian.giga.service.DownloadManager;
|
2016-04-29 12:40:03 +02:00
|
|
|
import us.shandian.giga.service.DownloadManagerService;
|
2019-04-05 19:45:39 +02:00
|
|
|
import us.shandian.giga.service.DownloadManagerService.DownloadManagerBinder;
|
|
|
|
import us.shandian.giga.service.MissionState;
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
public class DownloadDialog extends DialogFragment
|
|
|
|
implements RadioGroup.OnCheckedChangeListener, AdapterView.OnItemSelectedListener {
|
2017-05-15 05:57:57 +02:00
|
|
|
private static final String TAG = "DialogFragment";
|
|
|
|
private static final boolean DEBUG = MainActivity.DEBUG;
|
2020-04-02 13:51:10 +02:00
|
|
|
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2020-04-02 13:51:10 +02:00
|
|
|
StreamInfo currentInfo;
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2022-06-18 17:40:22 +02:00
|
|
|
StreamSizeWrapper<VideoStream> wrappedVideoStreams;
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2022-06-18 17:40:22 +02:00
|
|
|
StreamSizeWrapper<SubtitlesStream> wrappedSubtitleStreams;
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2023-03-20 14:12:08 +01:00
|
|
|
AudioTracksWrapper wrappedAudioTracks;
|
|
|
|
@State
|
2023-04-21 23:15:37 +02:00
|
|
|
int selectedAudioTrackIndex;
|
2023-03-20 14:12:08 +01:00
|
|
|
@State
|
2022-06-18 17:40:22 +02:00
|
|
|
int selectedVideoIndex; // set in the constructor
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2022-06-18 17:40:22 +02:00
|
|
|
int selectedAudioIndex = 0; // default to the first item
|
2018-11-20 23:10:50 +01:00
|
|
|
@State
|
2022-06-18 17:40:22 +02:00
|
|
|
int selectedSubtitleIndex = 0; // default to the first item
|
2020-04-02 13:51:10 +02:00
|
|
|
|
2021-07-19 10:42:24 +02:00
|
|
|
@Nullable
|
|
|
|
private OnDismissListener onDismissListener = null;
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private StoredDirectoryHelper mainStorageAudio = null;
|
|
|
|
private StoredDirectoryHelper mainStorageVideo = null;
|
|
|
|
private DownloadManager downloadManager = null;
|
|
|
|
private ActionMenuItemView okButton = null;
|
|
|
|
private Context context;
|
|
|
|
private boolean askForSavePath;
|
2020-04-02 13:51:10 +02:00
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
private AudioTrackAdapter audioTrackAdapter;
|
2018-11-20 23:10:50 +01:00
|
|
|
private StreamItemAdapter<AudioStream, Stream> audioStreamsAdapter;
|
|
|
|
private StreamItemAdapter<VideoStream, AudioStream> videoStreamsAdapter;
|
|
|
|
private StreamItemAdapter<SubtitlesStream, Stream> subtitleStreamsAdapter;
|
2020-04-02 13:51:10 +02:00
|
|
|
|
|
|
|
private final CompositeDisposable disposables = new CompositeDisposable();
|
|
|
|
|
2020-11-03 05:30:12 +01:00
|
|
|
private DownloadDialogBinding dialogBinding;
|
2020-04-02 13:51:10 +02:00
|
|
|
|
2018-09-23 20:12:23 +02:00
|
|
|
private SharedPreferences prefs;
|
|
|
|
|
2020-06-13 17:29:57 +02:00
|
|
|
// Variables for file name and MIME type when picking new folder because it's not set yet
|
|
|
|
private String filenameTmp;
|
|
|
|
private String mimeTmp;
|
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
private final ActivityResultLauncher<Intent> requestDownloadSaveAsLauncher =
|
|
|
|
registerForActivityResult(
|
|
|
|
new StartActivityForResult(), this::requestDownloadSaveAsResult);
|
|
|
|
private final ActivityResultLauncher<Intent> requestDownloadPickAudioFolderLauncher =
|
|
|
|
registerForActivityResult(
|
|
|
|
new StartActivityForResult(), this::requestDownloadPickAudioFolderResult);
|
|
|
|
private final ActivityResultLauncher<Intent> requestDownloadPickVideoFolderLauncher =
|
|
|
|
registerForActivityResult(
|
|
|
|
new StartActivityForResult(), this::requestDownloadPickVideoFolderResult);
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2022-06-18 17:40:22 +02:00
|
|
|
// Instance creation
|
2021-07-18 14:22:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2022-10-06 12:15:36 +02:00
|
|
|
public DownloadDialog() {
|
|
|
|
// Just an empty default no-arg ctor to keep Fragment.instantiate() happy
|
|
|
|
// otherwise InstantiationException will be thrown when fragment is recreated
|
|
|
|
// TODO: Maybe use a custom FragmentFactory instead?
|
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
/**
|
2022-06-18 17:40:22 +02:00
|
|
|
* Create a new download dialog with the video, audio and subtitle streams from the provided
|
|
|
|
* stream info. Video streams and video-only streams will be put into a single list menu,
|
|
|
|
* sorted according to their resolution and the default video resolution will be selected.
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
*
|
2022-06-18 17:40:22 +02:00
|
|
|
* @param context the context to use just to obtain preferences and strings (will not be stored)
|
|
|
|
* @param info the info from which to obtain downloadable streams and other info (e.g. title)
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
*/
|
2022-10-26 11:22:32 +02:00
|
|
|
public DownloadDialog(@NonNull final Context context, @NonNull final StreamInfo info) {
|
2022-06-18 17:40:22 +02:00
|
|
|
this.currentInfo = info;
|
2018-04-08 13:08:19 +02:00
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
final List<AudioStream> audioStreams =
|
|
|
|
getStreamsOfSpecifiedDelivery(info.getAudioStreams(), PROGRESSIVE_HTTP);
|
|
|
|
final List<List<AudioStream>> groupedAudioStreams =
|
|
|
|
ListHelper.getGroupedAudioStreams(context, audioStreams);
|
|
|
|
this.wrappedAudioTracks = new AudioTracksWrapper(groupedAudioStreams, context);
|
2023-04-21 23:15:37 +02:00
|
|
|
this.selectedAudioTrackIndex =
|
2023-03-20 14:12:08 +01:00
|
|
|
ListHelper.getDefaultAudioTrackGroup(context, groupedAudioStreams);
|
|
|
|
|
2022-06-18 17:40:22 +02:00
|
|
|
// TODO: Adapt this code when the downloader support other types of stream deliveries
|
|
|
|
final List<VideoStream> videoStreams = ListHelper.getSortedStreamVideosList(
|
|
|
|
context,
|
|
|
|
getStreamsOfSpecifiedDelivery(info.getVideoStreams(), PROGRESSIVE_HTTP),
|
|
|
|
getStreamsOfSpecifiedDelivery(info.getVideoOnlyStreams(), PROGRESSIVE_HTTP),
|
|
|
|
false,
|
2023-03-20 14:12:08 +01:00
|
|
|
// If there are multiple languages available, prefer streams without audio
|
|
|
|
// to allow language selection
|
|
|
|
wrappedAudioTracks.size() > 1
|
2022-06-18 17:40:22 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
this.wrappedVideoStreams = new StreamSizeWrapper<>(videoStreams, context);
|
|
|
|
this.wrappedSubtitleStreams = new StreamSizeWrapper<>(
|
|
|
|
getStreamsOfSpecifiedDelivery(info.getSubtitles(), PROGRESSIVE_HTTP), context);
|
|
|
|
|
|
|
|
this.selectedVideoIndex = ListHelper.getDefaultResolutionIndex(context, videoStreams);
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
/**
|
2022-06-18 17:40:22 +02:00
|
|
|
* @param onDismissListener the listener to call in {@link #onDismiss(DialogInterface)}
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
*/
|
2021-07-19 10:42:24 +02:00
|
|
|
public void setOnDismissListener(@Nullable final OnDismissListener onDismissListener) {
|
|
|
|
this.onDismissListener = onDismissListener;
|
|
|
|
}
|
2021-07-18 14:22:41 +02:00
|
|
|
|
2022-06-18 17:40:22 +02:00
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Android lifecycle
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2015-09-21 21:12:48 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
2017-05-15 05:57:57 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onCreate() called with: "
|
|
|
|
+ "savedInstanceState = [" + savedInstanceState + "]");
|
|
|
|
}
|
2017-05-15 05:57:57 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (!PermissionHelper.checkStoragePermissions(getActivity(),
|
|
|
|
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
|
2021-07-19 10:42:24 +02:00
|
|
|
dismiss();
|
2019-08-15 04:00:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:38:34 +02:00
|
|
|
context = getContext();
|
2019-04-05 19:45:39 +02:00
|
|
|
|
|
|
|
setStyle(STYLE_NO_TITLE, ThemeHelper.getDialogTheme(context));
|
2018-04-08 13:08:19 +02:00
|
|
|
Icepick.restoreInstanceState(this, savedInstanceState);
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
this.audioTrackAdapter = new AudioTrackAdapter(wrappedAudioTracks);
|
2022-11-22 14:01:58 +01:00
|
|
|
this.subtitleStreamsAdapter = new StreamItemAdapter<>(wrappedSubtitleStreams);
|
2023-03-20 14:12:08 +01:00
|
|
|
updateSecondaryStreams();
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final Intent intent = new Intent(context, DownloadManagerService.class);
|
2019-04-05 19:45:39 +02:00
|
|
|
context.startService(intent);
|
|
|
|
|
|
|
|
context.bindService(intent, new ServiceConnection() {
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onServiceConnected(final ComponentName cname, final IBinder service) {
|
2020-08-16 10:24:58 +02:00
|
|
|
final DownloadManagerBinder mgr = (DownloadManagerBinder) service;
|
2019-04-05 19:45:39 +02:00
|
|
|
|
|
|
|
mainStorageAudio = mgr.getMainStorageAudio();
|
|
|
|
mainStorageVideo = mgr.getMainStorageVideo();
|
|
|
|
downloadManager = mgr.getDownloadManager();
|
2019-04-19 21:18:19 +02:00
|
|
|
askForSavePath = mgr.askForSavePath();
|
2019-04-05 19:45:39 +02:00
|
|
|
|
|
|
|
okButton.setEnabled(true);
|
|
|
|
|
|
|
|
context.unbindService(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onServiceDisconnected(final ComponentName name) {
|
2019-04-05 19:45:39 +02:00
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
}, Context.BIND_AUTO_CREATE);
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
/**
|
|
|
|
* Update the displayed video streams based on the selected audio track.
|
|
|
|
*/
|
|
|
|
private void updateSecondaryStreams() {
|
|
|
|
final StreamSizeWrapper<AudioStream> audioStreams = getWrappedAudioStreams();
|
|
|
|
final var secondaryStreams = new SparseArrayCompat<SecondaryStreamHelper<AudioStream>>(4);
|
|
|
|
final List<VideoStream> videoStreams = wrappedVideoStreams.getStreamsList();
|
2023-03-29 13:39:29 +02:00
|
|
|
wrappedVideoStreams.resetSizes();
|
2023-03-20 14:12:08 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < videoStreams.size(); i++) {
|
|
|
|
if (!videoStreams.get(i).isVideoOnly()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final AudioStream audioStream = SecondaryStreamHelper
|
|
|
|
.getAudioStreamFor(audioStreams.getStreamsList(), videoStreams.get(i));
|
|
|
|
|
|
|
|
if (audioStream != null) {
|
|
|
|
secondaryStreams.append(i, new SecondaryStreamHelper<>(audioStreams, audioStream));
|
|
|
|
} else if (DEBUG) {
|
|
|
|
final MediaFormat mediaFormat = videoStreams.get(i).getFormat();
|
|
|
|
if (mediaFormat != null) {
|
|
|
|
Log.w(TAG, "No audio stream candidates for video format "
|
|
|
|
+ mediaFormat.name());
|
|
|
|
} else {
|
|
|
|
Log.w(TAG, "No audio stream candidates for unknown video format");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.videoStreamsAdapter = new StreamItemAdapter<>(wrappedVideoStreams, secondaryStreams);
|
|
|
|
this.audioStreamsAdapter = new StreamItemAdapter<>(audioStreams);
|
|
|
|
}
|
|
|
|
|
2017-05-15 05:57:57 +02:00
|
|
|
@Override
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
public View onCreateView(@NonNull final LayoutInflater inflater,
|
|
|
|
final ViewGroup container,
|
2020-03-31 19:20:15 +02:00
|
|
|
final Bundle savedInstanceState) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onCreateView() called with: "
|
|
|
|
+ "inflater = [" + inflater + "], container = [" + container + "], "
|
|
|
|
+ "savedInstanceState = [" + savedInstanceState + "]");
|
|
|
|
}
|
2018-04-08 13:08:19 +02:00
|
|
|
return inflater.inflate(R.layout.download_dialog, container);
|
2016-04-29 12:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
public void onViewCreated(@NonNull final View view,
|
|
|
|
@Nullable final Bundle savedInstanceState) {
|
2016-04-29 12:40:03 +02:00
|
|
|
super.onViewCreated(view, savedInstanceState);
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding = DownloadDialogBinding.bind(view);
|
|
|
|
|
|
|
|
dialogBinding.fileName.setText(FilenameUtils.createFilename(getContext(),
|
|
|
|
currentInfo.getName()));
|
2023-03-20 14:12:08 +01:00
|
|
|
selectedAudioIndex = ListHelper.getDefaultAudioFormat(getContext(),
|
|
|
|
getWrappedAudioStreams().getStreamsList());
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2018-09-23 20:12:23 +02:00
|
|
|
selectedSubtitleIndex = getSubtitleIndexBy(subtitleStreamsAdapter.getAll());
|
|
|
|
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.qualitySpinner.setOnItemSelectedListener(this);
|
2023-07-14 17:05:13 +02:00
|
|
|
dialogBinding.audioStreamSpinner.setOnItemSelectedListener(this);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.audioTrackSpinner.setOnItemSelectedListener(this);
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.videoAudioGroup.setOnCheckedChangeListener(this);
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2020-11-03 05:30:12 +01:00
|
|
|
initToolbar(dialogBinding.toolbarLayout.toolbar);
|
2018-04-08 13:08:19 +02:00
|
|
|
setupDownloadOptions();
|
2017-05-15 05:57:57 +02:00
|
|
|
|
2020-08-27 22:55:57 +02:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
|
2018-09-23 20:12:23 +02:00
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final int threads = prefs.getInt(getString(R.string.default_download_threads), 3);
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.threadsCount.setText(String.valueOf(threads));
|
|
|
|
dialogBinding.threads.setProgress(threads - 1);
|
2022-03-18 02:49:04 +01:00
|
|
|
dialogBinding.threads.setOnSeekBarChangeListener(new SimpleOnSeekBarChangeListener() {
|
2016-04-29 12:40:03 +02:00
|
|
|
@Override
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
public void onProgressChanged(@NonNull final SeekBar seekbar,
|
|
|
|
final int progress,
|
2020-03-31 19:20:15 +02:00
|
|
|
final boolean fromUser) {
|
|
|
|
final int newProgress = progress + 1;
|
|
|
|
prefs.edit().putInt(getString(R.string.default_download_threads), newProgress)
|
|
|
|
.apply();
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.threadsCount.setText(String.valueOf(newProgress));
|
2016-04-29 12:40:03 +02:00
|
|
|
}
|
|
|
|
});
|
2018-04-08 13:08:19 +02:00
|
|
|
|
|
|
|
fetchStreamsSize();
|
|
|
|
}
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
private void initToolbar(final Toolbar toolbar) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "initToolbar() called with: toolbar = [" + toolbar + "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbar.setTitle(R.string.download_dialog_title);
|
|
|
|
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
|
|
|
|
toolbar.inflateMenu(R.menu.dialog_url);
|
2021-07-19 10:42:24 +02:00
|
|
|
toolbar.setNavigationOnClickListener(v -> dismiss());
|
2021-07-18 14:22:41 +02:00
|
|
|
toolbar.setNavigationContentDescription(R.string.cancel);
|
|
|
|
|
|
|
|
okButton = toolbar.findViewById(R.id.okay);
|
|
|
|
okButton.setEnabled(false); // disable until the download service connection is done
|
|
|
|
|
|
|
|
toolbar.setOnMenuItemClickListener(item -> {
|
|
|
|
if (item.getItemId() == R.id.okay) {
|
|
|
|
prepareSelectedDownload();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-19 10:42:24 +02:00
|
|
|
@Override
|
|
|
|
public void onDismiss(@NonNull final DialogInterface dialog) {
|
|
|
|
super.onDismiss(dialog);
|
|
|
|
if (onDismissListener != null) {
|
|
|
|
onDismissListener.onDismiss(dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
disposables.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
dialogBinding = null;
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(@NonNull final Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
Icepick.saveInstanceState(this, outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Video, audio and subtitle spinners
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-04-08 13:08:19 +02:00
|
|
|
private void fetchStreamsSize() {
|
|
|
|
disposables.clear();
|
2020-03-31 19:20:15 +02:00
|
|
|
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(wrappedVideoStreams)
|
|
|
|
.subscribe(result -> {
|
2021-04-20 09:36:40 +02:00
|
|
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
|
|
|
== R.id.video_button) {
|
|
|
|
setupVideoSpinner();
|
|
|
|
}
|
2021-12-01 09:43:24 +01:00
|
|
|
}, throwable -> ErrorUtil.showSnackbar(context,
|
2021-04-20 12:51:20 +02:00
|
|
|
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
|
|
|
"Downloading video stream size",
|
|
|
|
currentInfo.getServiceId()))));
|
2023-03-20 14:12:08 +01:00
|
|
|
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(getWrappedAudioStreams())
|
2020-03-31 19:20:15 +02:00
|
|
|
.subscribe(result -> {
|
2021-04-20 09:36:40 +02:00
|
|
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
|
|
|
== R.id.audio_button) {
|
|
|
|
setupAudioSpinner();
|
|
|
|
}
|
2021-12-01 09:43:24 +01:00
|
|
|
}, throwable -> ErrorUtil.showSnackbar(context,
|
2021-04-20 12:51:20 +02:00
|
|
|
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
|
|
|
"Downloading audio stream size",
|
|
|
|
currentInfo.getServiceId()))));
|
2020-03-31 19:20:15 +02:00
|
|
|
disposables.add(StreamSizeWrapper.fetchSizeForWrapper(wrappedSubtitleStreams)
|
|
|
|
.subscribe(result -> {
|
2021-04-20 09:36:40 +02:00
|
|
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()
|
|
|
|
== R.id.subtitle_button) {
|
|
|
|
setupSubtitleSpinner();
|
|
|
|
}
|
2021-12-01 09:43:24 +01:00
|
|
|
}, throwable -> ErrorUtil.showSnackbar(context,
|
2021-04-20 12:51:20 +02:00
|
|
|
new ErrorInfo(throwable, UserAction.DOWNLOAD_OPEN_DIALOG,
|
|
|
|
"Downloading subtitle stream size",
|
|
|
|
currentInfo.getServiceId()))));
|
2018-04-08 13:08:19 +02:00
|
|
|
}
|
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
private void setupAudioTrackSpinner() {
|
|
|
|
if (getContext() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogBinding.audioTrackSpinner.setAdapter(audioTrackAdapter);
|
2023-04-21 23:15:37 +02:00
|
|
|
dialogBinding.audioTrackSpinner.setSelection(selectedAudioTrackIndex);
|
2023-03-20 14:12:08 +01:00
|
|
|
}
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
private void setupAudioSpinner() {
|
|
|
|
if (getContext() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.qualitySpinner.setVisibility(View.GONE);
|
2021-07-18 14:22:41 +02:00
|
|
|
setRadioButtonsState(true);
|
2023-03-21 16:58:36 +01:00
|
|
|
dialogBinding.audioStreamSpinner.setAdapter(audioStreamsAdapter);
|
|
|
|
dialogBinding.audioStreamSpinner.setSelection(selectedAudioIndex);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.audioStreamSpinner.setVisibility(View.VISIBLE);
|
|
|
|
dialogBinding.audioTrackSpinner.setVisibility(
|
|
|
|
wrappedAudioTracks.size() > 1 ? View.VISIBLE : View.GONE);
|
2023-05-02 00:11:09 +02:00
|
|
|
dialogBinding.audioTrackPresentInVideoText.setVisibility(View.GONE);
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
private void setupVideoSpinner() {
|
|
|
|
if (getContext() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogBinding.qualitySpinner.setAdapter(videoStreamsAdapter);
|
|
|
|
dialogBinding.qualitySpinner.setSelection(selectedVideoIndex);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.qualitySpinner.setVisibility(View.VISIBLE);
|
2021-07-18 14:22:41 +02:00
|
|
|
setRadioButtonsState(true);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.audioStreamSpinner.setVisibility(View.GONE);
|
|
|
|
onVideoStreamSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onVideoStreamSelected() {
|
|
|
|
final boolean isVideoOnly = videoStreamsAdapter.getItem(selectedVideoIndex).isVideoOnly();
|
|
|
|
|
|
|
|
dialogBinding.audioTrackSpinner.setVisibility(
|
|
|
|
isVideoOnly && wrappedAudioTracks.size() > 1 ? View.VISIBLE : View.GONE);
|
2023-05-02 00:11:09 +02:00
|
|
|
dialogBinding.audioTrackPresentInVideoText.setVisibility(
|
2023-05-01 00:04:04 +02:00
|
|
|
!isVideoOnly && wrappedAudioTracks.size() > 1 ? View.VISIBLE : View.GONE);
|
2020-11-03 05:30:12 +01:00
|
|
|
}
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
private void setupSubtitleSpinner() {
|
|
|
|
if (getContext() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-31 19:20:15 +02:00
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
dialogBinding.qualitySpinner.setAdapter(subtitleStreamsAdapter);
|
|
|
|
dialogBinding.qualitySpinner.setSelection(selectedSubtitleIndex);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.qualitySpinner.setVisibility(View.VISIBLE);
|
2021-07-18 14:22:41 +02:00
|
|
|
setRadioButtonsState(true);
|
2023-03-20 14:12:08 +01:00
|
|
|
dialogBinding.audioStreamSpinner.setVisibility(View.GONE);
|
|
|
|
dialogBinding.audioTrackSpinner.setVisibility(View.GONE);
|
2023-05-02 00:11:09 +02:00
|
|
|
dialogBinding.audioTrackPresentInVideoText.setVisibility(View.GONE);
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2021-07-18 14:22:41 +02:00
|
|
|
// Activity results
|
2020-03-31 19:20:15 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
private void requestDownloadPickAudioFolderResult(final ActivityResult result) {
|
|
|
|
requestDownloadPickFolderResult(
|
|
|
|
result, getString(R.string.download_path_audio_key), DownloadManager.TAG_AUDIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestDownloadPickVideoFolderResult(final ActivityResult result) {
|
|
|
|
requestDownloadPickFolderResult(
|
|
|
|
result, getString(R.string.download_path_video_key), DownloadManager.TAG_VIDEO);
|
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
private void requestDownloadSaveAsResult(@NonNull final ActivityResult result) {
|
2021-06-20 20:14:44 +02:00
|
|
|
if (result.getResultCode() != Activity.RESULT_OK) {
|
2020-06-13 17:29:57 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
if (result.getData() == null || result.getData().getData() == null) {
|
2020-06-13 17:29:57 +02:00
|
|
|
showFailedDialog(R.string.general_error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
if (FilePickerActivityHelper.isOwnFileUri(context, result.getData().getData())) {
|
|
|
|
final File file = Utils.getFileForUri(result.getData().getData());
|
|
|
|
checkSelectedDownload(null, Uri.fromFile(file), file.getName(),
|
|
|
|
StoredFileHelper.DEFAULT_MIME);
|
|
|
|
return;
|
|
|
|
}
|
2019-08-15 03:15:42 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
final DocumentFile docFile = DocumentFile.fromSingleUri(context,
|
|
|
|
result.getData().getData());
|
2021-06-20 20:14:44 +02:00
|
|
|
if (docFile == null) {
|
|
|
|
showFailedDialog(R.string.general_error);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
// check if the selected file was previously used
|
|
|
|
checkSelectedDownload(null, result.getData().getData(), docFile.getName(),
|
|
|
|
docFile.getType());
|
|
|
|
}
|
2020-06-13 17:29:57 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
private void requestDownloadPickFolderResult(@NonNull final ActivityResult result,
|
2021-06-20 20:14:44 +02:00
|
|
|
final String key,
|
|
|
|
final String tag) {
|
|
|
|
if (result.getResultCode() != Activity.RESULT_OK) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-13 17:29:57 +02:00
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
if (result.getData() == null || result.getData().getData() == null) {
|
|
|
|
showFailedDialog(R.string.general_error);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-13 17:29:57 +02:00
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
Uri uri = result.getData().getData();
|
|
|
|
if (FilePickerActivityHelper.isOwnFileUri(context, uri)) {
|
|
|
|
uri = Uri.fromFile(Utils.getFileForUri(uri));
|
|
|
|
} else {
|
|
|
|
context.grantUriPermission(context.getPackageName(), uri,
|
|
|
|
StoredDirectoryHelper.PERMISSION_FLAGS);
|
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(key,
|
|
|
|
uri.toString()).apply();
|
2021-06-20 20:14:44 +02:00
|
|
|
|
|
|
|
try {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
final StoredDirectoryHelper mainStorage = new StoredDirectoryHelper(context, uri, tag);
|
2021-06-20 20:14:44 +02:00
|
|
|
checkSelectedDownload(mainStorage, mainStorage.findFile(filenameTmp),
|
|
|
|
filenameTmp, mimeTmp);
|
|
|
|
} catch (final IOException e) {
|
|
|
|
showFailedDialog(R.string.general_error);
|
2019-04-05 19:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2021-07-18 14:22:41 +02:00
|
|
|
// Listeners
|
2020-03-31 19:20:15 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2017-05-15 05:57:57 +02:00
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onCheckedChanged(final RadioGroup group, @IdRes final int checkedId) {
|
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onCheckedChanged() called with: "
|
|
|
|
+ "group = [" + group + "], checkedId = [" + checkedId + "]");
|
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
boolean flag = true;
|
|
|
|
|
2017-05-15 05:57:57 +02:00
|
|
|
switch (checkedId) {
|
|
|
|
case R.id.audio_button:
|
2018-04-08 13:08:19 +02:00
|
|
|
setupAudioSpinner();
|
2017-05-15 05:57:57 +02:00
|
|
|
break;
|
|
|
|
case R.id.video_button:
|
2018-04-08 13:08:19 +02:00
|
|
|
setupVideoSpinner();
|
2017-05-15 05:57:57 +02:00
|
|
|
break;
|
2018-09-23 20:12:23 +02:00
|
|
|
case R.id.subtitle_button:
|
|
|
|
setupSubtitleSpinner();
|
|
|
|
flag = false;
|
|
|
|
break;
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.threads.setEnabled(flag);
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
public void onItemSelected(final AdapterView<?> parent,
|
|
|
|
final View view,
|
|
|
|
final int position,
|
|
|
|
final long id) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (DEBUG) {
|
|
|
|
Log.d(TAG, "onItemSelected() called with: "
|
|
|
|
+ "parent = [" + parent + "], view = [" + view + "], "
|
|
|
|
+ "position = [" + position + "], id = [" + id + "]");
|
|
|
|
}
|
2023-03-20 14:12:08 +01:00
|
|
|
|
|
|
|
switch (parent.getId()) {
|
|
|
|
case R.id.quality_spinner:
|
|
|
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
|
|
|
case R.id.video_button:
|
|
|
|
selectedVideoIndex = position;
|
|
|
|
onVideoStreamSelected();
|
|
|
|
break;
|
|
|
|
case R.id.subtitle_button:
|
|
|
|
selectedSubtitleIndex = position;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
onItemSelectedSetFileName();
|
2017-05-15 05:57:57 +02:00
|
|
|
break;
|
2023-03-20 14:12:08 +01:00
|
|
|
case R.id.audio_track_spinner:
|
2023-04-21 23:15:37 +02:00
|
|
|
final boolean trackChanged = selectedAudioTrackIndex != position;
|
|
|
|
selectedAudioTrackIndex = position;
|
2023-03-21 16:58:36 +01:00
|
|
|
if (trackChanged) {
|
|
|
|
updateSecondaryStreams();
|
|
|
|
fetchStreamsSize();
|
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
break;
|
2023-03-20 14:12:08 +01:00
|
|
|
case R.id.audio_stream_spinner:
|
|
|
|
selectedAudioIndex = position;
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
2022-12-04 13:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onItemSelectedSetFileName() {
|
2023-01-11 19:45:55 +01:00
|
|
|
final String fileName = FilenameUtils.createFilename(getContext(), currentInfo.getName());
|
|
|
|
final String prevFileName = Optional.ofNullable(dialogBinding.fileName.getText())
|
|
|
|
.map(Object::toString)
|
|
|
|
.orElse("");
|
|
|
|
|
|
|
|
if (prevFileName.isEmpty()
|
|
|
|
|| prevFileName.equals(fileName)
|
|
|
|
|| prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) {
|
|
|
|
// only update the file name field if it was not edited by the user
|
|
|
|
|
|
|
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
|
|
|
case R.id.audio_button:
|
|
|
|
case R.id.video_button:
|
|
|
|
if (!prevFileName.equals(fileName)) {
|
|
|
|
// since the user might have switched between audio and video, the correct
|
|
|
|
// text might already be in place, so avoid resetting the cursor position
|
|
|
|
dialogBinding.fileName.setText(fileName);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case R.id.subtitle_button:
|
|
|
|
final String setSubtitleLanguageCode = subtitleStreamsAdapter
|
|
|
|
.getItem(selectedSubtitleIndex).getLanguageTag();
|
|
|
|
// this will reset the cursor position, which is bad UX, but it can't be avoided
|
|
|
|
dialogBinding.fileName.setText(getString(
|
|
|
|
R.string.caption_file_name, fileName, setSubtitleLanguageCode));
|
|
|
|
break;
|
|
|
|
}
|
2022-12-04 13:29:22 +01:00
|
|
|
}
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 19:20:15 +02:00
|
|
|
public void onNothingSelected(final AdapterView<?> parent) {
|
2017-05-15 05:57:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Download
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2018-04-08 13:08:19 +02:00
|
|
|
protected void setupDownloadOptions() {
|
|
|
|
setRadioButtonsState(false);
|
2023-03-20 14:12:08 +01:00
|
|
|
setupAudioTrackSpinner();
|
2018-04-08 13:08:19 +02:00
|
|
|
|
|
|
|
final boolean isVideoStreamsAvailable = videoStreamsAdapter.getCount() > 0;
|
|
|
|
final boolean isAudioStreamsAvailable = audioStreamsAdapter.getCount() > 0;
|
2018-09-23 20:12:23 +02:00
|
|
|
final boolean isSubtitleStreamsAvailable = subtitleStreamsAdapter.getCount() > 0;
|
2016-04-29 12:40:03 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
dialogBinding.audioButton.setVisibility(isAudioStreamsAvailable ? View.VISIBLE
|
|
|
|
: View.GONE);
|
|
|
|
dialogBinding.videoButton.setVisibility(isVideoStreamsAvailable ? View.VISIBLE
|
|
|
|
: View.GONE);
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.subtitleButton.setVisibility(isSubtitleStreamsAvailable
|
|
|
|
? View.VISIBLE : View.GONE);
|
2018-04-08 13:08:19 +02:00
|
|
|
|
2021-07-18 14:22:41 +02:00
|
|
|
prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
|
2020-07-31 22:19:49 +02:00
|
|
|
final String defaultMedia = prefs.getString(getString(R.string.last_used_download_type),
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
getString(R.string.last_download_type_video_key));
|
2020-07-31 22:19:49 +02:00
|
|
|
|
|
|
|
if (isVideoStreamsAvailable
|
|
|
|
&& (defaultMedia.equals(getString(R.string.last_download_type_video_key)))) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.videoButton.setChecked(true);
|
2020-07-31 22:19:49 +02:00
|
|
|
setupVideoSpinner();
|
|
|
|
} else if (isAudioStreamsAvailable
|
|
|
|
&& (defaultMedia.equals(getString(R.string.last_download_type_audio_key)))) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.audioButton.setChecked(true);
|
2020-07-31 22:19:49 +02:00
|
|
|
setupAudioSpinner();
|
|
|
|
} else if (isSubtitleStreamsAvailable
|
|
|
|
&& (defaultMedia.equals(getString(R.string.last_download_type_subtitle_key)))) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.subtitleButton.setChecked(true);
|
2020-07-31 22:19:49 +02:00
|
|
|
setupSubtitleSpinner();
|
|
|
|
} else if (isVideoStreamsAvailable) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.videoButton.setChecked(true);
|
2018-04-08 13:08:19 +02:00
|
|
|
setupVideoSpinner();
|
|
|
|
} else if (isAudioStreamsAvailable) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.audioButton.setChecked(true);
|
2018-04-08 13:08:19 +02:00
|
|
|
setupAudioSpinner();
|
2018-09-23 20:12:23 +02:00
|
|
|
} else if (isSubtitleStreamsAvailable) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.subtitleButton.setChecked(true);
|
2018-09-23 20:12:23 +02:00
|
|
|
setupSubtitleSpinner();
|
2018-04-08 13:08:19 +02:00
|
|
|
} else {
|
2020-03-31 19:20:15 +02:00
|
|
|
Toast.makeText(getContext(), R.string.no_streams_available_download,
|
|
|
|
Toast.LENGTH_SHORT).show();
|
2021-07-19 10:42:24 +02:00
|
|
|
dismiss();
|
2016-02-17 21:39:41 +01:00
|
|
|
}
|
2015-09-21 21:12:48 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void setRadioButtonsState(final boolean enabled) {
|
2020-11-03 05:30:12 +01:00
|
|
|
dialogBinding.audioButton.setEnabled(enabled);
|
|
|
|
dialogBinding.videoButton.setEnabled(enabled);
|
|
|
|
dialogBinding.subtitleButton.setEnabled(enabled);
|
2018-04-08 13:08:19 +02:00
|
|
|
}
|
2016-04-29 12:40:03 +02:00
|
|
|
|
2023-03-20 14:12:08 +01:00
|
|
|
private StreamSizeWrapper<AudioStream> getWrappedAudioStreams() {
|
2023-04-21 23:15:37 +02:00
|
|
|
if (selectedAudioTrackIndex < 0 || selectedAudioTrackIndex > wrappedAudioTracks.size()) {
|
2023-03-20 14:12:08 +01:00
|
|
|
return StreamSizeWrapper.empty();
|
|
|
|
}
|
2023-04-21 23:15:37 +02:00
|
|
|
return wrappedAudioTracks.getTracksList().get(selectedAudioTrackIndex);
|
2023-03-20 14:12:08 +01:00
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
private int getSubtitleIndexBy(@NonNull final List<SubtitlesStream> streams) {
|
2019-10-28 03:35:51 +01:00
|
|
|
final Localization preferredLocalization = NewPipe.getPreferredLocalization();
|
2018-11-24 04:14:37 +01:00
|
|
|
|
2019-10-28 03:35:51 +01:00
|
|
|
int candidate = 0;
|
2018-11-24 04:14:37 +01:00
|
|
|
for (int i = 0; i < streams.size(); i++) {
|
2019-10-28 03:35:51 +01:00
|
|
|
final Locale streamLocale = streams.get(i).getLocale();
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
final boolean languageEquals = streamLocale.getLanguage() != null
|
|
|
|
&& preferredLocalization.getLanguageCode() != null
|
|
|
|
&& streamLocale.getLanguage()
|
|
|
|
.equals(new Locale(preferredLocalization.getLanguageCode()).getLanguage());
|
|
|
|
final boolean countryEquals = streamLocale.getCountry() != null
|
|
|
|
&& streamLocale.getCountry().equals(preferredLocalization.getCountryCode());
|
2019-10-28 03:35:51 +01:00
|
|
|
|
|
|
|
if (languageEquals) {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (countryEquals) {
|
|
|
|
return i;
|
|
|
|
}
|
2018-11-24 04:14:37 +01:00
|
|
|
|
2019-10-28 03:35:51 +01:00
|
|
|
candidate = i;
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-28 03:35:51 +01:00
|
|
|
return candidate;
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
@NonNull
|
2019-04-05 19:45:39 +02:00
|
|
|
private String getNameEditText() {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
final String str = Objects.requireNonNull(dialogBinding.fileName.getText()).toString()
|
|
|
|
.trim();
|
2019-04-09 23:38:34 +02:00
|
|
|
|
|
|
|
return FilenameUtils.createFilename(context, str.isEmpty() ? currentInfo.getName() : str);
|
2019-04-05 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void showFailedDialog(@StringRes final int msg) {
|
2020-01-31 22:49:43 +01:00
|
|
|
assureCorrectAppLanguage(getContext());
|
2019-04-09 23:38:34 +02:00
|
|
|
new AlertDialog.Builder(context)
|
2019-06-14 17:19:50 +02:00
|
|
|
.setTitle(R.string.general_error)
|
2019-04-05 19:45:39 +02:00
|
|
|
.setMessage(msg)
|
2021-08-30 16:15:26 +02:00
|
|
|
.setNegativeButton(getString(R.string.ok), null)
|
2019-04-05 19:45:39 +02:00
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
2021-06-20 20:14:44 +02:00
|
|
|
private void launchDirectoryPicker(final ActivityResultLauncher<Intent> launcher) {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
NoFileManagerSafeGuard.launchSafe(launcher, StoredDirectoryHelper.getPicker(context), TAG,
|
|
|
|
context);
|
2021-06-20 20:14:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-23 20:12:23 +02:00
|
|
|
private void prepareSelectedDownload() {
|
2020-08-16 10:24:58 +02:00
|
|
|
final StoredDirectoryHelper mainStorage;
|
|
|
|
final MediaFormat format;
|
2020-07-31 22:19:49 +02:00
|
|
|
final String selectedMediaType;
|
2016-02-17 21:39:41 +01:00
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
// first, build the filename and get the output folder (if possible)
|
2019-04-09 23:38:34 +02:00
|
|
|
// later, run a very very very large file checking logic
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2020-06-13 17:29:57 +02:00
|
|
|
filenameTmp = getNameEditText().concat(".");
|
2018-09-23 20:12:23 +02:00
|
|
|
|
2020-11-03 05:30:12 +01:00
|
|
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
2018-09-23 20:12:23 +02:00
|
|
|
case R.id.audio_button:
|
2020-07-31 22:19:49 +02:00
|
|
|
selectedMediaType = getString(R.string.last_download_type_audio_key);
|
2019-04-05 19:45:39 +02:00
|
|
|
mainStorage = mainStorageAudio;
|
|
|
|
format = audioStreamsAdapter.getItem(selectedAudioIndex).getFormat();
|
2020-06-13 17:29:57 +02:00
|
|
|
if (format == MediaFormat.WEBMA_OPUS) {
|
|
|
|
mimeTmp = "audio/ogg";
|
|
|
|
filenameTmp += "opus";
|
2022-06-18 17:40:22 +02:00
|
|
|
} else if (format != null) {
|
|
|
|
mimeTmp = format.mimeType;
|
|
|
|
filenameTmp += format.suffix;
|
2019-12-29 21:56:32 +01:00
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
break;
|
|
|
|
case R.id.video_button:
|
2020-07-31 22:19:49 +02:00
|
|
|
selectedMediaType = getString(R.string.last_download_type_video_key);
|
2019-04-05 19:45:39 +02:00
|
|
|
mainStorage = mainStorageVideo;
|
|
|
|
format = videoStreamsAdapter.getItem(selectedVideoIndex).getFormat();
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
if (format != null) {
|
|
|
|
mimeTmp = format.mimeType;
|
|
|
|
filenameTmp += format.suffix;
|
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
break;
|
|
|
|
case R.id.subtitle_button:
|
2020-07-31 22:19:49 +02:00
|
|
|
selectedMediaType = getString(R.string.last_download_type_subtitle_key);
|
2020-03-31 19:20:15 +02:00
|
|
|
mainStorage = mainStorageVideo; // subtitle & video files go together
|
2019-04-05 19:45:39 +02:00
|
|
|
format = subtitleStreamsAdapter.getItem(selectedSubtitleIndex).getFormat();
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
if (format != null) {
|
|
|
|
mimeTmp = format.mimeType;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format == MediaFormat.TTML) {
|
|
|
|
filenameTmp += MediaFormat.SRT.suffix;
|
2022-05-21 12:02:57 +02:00
|
|
|
} else if (format != null) {
|
|
|
|
filenameTmp += format.suffix;
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
}
|
2018-09-23 20:12:23 +02:00
|
|
|
break;
|
|
|
|
default:
|
2019-04-05 19:45:39 +02:00
|
|
|
throw new RuntimeException("No stream selected");
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
if (!askForSavePath && (mainStorage == null
|
2021-01-16 15:46:50 +01:00
|
|
|
|| mainStorage.isDirect() == NewPipeSettings.useStorageAccessFramework(context)
|
|
|
|
|| mainStorage.isInvalidSafStorage())) {
|
2020-06-13 17:29:57 +02:00
|
|
|
// Pick new download folder if one of:
|
|
|
|
// - Download folder is not set
|
|
|
|
// - Download folder uses SAF while SAF is disabled
|
|
|
|
// - Download folder doesn't use SAF while SAF is enabled
|
2021-01-16 15:46:50 +01:00
|
|
|
// - Download folder uses SAF but the user manually revoked access to it
|
2020-06-13 17:29:57 +02:00
|
|
|
Toast.makeText(context, getString(R.string.no_dir_yet),
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId() == R.id.audio_button) {
|
2021-06-20 20:14:44 +02:00
|
|
|
launchDirectoryPicker(requestDownloadPickAudioFolderLauncher);
|
2020-06-13 17:29:57 +02:00
|
|
|
} else {
|
2021-06-20 20:14:44 +02:00
|
|
|
launchDirectoryPicker(requestDownloadPickVideoFolderLauncher);
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2019-08-02 06:07:37 +02:00
|
|
|
|
2020-06-13 17:29:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (askForSavePath) {
|
2021-06-06 22:15:32 +02:00
|
|
|
final Uri initialPath;
|
2019-08-17 18:38:33 +02:00
|
|
|
if (NewPipeSettings.useStorageAccessFramework(context)) {
|
2021-06-06 22:15:32 +02:00
|
|
|
initialPath = null;
|
2019-08-15 04:00:11 +02:00
|
|
|
} else {
|
2020-06-13 17:29:57 +02:00
|
|
|
final File initialSavePath;
|
2020-11-03 05:30:12 +01:00
|
|
|
if (dialogBinding.videoAudioGroup.getCheckedRadioButtonId() == R.id.audio_button) {
|
2019-08-15 04:00:11 +02:00
|
|
|
initialSavePath = NewPipeSettings.getDir(Environment.DIRECTORY_MUSIC);
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
2019-08-15 04:00:11 +02:00
|
|
|
initialSavePath = NewPipeSettings.getDir(Environment.DIRECTORY_MOVIES);
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2021-06-06 22:15:32 +02:00
|
|
|
initialPath = Uri.parse(initialSavePath.getAbsolutePath());
|
2019-08-15 04:00:11 +02:00
|
|
|
}
|
2019-08-15 03:15:42 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
NoFileManagerSafeGuard.launchSafe(requestDownloadSaveAsLauncher,
|
|
|
|
StoredFileHelper.getNewPicker(context, filenameTmp, mimeTmp, initialPath), TAG,
|
|
|
|
context);
|
2020-06-13 17:29:57 +02:00
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
return;
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
// check for existing file with the same name
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
checkSelectedDownload(mainStorage, mainStorage.findFile(filenameTmp), filenameTmp,
|
|
|
|
mimeTmp);
|
2020-07-31 22:19:49 +02:00
|
|
|
|
|
|
|
// remember the last media type downloaded by the user
|
2020-06-13 17:29:57 +02:00
|
|
|
prefs.edit().putString(getString(R.string.last_used_download_type), selectedMediaType)
|
2020-07-31 22:19:49 +02:00
|
|
|
.apply();
|
2019-04-09 23:38:34 +02:00
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void checkSelectedDownload(final StoredDirectoryHelper mainStorage,
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
final Uri targetFile,
|
|
|
|
final String filename,
|
2020-03-31 19:20:15 +02:00
|
|
|
final String mime) {
|
2019-04-05 19:45:39 +02:00
|
|
|
StoredFileHelper storage;
|
2019-04-09 23:38:34 +02:00
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
try {
|
2019-04-09 23:38:34 +02:00
|
|
|
if (mainStorage == null) {
|
|
|
|
// using SAF on older android version
|
|
|
|
storage = new StoredFileHelper(context, null, targetFile, "");
|
|
|
|
} else if (targetFile == null) {
|
|
|
|
// the file does not exist, but it is probably used in a pending download
|
2020-03-31 19:20:15 +02:00
|
|
|
storage = new StoredFileHelper(mainStorage.getUri(), filename, mime,
|
|
|
|
mainStorage.getTag());
|
2019-04-09 23:38:34 +02:00
|
|
|
} else {
|
|
|
|
// the target filename is already use, attempt to use it
|
2020-03-31 19:20:15 +02:00
|
|
|
storage = new StoredFileHelper(context, mainStorage.getUri(), targetFile,
|
|
|
|
mainStorage.getTag());
|
2019-04-09 23:38:34 +02:00
|
|
|
}
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final Exception e) {
|
2021-12-01 09:43:24 +01:00
|
|
|
ErrorUtil.createNotification(requireContext(),
|
2020-12-11 14:55:47 +01:00
|
|
|
new ErrorInfo(e, UserAction.DOWNLOAD_FAILED, "Getting storage"));
|
2019-04-05 19:45:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-17 20:28:15 +01:00
|
|
|
// get state of potential mission referring to the same file
|
2020-08-16 10:24:58 +02:00
|
|
|
final MissionState state = downloadManager.checkForExistingMission(storage);
|
2021-03-17 20:28:15 +01:00
|
|
|
@StringRes final int msgBtn;
|
|
|
|
@StringRes final int msgBody;
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2021-03-17 20:28:15 +01:00
|
|
|
// this switch checks if there is already a mission referring to the same file
|
2019-04-05 19:45:39 +02:00
|
|
|
switch (state) {
|
2021-03-17 20:28:15 +01:00
|
|
|
case Finished: // there is already a finished mission
|
2019-04-05 19:45:39 +02:00
|
|
|
msgBtn = R.string.overwrite;
|
|
|
|
msgBody = R.string.overwrite_finished_warning;
|
|
|
|
break;
|
|
|
|
case Pending:
|
|
|
|
msgBtn = R.string.overwrite;
|
|
|
|
msgBody = R.string.download_already_pending;
|
|
|
|
break;
|
|
|
|
case PendingRunning:
|
|
|
|
msgBtn = R.string.generate_unique_name;
|
|
|
|
msgBody = R.string.download_already_running;
|
|
|
|
break;
|
2021-03-17 20:28:15 +01:00
|
|
|
case None: // there is no mission referring to the same file
|
2019-04-09 23:38:34 +02:00
|
|
|
if (mainStorage == null) {
|
|
|
|
// This part is called if:
|
|
|
|
// * using SAF on older android version
|
|
|
|
// * save path not defined
|
2019-08-15 04:00:11 +02:00
|
|
|
// * if the file exists overwrite it, is not necessary ask
|
|
|
|
if (!storage.existsAsFile() && !storage.create()) {
|
|
|
|
showFailedDialog(R.string.error_file_creation);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
continueSelectedDownload(storage);
|
|
|
|
return;
|
|
|
|
} else if (targetFile == null) {
|
|
|
|
// This part is called if:
|
|
|
|
// * the filename is not used in a pending/finished download
|
|
|
|
// * the file does not exists, create
|
2019-06-14 17:19:50 +02:00
|
|
|
|
|
|
|
if (!mainStorage.mkdirs()) {
|
|
|
|
showFailedDialog(R.string.error_path_creation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:38:34 +02:00
|
|
|
storage = mainStorage.createFile(filename, mime);
|
|
|
|
if (storage == null || !storage.canWrite()) {
|
|
|
|
showFailedDialog(R.string.error_file_creation);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
continueSelectedDownload(storage);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
msgBtn = R.string.overwrite;
|
|
|
|
msgBody = R.string.overwrite_unrelated_warning;
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-17 20:28:15 +01:00
|
|
|
return; // unreachable
|
2019-04-05 19:45:39 +02:00
|
|
|
}
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final AlertDialog.Builder askDialog = new AlertDialog.Builder(context)
|
2019-04-09 23:38:34 +02:00
|
|
|
.setTitle(R.string.download_dialog_title)
|
2019-04-05 19:45:39 +02:00
|
|
|
.setMessage(msgBody)
|
2021-08-04 18:55:32 +02:00
|
|
|
.setNegativeButton(R.string.cancel, null);
|
2019-04-09 23:38:34 +02:00
|
|
|
final StoredFileHelper finalStorage = storage;
|
|
|
|
|
|
|
|
|
|
|
|
if (mainStorage == null) {
|
|
|
|
// This part is called if:
|
|
|
|
// * using SAF on older android version
|
|
|
|
// * save path not defined
|
|
|
|
switch (state) {
|
|
|
|
case Pending:
|
|
|
|
case Finished:
|
|
|
|
askDialog.setPositiveButton(msgBtn, (dialog, which) -> {
|
|
|
|
dialog.dismiss();
|
|
|
|
downloadManager.forgetMission(finalStorage);
|
|
|
|
continueSelectedDownload(finalStorage);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-12 03:54:10 +02:00
|
|
|
askDialog.show();
|
2019-04-09 23:38:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
askDialog.setPositiveButton(msgBtn, (dialog, which) -> {
|
|
|
|
dialog.dismiss();
|
|
|
|
|
|
|
|
StoredFileHelper storageNew;
|
|
|
|
switch (state) {
|
|
|
|
case Finished:
|
|
|
|
case Pending:
|
|
|
|
downloadManager.forgetMission(finalStorage);
|
|
|
|
case None:
|
|
|
|
if (targetFile == null) {
|
|
|
|
storageNew = mainStorage.createFile(filename, mime);
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
// try take (or steal) the file
|
2020-03-31 19:20:15 +02:00
|
|
|
storageNew = new StoredFileHelper(context, mainStorage.getUri(),
|
|
|
|
targetFile, mainStorage.getTag());
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final IOException e) {
|
2020-03-31 19:20:15 +02:00
|
|
|
Log.e(TAG, "Failed to take (or steal) the file in "
|
|
|
|
+ targetFile.toString());
|
2019-04-09 23:38:34 +02:00
|
|
|
storageNew = null;
|
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (storageNew != null && storageNew.canWrite()) {
|
2019-04-09 23:38:34 +02:00
|
|
|
continueSelectedDownload(storageNew);
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
2019-04-09 23:38:34 +02:00
|
|
|
showFailedDialog(R.string.error_file_creation);
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
break;
|
|
|
|
case PendingRunning:
|
|
|
|
storageNew = mainStorage.createUniqueFile(filename, mime);
|
2020-03-31 19:20:15 +02:00
|
|
|
if (storageNew == null) {
|
2019-04-09 23:38:34 +02:00
|
|
|
showFailedDialog(R.string.error_file_creation);
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
2019-04-09 23:38:34 +02:00
|
|
|
continueSelectedDownload(storageNew);
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2019-04-09 23:38:34 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-07-12 03:54:10 +02:00
|
|
|
askDialog.show();
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
private void continueSelectedDownload(@NonNull final StoredFileHelper storage) {
|
2019-04-05 19:45:39 +02:00
|
|
|
if (!storage.canWrite()) {
|
|
|
|
showFailedDialog(R.string.permission_denied);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the selected file has to be overwritten, by simply checking its length
|
|
|
|
try {
|
2020-03-31 19:20:15 +02:00
|
|
|
if (storage.length() > 0) {
|
|
|
|
storage.truncate();
|
|
|
|
}
|
2020-08-16 10:24:58 +02:00
|
|
|
} catch (final IOException e) {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
Log.e(TAG, "Failed to truncate the file: " + storage.getUri().toString(), e);
|
2019-04-05 19:45:39 +02:00
|
|
|
showFailedDialog(R.string.overwrite_failed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final Stream selectedStream;
|
2019-09-28 23:11:05 +02:00
|
|
|
Stream secondaryStream = null;
|
2020-08-16 10:24:58 +02:00
|
|
|
final char kind;
|
2020-11-03 05:30:12 +01:00
|
|
|
int threads = dialogBinding.threads.getProgress() + 1;
|
2020-08-16 10:24:58 +02:00
|
|
|
final String[] urls;
|
|
|
|
final MissionRecoveryInfo[] recoveryInfo;
|
2018-09-23 20:12:23 +02:00
|
|
|
String psName = null;
|
|
|
|
String[] psArgs = null;
|
2018-11-20 23:10:50 +01:00
|
|
|
long nearLength = 0;
|
2018-09-23 20:12:23 +02:00
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
// more download logic: select muxer, subtitle converter, etc.
|
2020-11-03 05:30:12 +01:00
|
|
|
switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) {
|
2019-04-05 19:45:39 +02:00
|
|
|
case R.id.audio_button:
|
|
|
|
kind = 'a';
|
|
|
|
selectedStream = audioStreamsAdapter.getItem(selectedAudioIndex);
|
|
|
|
|
|
|
|
if (selectedStream.getFormat() == MediaFormat.M4A) {
|
|
|
|
psName = Postprocessing.ALGORITHM_M4A_NO_DASH;
|
2019-11-26 17:41:16 +01:00
|
|
|
} else if (selectedStream.getFormat() == MediaFormat.WEBMA_OPUS) {
|
2019-09-24 02:38:29 +02:00
|
|
|
psName = Postprocessing.ALGORITHM_OGG_FROM_WEBM_DEMUXER;
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
break;
|
|
|
|
case R.id.video_button:
|
|
|
|
kind = 'v';
|
|
|
|
selectedStream = videoStreamsAdapter.getItem(selectedVideoIndex);
|
|
|
|
|
2020-08-16 10:24:58 +02:00
|
|
|
final SecondaryStreamHelper<AudioStream> secondary = videoStreamsAdapter
|
2019-04-05 19:45:39 +02:00
|
|
|
.getAllSecondary()
|
|
|
|
.get(wrappedVideoStreams.getStreamsList().indexOf(selectedStream));
|
|
|
|
|
2019-09-28 23:11:05 +02:00
|
|
|
if (secondary != null) {
|
|
|
|
secondaryStream = secondary.getStream();
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
if (selectedStream.getFormat() == MediaFormat.MPEG_4) {
|
2019-04-05 19:45:39 +02:00
|
|
|
psName = Postprocessing.ALGORITHM_MP4_FROM_DASH_MUXER;
|
2020-03-31 19:20:15 +02:00
|
|
|
} else {
|
2019-04-05 19:45:39 +02:00
|
|
|
psName = Postprocessing.ALGORITHM_WEBM_MUXER;
|
2020-03-31 19:20:15 +02:00
|
|
|
}
|
2019-04-05 19:45:39 +02:00
|
|
|
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
final long videoSize = wrappedVideoStreams.getSizeInBytes(
|
|
|
|
(VideoStream) selectedStream);
|
2019-04-05 19:45:39 +02:00
|
|
|
|
2019-04-25 05:34:29 +02:00
|
|
|
// set nearLength, only, if both sizes are fetched or known. This probably
|
|
|
|
// does not work on slow networks but is later updated in the downloader
|
2019-09-28 23:11:05 +02:00
|
|
|
if (secondary.getSizeInBytes() > 0 && videoSize > 0) {
|
|
|
|
nearLength = secondary.getSizeInBytes() + videoSize;
|
2019-04-05 19:45:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case R.id.subtitle_button:
|
2020-03-31 19:20:15 +02:00
|
|
|
threads = 1; // use unique thread for subtitles due small file size
|
2019-04-05 19:45:39 +02:00
|
|
|
kind = 's';
|
|
|
|
selectedStream = subtitleStreamsAdapter.getItem(selectedSubtitleIndex);
|
|
|
|
|
|
|
|
if (selectedStream.getFormat() == MediaFormat.TTML) {
|
|
|
|
psName = Postprocessing.ALGORITHM_TTML_CONVERTER;
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
psArgs = new String[] {
|
2019-04-05 19:45:39 +02:00
|
|
|
selectedStream.getFormat().getSuffix(),
|
2020-03-31 19:20:15 +02:00
|
|
|
"false" // ignore empty frames
|
2019-04-05 19:45:39 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2018-09-23 20:12:23 +02:00
|
|
|
}
|
2016-02-17 21:39:41 +01:00
|
|
|
|
2019-09-28 23:11:05 +02:00
|
|
|
if (secondaryStream == null) {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
urls = new String[] {
|
|
|
|
selectedStream.getContent()
|
2019-09-28 23:11:05 +02:00
|
|
|
};
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
recoveryInfo = new MissionRecoveryInfo[] {
|
2019-09-28 23:11:05 +02:00
|
|
|
new MissionRecoveryInfo(selectedStream)
|
|
|
|
};
|
2017-12-08 15:05:08 +01:00
|
|
|
} else {
|
2022-06-18 17:40:22 +02:00
|
|
|
if (secondaryStream.getDeliveryMethod() != PROGRESSIVE_HTTP) {
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
throw new IllegalArgumentException("Unsupported stream delivery format"
|
|
|
|
+ secondaryStream.getDeliveryMethod());
|
|
|
|
}
|
|
|
|
|
|
|
|
urls = new String[] {
|
|
|
|
selectedStream.getContent(), secondaryStream.getContent()
|
2019-09-28 23:11:05 +02:00
|
|
|
};
|
Add support of other delivery methods than progressive HTTP (in the player only)
Detailed changes:
- External players:
- Add a message instruction about stream selection;
- Add a message when there is no stream available for external players;
- Return now HLS, DASH and SmoothStreaming URL contents, in addition to progressive HTTP ones.
- Player:
- Support DASH, HLS and SmoothStreaming streams for videos, whether they are content URLs or the manifests themselves, in addition to progressive HTTP ones;
- Use a custom HttpDataSource to play YouTube contents, based of ExoPlayer's default one, which allows better spoofing of official clients (custom user-agent and headers (depending of the client used), use of range and rn (set dynamically by the DataSource) parameters);
- Fetch YouTube progressive contents as DASH streams, like official clients, support fully playback of livestreams which have ended recently and OTF streams;
- Use ExoPlayer's default retries count for contents on non-fatal errors (instead of Integer.MAX_VALUE for non-live contents and 5 for live contents).
- Download dialog:
- Add message about support of progressive HTTP streams only for downloading;
- Remove several duplicated code and update relevant usages;
- Support downloading of contents with an unknown media format.
- ListHelper:
- Catch NumberFormatException when trying to compare two video streams between them.
- Tests:
- Update ListHelperTest and StreamItemAdapterTest to fix breaking changes in the extractor.
- Other places:
- Fixes deprecation of changes made in the extractor;
- Improve some code related to the files changed.
- Issues fixed and/or improved with the changes:
- Seeking of PeerTube HLS streams (the duration shown was the one from the stream duration and not the one parsed, incomplete because HLS streams are fragmented MP4s with multiple sidx boxes, for which seeking is not supported by ExoPlayer) (the app now uses the HLS manifest returned for each quality, in the master playlist (not fetched and computed by the extractor));
- Crash when loading PeerTube streams with a separated audio;
- Lack of some streams on some YouTube videos (OTF streams);
- Loading times of YouTube streams, after a quality change or a playback start;
- View count of YouTube ended livestreams interpreted as watching count (this type of streams is not interpreted anymore as livestreams);
- Watchable time of YouTube ended livestreams;
- Playback of SoundCloud HLS-only tracks (which cannot be downloaded anymore because the workaround which was used is being removed by SoundCloud, so it has been removed from the extractor).
2022-06-16 11:13:19 +02:00
|
|
|
recoveryInfo = new MissionRecoveryInfo[] {new MissionRecoveryInfo(selectedStream),
|
2020-03-31 19:20:15 +02:00
|
|
|
new MissionRecoveryInfo(secondaryStream)};
|
2017-12-08 15:05:08 +01:00
|
|
|
}
|
2016-03-25 19:01:22 +01:00
|
|
|
|
2020-03-31 19:20:15 +02:00
|
|
|
DownloadManagerService.startMission(context, urls, storage, kind, threads,
|
|
|
|
currentInfo.getUrl(), psName, psArgs, nearLength, recoveryInfo);
|
2018-04-08 13:08:19 +02:00
|
|
|
|
2021-04-22 04:45:04 +02:00
|
|
|
Toast.makeText(context, getString(R.string.download_has_started),
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
2019-04-05 19:45:39 +02:00
|
|
|
dismiss();
|
2016-02-17 21:39:41 +01:00
|
|
|
}
|
2015-09-21 21:12:48 +02:00
|
|
|
}
|