Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network error when using bg-helper #7114

Open
3 tasks done
agevlakh opened this issue Feb 19, 2025 · 16 comments
Open
3 tasks done

network error when using bg-helper #7114

agevlakh opened this issue Feb 19, 2025 · 16 comments
Labels
bug Something isn't working help wanted Looking for help

Comments

@agevlakh
Copy link

Steps to reproduce

  1. setup bg-helper on your piped instance
  2. play video on libretube on your instance
  3. see network error

Expected behavior

playing video without issues

Actual behavior

network error

LibreTube version

0.27.0

Android version

android 15

Other details

fox fix IOS player response is not valid in this post setup bg-helper. it fixed error in web browser, but broke playing in libretube, see network error

Acknowledgements

  • I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open issue.
  • I have written a short but informative title.
  • I will fill out all of the requested information in this form.
@agevlakh agevlakh added the bug Something isn't working label Feb 19, 2025
@FineFindus
Copy link
Contributor

Have you tried to disable HLS (Settings > Audio and video)? It's currently broken when using together with poTokens.

@Figim
Copy link

Figim commented Feb 23, 2025

Have you tried to disable HLS (Settings > Audio and video)? It's currently broken when using together with poTokens.

There seems to be a problem with Piped Instances. Would it be better if this issue was discussed in the Piped repo?

Everything is fine when I turn off the proxy

@agevlakh
Copy link
Author

Have you tried to disable HLS (Settings > Audio and video)? It's currently broken when using together with poTokens.

When I did it, I have source error while play video

@Figim
Copy link

Figim commented Feb 23, 2025

Have you tried to disable HLS (Settings > Audio and video)? It's currently broken when using together with poTokens.

When I did it, I have source error while play video

This is an http 403 error. There will be no fix for this for instances either. (I don't think it's possible) But this is fixed in the proxyless version

@ValentinsParamonovs
Copy link

The Network error message originates from com.github.libretube.services.OnlinePlayerService:301. It is shown due to no HLS/DASH/LBRY streams being present in the response from /streams/<video_id>.

I don't know if it's the logic inside the bg-helper to blame or if it's YT that comes up with this responses, but, with bg-helper active, the responses contain playable links only in videoStreams and audioStreams lists.

I hacked together a primitive solution to play these:

diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt
index 9f31d3dd6..084bc2ae9 100644
--- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt
+++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt
@@ -10,6 +10,8 @@ import androidx.media3.common.MimeTypes
 import androidx.media3.common.Player
 import androidx.media3.datasource.DefaultDataSource
 import androidx.media3.exoplayer.hls.HlsMediaSource
+import androidx.media3.exoplayer.source.MergingMediaSource
+import androidx.media3.exoplayer.source.ProgressiveMediaSource
 import com.github.libretube.R
 import com.github.libretube.api.JsonHelper
 import com.github.libretube.api.RetrofitInstance
@@ -296,6 +298,26 @@ open class OnlinePlayerService : AbstractPlayerService() {
                 exoPlayer?.setMediaSource(mediaSource)
                 return
             }
