From 9b8de51fa0c11a03543cd6205c93a8e934390ba5 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:53:33 +0530 Subject: [PATCH 1/9] Update Android Gradle Plugin to 7.3.1 and clojars Maven URL Update Gradle to 7.5.1 Update Desugaring to 1.1.8 change application id to newpipelegacy --- app/build.gradle | 6 +++--- app/src/debug/AndroidManifest.xml | 6 ++---- app/src/main/AndroidManifest.xml | 4 +++- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 6 ++++++ gradlew.bat | 14 ++++++++------ 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 347a1398c..dba27db08 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,10 +9,10 @@ plugins { android { compileSdk 31 - buildToolsVersion '30.0.3' + namespace 'org.schabi.newpipelegacy' defaultConfig { - applicationId "org.schabi.newpipe" + applicationId "org.schabi.newpipelegacy" resValue "string", "app_name", "NewPipe" minSdk 16 targetSdk 29 @@ -184,7 +184,7 @@ sonarqube { dependencies { /** Desugaring **/ - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.6' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8' /** NewPipe libraries **/ // You can use a local version by uncommenting a few lines in settings.gradle diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml index 1c25999d2..02a0f6c74 100644 --- a/app/src/debug/AndroidManifest.xml +++ b/app/src/debug/AndroidManifest.xml @@ -1,8 +1,6 @@ - + @@ -14,6 +13,9 @@ + /dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f93..53a6b238d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal From dd1cc34c1c26a4a0b1a70f845572af145f1129b7 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:36:48 +0530 Subject: [PATCH 2/9] Use nio package of desugar_jdk_libs_nio 2.0.1 update kotlin_version to '1.8.20' AGP to 7.4.0 To use NewPipe Extractor in Android projects the minSdk is below 19, the desugar_jdk_libs_nio artifact is required, which requires Android Gradle Plugin (AGP) version 7.4.0 --- app/build.gradle | 2 +- build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index dba27db08..f4e8c4bbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -184,7 +184,7 @@ sonarqube { dependencies { /** Desugaring **/ - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.8' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_neo:2.0.1' /** NewPipe libraries **/ // You can use a local version by uncommenting a few lines in settings.gradle diff --git a/build.gradle b/build.gradle index d2f1dc4c5..d199d60f8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.8.20' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' + classpath 'com.android.tools.build:gradle:7.4.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong From b980d6b05b8f842661bd7798dd612d3a8f0df087 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 16:05:24 +0530 Subject: [PATCH 3/9] fix typo in the desugar_jdk_libs_nio library --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index f4e8c4bbe..33fae4068 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -184,7 +184,7 @@ sonarqube { dependencies { /** Desugaring **/ - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_neo:2.0.1' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.1' /** NewPipe libraries **/ // You can use a local version by uncommenting a few lines in settings.gradle From ebd1a95f7e3ecda350984cc7898a8dc2381bfe03 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:55:25 +0530 Subject: [PATCH 4/9] Use kotlin_version 1.6.21 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d199d60f8..1384d0a9c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.8.20' + ext.kotlin_version = '1.6.21' repositories { google() mavenCentral() From da597c62fae7bd8a16e5a6d467b3d009aab42388 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:20:53 +0530 Subject: [PATCH 5/9] Update desugar_jdk_libs_nio to 2.0.3 androidxRoomVersion to 2.4.3 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 33fae4068..36a47c9a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -103,7 +103,7 @@ ext { checkstyleVersion = '10.3.1' androidxLifecycleVersion = '2.3.1' - androidxRoomVersion = '2.4.2' + androidxRoomVersion = '2.4.3' androidxWorkVersion = '2.7.1' icepickVersion = '3.2.0' @@ -184,7 +184,7 @@ sonarqube { dependencies { /** Desugaring **/ - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.1' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.0.3' /** NewPipe libraries **/ // You can use a local version by uncommenting a few lines in settings.gradle From d5f6960de4f7d4b7fa6949406bf78819fea114f2 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:32:10 +0530 Subject: [PATCH 6/9] Add conscrypt to fix soundcloud mediacc not working on Jellybean Kitkat devices thanks to @evermind-zz for BraveNewPipeLegacy Conscrypt implementation Co-Authored-By: evermind-zz <55653+evermind-zz@users.noreply.github.com> --- app/build.gradle | 3 +++ app/proguard-rules.pro | 3 +++ app/src/main/java/org/schabi/newpipelegacy/App.java | 4 ++++ .../org/schabi/newpipelegacy/util/TLSSocketFactoryCompat.java | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 36a47c9a0..0b8856b83 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -286,6 +286,9 @@ dependencies { // Date and time formatting implementation "org.ocpsoft.prettytime:prettytime:5.0.8.Final" + // Conscrypt libraries + implementation "org.conscrypt:conscrypt-android:2.5.2" + /** Debugging **/ // Memory leak detection implementation "com.squareup.leakcanary:leakcanary-object-watcher-android:${leakCanaryVersion}" diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 589143ccc..b6e7cc0de 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -46,6 +46,9 @@ private void writeObject(java.io.ObjectOutputStream); private void readObject(java.io.ObjectInputStream); } +# conscrypt rules +-dontwarn com.android.org.conscrypt.SSLParametersImpl +-dontwarn org.apache.harmony.xnet.provider.jsse.SSLParametersImpl # for some reason NotificationModeConfigFragment wasn't kept (only referenced in a preference xml) -keep class org.schabi.newpipelegacy.settings.notifications.** { *; } diff --git a/app/src/main/java/org/schabi/newpipelegacy/App.java b/app/src/main/java/org/schabi/newpipelegacy/App.java index d7667ae5e..3b287a87b 100644 --- a/app/src/main/java/org/schabi/newpipelegacy/App.java +++ b/app/src/main/java/org/schabi/newpipelegacy/App.java @@ -14,6 +14,7 @@ import org.acra.ACRA; import org.acra.config.CoreConfigurationBuilder; +import org.conscrypt.Conscrypt; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.downloader.Downloader; import org.schabi.newpipelegacy.error.ReCaptchaActivity; @@ -27,6 +28,7 @@ import java.io.IOException; import java.io.InterruptedIOException; import java.net.SocketException; +import java.security.Security; import java.util.List; import java.util.Objects; @@ -77,6 +79,8 @@ public void onCreate() { app = this; + Security.insertProviderAt(Conscrypt.newProvider(), 1); + if (ProcessPhoenix.isPhoenixProcess(this)) { Log.i(TAG, "This is a phoenix process! " + "Aborting initialization of App[onCreate]"); diff --git a/app/src/main/java/org/schabi/newpipelegacy/util/TLSSocketFactoryCompat.java b/app/src/main/java/org/schabi/newpipelegacy/util/TLSSocketFactoryCompat.java index fad1edb3a..19a9baf85 100644 --- a/app/src/main/java/org/schabi/newpipelegacy/util/TLSSocketFactoryCompat.java +++ b/app/src/main/java/org/schabi/newpipelegacy/util/TLSSocketFactoryCompat.java @@ -107,7 +107,7 @@ public Socket createSocket(final InetAddress address, final int port, private Socket enableTLSOnSocket(final Socket socket) { if (socket instanceof SSLSocket) { - ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.1", "TLSv1.2"}); + ((SSLSocket) socket).setEnabledProtocols(new String[]{"TLSv1.2", "TLSv1.3"}); } return socket; } From 662ff330676fdbc7930ccafe7bc58e963df847e2 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:38:14 +0530 Subject: [PATCH 7/9] Support audio only background for services only supporting video streams Some services may only have video streams and no separate audio streams available. This commit will add audio background playback support for those services. It uses the video source as audio source for background playback. Co-Authored-By: evermind-zz <55653+evermind-zz@users.noreply.github.com> --- .../resolver/AudioPlaybackResolver.java | 40 +++++++++++++++++-- .../player/resolver/PlaybackResolver.java | 20 ++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipelegacy/player/resolver/AudioPlaybackResolver.java b/app/src/main/java/org/schabi/newpipelegacy/player/resolver/AudioPlaybackResolver.java index a11528af2..c665bdb48 100644 --- a/app/src/main/java/org/schabi/newpipelegacy/player/resolver/AudioPlaybackResolver.java +++ b/app/src/main/java/org/schabi/newpipelegacy/player/resolver/AudioPlaybackResolver.java @@ -11,7 +11,9 @@ import com.google.android.exoplayer2.source.MediaSource; import org.schabi.newpipe.extractor.stream.AudioStream; +import org.schabi.newpipe.extractor.stream.Stream; import org.schabi.newpipe.extractor.stream.StreamInfo; +import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipelegacy.player.helper.PlayerDataSource; import org.schabi.newpipelegacy.player.mediaitem.MediaItemTag; import org.schabi.newpipelegacy.player.mediaitem.StreamInfoTag; @@ -43,20 +45,50 @@ public MediaSource resolve(@NonNull final StreamInfo info) { final List audioStreams = getNonTorrentStreams(info.getAudioStreams()); - final int index = ListHelper.getDefaultAudioFormat(context, audioStreams); - if (index < 0 || index >= info.getAudioStreams().size()) { + final Stream stream = getAudioSource(info); + if (stream == null) { return null; } - final AudioStream audio = info.getAudioStreams().get(index); final MediaItemTag tag = StreamInfoTag.of(info); try { return PlaybackResolver.buildMediaSource( - dataSource, audio, info, PlaybackResolver.cacheKeyOf(info, audio), tag); + dataSource, stream, info, PlaybackResolver.cacheKeyOf(info, stream), tag); } catch (final ResolverException e) { Log.e(TAG, "Unable to create audio source", e); return null; } } + + /** + * Get a stream to be played as audio. If a service has no separate {@link AudioStream}s we + * use a video stream as audio source to support audio background playback. + * + * @param info of the stream + * @return the audio source to use or null if none could be found + */ + @Nullable + private Stream getAudioSource(@NonNull final StreamInfo info) { + final List audioStreams = getNonTorrentStreams(info.getAudioStreams()); + if (!audioStreams.isEmpty()) { + final int index = ListHelper.getDefaultAudioFormat(context, audioStreams); + return getStreamForIndex(index, audioStreams); + } else { + final List videoStreams = getNonTorrentStreams(info.getVideoStreams()); + if (!videoStreams.isEmpty()) { + final int index = ListHelper.getDefaultResolutionIndex(context, videoStreams); + return getStreamForIndex(index, videoStreams); + } + } + return null; + } + + @Nullable + Stream getStreamForIndex(final int index, @NonNull final List streams) { + if (index >= 0 && index < streams.size()) { + return streams.get(index); + } + return null; + } } diff --git a/app/src/main/java/org/schabi/newpipelegacy/player/resolver/PlaybackResolver.java b/app/src/main/java/org/schabi/newpipelegacy/player/resolver/PlaybackResolver.java index a2ed70144..751e729e3 100644 --- a/app/src/main/java/org/schabi/newpipelegacy/player/resolver/PlaybackResolver.java +++ b/app/src/main/java/org/schabi/newpipelegacy/player/resolver/PlaybackResolver.java @@ -158,6 +158,26 @@ static String cacheKeyOf(final StreamInfo info, final AudioStream audioStream) { return cacheKey.toString(); } + + /** + * Use common base type {@link Stream} to handle {@link AudioStream} or {@link VideoStream} + * transparently. For more info see {@link #cacheKeyOf(StreamInfo, AudioStream)} or + * {@link #cacheKeyOf(StreamInfo, VideoStream)}. + * + * @param info the {@link StreamInfo stream info}, to distinguish between streams with + * the same features but coming from different stream infos + * @param stream the {@link Stream} ({@link AudioStream} or {@link VideoStream}) + * for which the cache key should be created + * @return a key to be used to store the cache of the provided {@link Stream} + */ + static String cacheKeyOf(final StreamInfo info, final Stream stream) { + if (stream instanceof AudioStream) { + return cacheKeyOf(info, (AudioStream) stream); + } else if (stream instanceof VideoStream) { + return cacheKeyOf(info, (VideoStream) stream); + } + throw new RuntimeException("no audio or video stream. That should never happen"); + } //endregion From de6aaa26f4fcae030d7f71a258ebc004a3d91b2b Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Sun, 14 Jul 2024 14:42:29 +0530 Subject: [PATCH 8/9] set 'playback in background button' visible if there are videostreams Co-Authored-By: evermind-zz <55653+evermind-zz@users.noreply.github.com> --- .../newpipelegacy/fragments/detail/VideoDetailFragment.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipelegacy/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipelegacy/fragments/detail/VideoDetailFragment.java index 6a66f6241..08e6b29e0 100644 --- a/app/src/main/java/org/schabi/newpipelegacy/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipelegacy/fragments/detail/VideoDetailFragment.java @@ -1664,8 +1664,9 @@ public void handleResult(@NonNull final StreamInfo info) { binding.detailControlsDownload.setVisibility( StreamTypeUtil.isLiveStream(info.getStreamType()) ? View.GONE : View.VISIBLE); - binding.detailControlsBackground.setVisibility(info.getAudioStreams().isEmpty() - ? View.GONE : View.VISIBLE); + binding.detailControlsBackground.setVisibility( + info.getAudioStreams().isEmpty() && info.getVideoStreams().isEmpty() + ? View.GONE : View.VISIBLE); final boolean noVideoStreams = info.getVideoStreams().isEmpty() && info.getVideoOnlyStreams().isEmpty(); From b37482e95a6a8c9e943597eb4921f36641eb3f80 Mon Sep 17 00:00:00 2001 From: ShareASmile <60492161+ShareASmile@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:45:23 +0530 Subject: [PATCH 9/9] change app name to "NewPipe flora" & update kotlin_version to 1.8.20 --- app/build.gradle | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 42055c4c4..173b86784 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' archivesBaseName = 'app' applicationIdSuffix ".flora" - resValue "string", "app_name", "NewPipe " + "Flora" + resValue "string", "app_name", "NewPipe " + "flora" } } diff --git a/build.gradle b/build.gradle index 1384d0a9c..d199d60f8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.8.20' repositories { google() mavenCentral()