+            streams.videoStreams.isNotEmpty() -> {
+                val pmsFactory = ProgressiveMediaSource.Factory(DefaultDataSource.Factory(this))
+
+                val videoItem = createMediaItem(
+                    streams.videoStreams[0].url!!.toUri(),
+                    streams.videoStreams[0].mimeType!!,
+                    streams
+                )
+                val videoSource = pmsFactory.createMediaSource(videoItem)
+
+                val audioItem = createMediaItem(
+                    streams.audioStreams[0].url!!.toUri(),
+                    streams.audioStreams[0].mimeType!!,
+                    streams
+                )
+                val audioSource = pmsFactory.createMediaSource(audioItem)
+
+                exoPlayer?.setMediaSource(MergingMediaSource(videoSource, audioSource))
+                return
+            }
             // NO STREAM FOUND
             else -> {
                 toastFromMainThread(R.string.unknown_error)

It takes the first stream from videoStreams and the first stream from audioStreams and slaps them together into a single media source (I've no idea if ProgressiveMediaSource is a suitable choice for this).

But these video/audio links are not streamable (AFAIU) and thus the video takes a long time to load.

@agevlakh
Copy link
Author

There will be no fix for this for instances either

why won't there be a fix? are there any technical difficulties? as I understand it, it turned out that Piped selfhosted does not work without bg-helper due to some new features of YouTube. Isn't it logical to adapt the application to the features of using bg-helper. I don't know about others, but personally I don't see any point in using this application without Piped selfhosted. But I'm not a programmer and I really like the application. and I think there are many other people whose usage scenario is similar to mine.

@Figim
Copy link

Figim commented Feb 25, 2025

There will be no fix for this for instances either

why won't there be a fix? are there any technical difficulties? as I understand it, it turned out that Piped selfhosted does not work without bg-helper due to some new features of YouTube. Isn't it logical to adapt the application to the features of using bg-helper. I don't know about others, but personally I don't see any point in using this application without Piped selfhosted. But I'm not a programmer and I really like the application. and I think there are many other people whose usage scenario is similar to mine.

LibreTube now offers two methods. Proxy or proxyless options. The proxy option is not stable. But many users want Stability. LibreTube is a stable, easy and versatile application. If you don't want it, don't use it. I didn't say that the issue wouldn't be considered for resolution. It still protects you from , ads, and tracking. Offers secure streaming. Easier interface. The app is pretty much perfect. 👌

@agevlakh
Copy link
Author

I totally agree with you. The app is great. Thank you very much for your work. I think it's one of the best apps for YouTube.
But since I encounter YouTube blocking, this application helps me work with YouTube through piped without using VPN, which is very convenient

@mebitek
Copy link

mebitek commented Feb 25, 2025

same situation here.
selfhosted with bg-helper, works perfect on browser but form my android I get the network error.

@Bnyro
Copy link
Member

Bnyro commented Feb 27, 2025

The Network error message originates from com.github.libretube.services.OnlinePlayerService:301. It is shown due to no HLS/DASH/LBRY streams being present in the response from /streams/<video_id>.

I don't know if it's the logic inside the bg-helper to blame or if it's YT that comes up with this responses, but, with bg-helper active, the responses contain playable links only in videoStreams and audioStreams lists.

We do create our own DASH manifests using videoStreams and audioStreams in that case (if Use HLS in the instance settings is disabled): see https://github.com/libre-tube/LibreTube/blob/master/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt#L269 and https://github.com/libre-tube/LibreTube/blob/master/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt#L278 (ignore the comment at the line before, that's outdated, forgot to remove it). Have you tried to just adapt the conditions there to always go into the DASH case (or just set the mentioned setting accordingly)?

But these video/audio links are not streamable (AFAIU) and thus the video takes a long time to load.

In theory all streams should be streamable using Range headers, I think it would however require creating a custom MediaSource implementation. The reason that it's slow as of right now is because YouTube ratelimits connections that don't use proper Range headers and segmented requests. (Tbh I don't know how ProgressiveMediaSource works internally, but it certainly doesn't do that)

My whole IP range that I used for testing got IP banned, so I'm unfortunately not really able to help much here.

@agevlakh
Copy link
Author

agevlakh commented Mar 1, 2025

I updated all Piped docker images. libretube is now working

@Alifoss
Copy link

Alifoss commented Mar 1, 2025

I've updated piped-backend and libretube, i have this piped configuration for over a year now. After updating both, libretube returns Network error on every video using HLS as how i used it for the last year. When disabling HLS and using DASH, libretube works but almost every video abruptly stops playing after some minutes. Am i missing something here? Am i supposed to add bg-helper to my instance with these new changes?

@agevlakh
Copy link
Author

agevlakh commented Mar 1, 2025

@Alifoss In this thread I described the error after updating Piped. Maybe it is somehow related to your error.

@drJeckyll
Copy link

I've updated piped-backend and libretube, i have this piped configuration for over a year now. After updating both, libretube returns Network error on every video using HLS as how i used it for the last year. When disabling HLS and using DASH, libretube works but almost every video abruptly stops playing after some minutes. Am i missing something here? Am i supposed to add bg-helper to my instance with these new changes?

I don't think this is LibreTube issue, since I see same thing happening on my private piped instance playing from browser. After about a minute piped proxy requests start to fail with "Reason: CORS request did not succeed" (which is not CORS issue per se). Same request with curl return "curl: (92) HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)". Same issue happens with instance "drgns.space".

@Alifoss
Copy link

Alifoss commented Mar 1, 2025

I've updated piped-backend and libretube, i have this piped configuration for over a year now. After updating both, libretube returns Network error on every video using HLS as how i used it for the last year. When disabling HLS and using DASH, libretube works but almost every video abruptly stops playing after some minutes. Am i missing something here? Am i supposed to add bg-helper to my instance with these new changes?

I don't think this is LibreTube issue, since I see same thing happening on my private piped instance playing from browser. After about a minute piped proxy requests start to fail with "Reason: CORS request did not succeed" (which is not CORS issue per se). Same request with curl return "curl: (92) HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)". Same issue happens with instance "drgns.space".

Do u have bg-helper implemented? If not perhaps it's expected now in some way? If yes, i don't need to implement it as with it the issue is also occuring

Edit: I just tested it with bg-helper implemented, and the behavior seems the same. Every video abrupting at the 00:59 - 01:00 mark. I'll use my backup to revert to the previous version for now, as refreshing 'IOS player response not valid' couple of times is better than every video abrupting after a minute.

@Bnyro Bnyro added the help wanted Looking for help label Mar 1, 2025
@drJeckyll
Copy link

I've updated piped-backend and libretube, i have this piped configuration for over a year now. After updating both, libretube returns Network error on every video using HLS as how i used it for the last year. When disabling HLS and using DASH, libretube works but almost every video abruptly stops playing after some minutes. Am i missing something here? Am i supposed to add bg-helper to my instance with these new changes?

I don't think this is LibreTube issue, since I see same thing happening on my private piped instance playing from browser. After about a minute piped proxy requests start to fail with "Reason: CORS request did not succeed" (which is not CORS issue per se). Same request with curl return "curl: (92) HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)". Same issue happens with instance "drgns.space".

Do u have bg-helper implemented? If not perhaps it's expected now in some way? If yes, i don't need to implement it as with it the issue is also occuring

Edit: I just tested it with bg-helper implemented, and the behavior seems the same. Every video abrupting at the 00:59 - 01:00 mark. I'll use my backup to revert to the previous version for now, as refreshing 'IOS player response not valid' couple of times is better than every video abrupting after a minute.

yes, I have bg-helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Looking for help
Projects
None yet
Development

No branches or pull requests

8 participants