anxdpanic / plugin.video.youtube

Watch your favorite YouTube content on Kodi
https://ytaddon.panicked.xyz/forum
662 stars 112 forks source link

Buffering Bug #163

Closed neo-neo1 closed 2 years ago

neo-neo1 commented 3 years ago

Several people have all recently reported this same issue at Kodi forums - YouTube Addon (last page). This is a reproducible problem. When playing videos from a playlist after 2-3 videos the next video that starts will buffer every several seconds.

I’m able to open a new video that won’t buffer but If I go back to the previous video which had buffering issues it will always have buffering issues unless I restart Kodi device or delete cache and database from YouTube addon settings.

This is not a network or device issue.

Edit: (Additional detail) It doesn’t only happen to videos in a playlist. Usually after watching several videos at random as well. After a Kodi restart I haven’t had the first video I opened buffer, usually after watching several.

In this YouTube Add-on settings I changed the cache size and video settings to every available option yielding the same result.

Been using this Addon since 1.0.

wagnerch commented 3 years ago

Also affects:

With or without MPEG-DASH, same effect.

pbo10 commented 3 years ago

I have what sounds like the same issue on an NVidia Shield running Kodi 19.1.

It seems fairly random and I'm not using playlists, but every couple of videos I try to play buffers to the point of being unwatchable. If I stop the video and start again a few times eventually it runs fine.

asavah commented 3 years ago

Can confirm this too. Happens randomly with some videos, I don't usually use playlists. Youtube addon is configured to prefer vp9/webm. Stopping the video and starting it again usually solves the issue.

wagnerch commented 3 years ago

Also affects:

Add-on Version: 6.8.15
Kodi Version: 19.1-ish
Kodi GUI Language: English
Operating System: CoreELEC 19.2rc2
Operating System Language: English
Hardware: Amlogic S905D 2G

Restarting the videos doesn't fix it for me, it just ends up buffering in pretty much the same spots, within a few seconds it. However, restarting Kodi (via systemctl restart kodi) does clear the issue.

wagnerch commented 3 years ago

Here is a snippet of a log, a much much larger log spanning ~20 hours is available. It shows the video playing just before fine at 08:04, and then the stuttering/buffering happening on the video starting at 08:16

https://paste.ubuntu.com/p/RzRFzcYhQS/

I also tried to restart the same video, and pretty much buffers in the same exact spots. Restart kodi, and video plays fine.

neo-neo1 commented 3 years ago

Also affects:

Add-on Version: 6.8.15
Kodi Version: 19.1-ish
Kodi GUI Language: English
Operating System: CoreELEC 19.2rc2
Operating System Language: English
Hardware: Amlogic S905D 2G

Restarting the videos doesn't fix it for me, it just ends up buffering in pretty much the same spots, within a few seconds it. However, restarting Kodi (via systemctl restart kodi) does clear the issue.

I can also confirm restarting videos doesn’t fix the buffer issue. Only a Kodi device restart or clearing database and cache from Kodi YouTube Add-on settings.

To elaborate on my original post it doesn’t only occur to videos in a playlist. After a Kodi restart I haven’t had the first video I opened buffer, usually after watching several.

In this YouTube Add-on settings I changed the cache size and video settings to every available option yielding the same result with this buffering bug still persisting.

Isayso commented 3 years ago

This occurs also if I send videos from other devices via html POST to play queue. And is independent to settings of cache in advancedsettings.xml

Add-on Version: 6.8.15 and 6.8.14 and 6.8.13 Kodi Version: 19.1 Kodi GUI Language: English Operating System: LibreELEC 10.0 Hardware: Raspberry Pi 3 and 3+

dchristl commented 3 years ago

Can also confirm this issue. I always use POST for playing multiple videos in queue. Restarting the video doesn't work for me either only a Kodi restart. I often watch multiple short (<15 min) videos without any issue. Sometimes 2 large videos are a problem. It seems a longer playlist (more time not more items) lead earlier to this issue.

Add-on Version: 6.8.15 Kodi Version: 19.1 Kodi GUI Language: German Operating System: Ubuntu 20.04.2 Hardware: AMD Athlon 8 core, Nvidia Geforce GTX275, 16 GB RAM

brainwaster commented 3 years ago

Same issue for me, happens randomly, it can happen immediately or after playing a few vids. I can fix it without a restart by turning off MPEG DASH if it's on or turn it on if it's off.

ADD-on Version: 6.8.15 Kodi Version: 18.9 Kodi GUI Language: English Operating System: LibreElec 9.2.6 Hardware: Intel Core Duo Quad Core 4ghz, 4gig ram, AMD Radeon HD 4550

pbo10 commented 3 years ago

I've been looking around some more and I think this issue may be down to YouTube throttling on their side. If you read the youtube-dl reddit forum they seem to be aware of throttling being done by Youtube now, I also tested myself downloading a list of videos with youtube-dl and the first few start downloading at 2mbps+ then drops to 50kb/s. Not sure what triggers the throttling yet though.

https://github.com/ytdl-org/youtube-dl/issues/29326

I think it then stops throttling after a short time, so perhaps just by exiting Kodi and restarting it allows enough time for the throttling to have stopped.

wagnerch commented 3 years ago

This comment is interesting, it is suggesting that there is a "n" query parameter that YouTube is putting this parameter in their URLs and the client-side needs to modify it and send it back as a signature/challenge of some sorts.

https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377 https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-866674128

pbo10 commented 3 years ago

Yea they seem to have the fix but no one has had time to implement it yet. Hopefully the fix works and can be added here as well.

drrak commented 3 years ago

Translator: I have a problem with buffering too. Not only in playlists, just in randomly played videos.

RPi4, LibrELEC 9.95.4, Kodi 19.1, YouTube 6.8.15+matrix.1

RNavega commented 2 years ago

The yt-dlp project seems to be using the workaround of forcing / spoofing an Android device? But it's not clear how this is done internally (what kind of headers they're changing etc) that we could do from plugin.video.youtube.

https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/extractor/youtube.py

clovk commented 2 years ago

This has been plaguing me now for months and I've tried YouTube addons 6.8.10 -15, from repos and downloads, Libreelec 9.2.6, 9.2.8 and 10.1, Odroid C2, C4 and Raspberry pi 4 (all buffer even 1080 at 30fps) and upgraded my network to a i5 pfsense and cat6 cabling, nothing worked. I think there are 2 issues here:

  1. Playing from (long) playlist: Videos randomly start buffering. Rebooting, waiting (1-2 min), or playing something from a local (network) source fixes the problem, for the next few videos. I think it's a Kodi - Youtube-addon problem (just a feeling, not a programmer).

  2. Certain videos always buffer. Rebooting, reinstalling, clearing various add-on, system caches does nothing. Here is a partial list of channels who's videos always buffer: https://youtube.com/c/MxRPlays https://youtube.com/c/ForgottenWeapons https://youtube.com/c/JerryRigEverything https://youtube.com/user/DemolitionRanch

Downloading videos from these channels with youtube-dl (on x86 Ubuntu), yields similar download speeds to other videos. Here I think google is throteling somehow...

Also, is it just my YouTube addon, that only buffers a few seconds and gets cleared everytime I scrub or play/pause? So I can't just wait for it to buffer, since the buffer resets when I click play, or go back 10 seconds... I've played with the buffer size in the add-on settings and I have an advanced settings file for buffering everything to 400mb on a RPI4 2gb, which all other local/online videos respect, just not the YouTube add-on.

RNavega commented 2 years ago

Someone from Pytube generously wrote the functions needed to parse and generate the "n" token: https://github.com/pytube/pytube/blob/master/pytube/cipher.py

anxdpanic commented 2 years ago

Thanks for the heads up @RNavega https://github.com/anxdpanic/plugin.video.youtube/pull/176

anxdpanic commented 2 years ago

I've created an alpha build with this included, https://github.com/anxdpanic/plugin.video.youtube/releases/tag/6.x.x-dev

gc248 commented 2 years ago

Thanks for the new build! While I'm not skilled enough to contribute code, I can at least test it. I've installed it on my main system and will see how it behaves over the next few days. I hope others will do the same.

pnperehod commented 2 years ago

alpha1 didn't fixed the bug - still endless buffering after 3-4 videos

AlexNk commented 2 years ago

Tested the alpha build - it seems that the videos are starting faster now, but I still got the buffering issue twice in 20-25 videos. It might be less often than before, but I am not sure about this - need more tests.

pnperehod commented 2 years ago

Tested the alpha build - it seems that the videos are starting faster now, but I still got the buffering issue twice in 20-25 videos. It might be less often than before, but I am not sure about this - need more tests.

Almost the same here, but number of videos smaller, from 3 to 7 оn average

neo-neo1 commented 2 years ago

I've created an alpha build with this included, https://github.com/anxdpanic/plugin.video.youtube/releases/tag/6.x.x-dev

Unfortunately the buffering did not go away and still persists same as before. After a few videos at random it will start buffering to unwatchable conditions. Thank you for your attempt.

neo-neo1 commented 2 years ago

Just as an update to the Alpha build I believe it may have at least done something. If a video starts buffering I can stop and reopen it and it’ll play fine. Before I had to restart Kodi to get the same video exhibiting buffering to play normally.

arcaine2 commented 2 years ago

@neo-neo1, if that's the behaviour, then it works for me like this for a very long time. I'm currently on 6.8.16+matrix1 version, but it's been a few months like this. Sometimes i get the buffering as soon as i start a video, but most of the time it is enough to stop and start it again. Sometimes 2-3 times, sometimes with a small, couple seconds delay, and it plays fine then. I never had to restart Kodi as a whole to get it played correctly. It behaves like this for me on Shield TV, as well as a on Linux based PC i'm using. I haven't tried it on Windows at all.

pix0wl commented 2 years ago

Version 6.8.17 fixed this problem for me. Thanks to ramateur and anxdpanic. 👍

DmnzH commented 2 years ago

6.8.17+matrix1 still not working for me unfortunately, buffering still happen occasionally. Kodi 19.1 Matrix, Ubuntu 20.04, x64, HD 5450

neo-neo1 commented 2 years ago

6.8.17+matrix1 still not working for me unfortunately, buffering still happen occasionally. Kodi 19.1 Matrix, Ubuntu 20.04, x64, HD 5450

Yep it’s not working for anyone as far as I know. We’re at the mercy of the devs generosity.

pnperehod commented 2 years ago

yes, unfortunately buffering problem still present, 6.8.17-alpha1, RPi 3b+ libreelec 9.2.6, Odroid C4 Coreelec 9.2.7

pix0wl commented 2 years ago

Strange. I've started about 50 different videos with version 6.8.17 and have not had the bug with any of them. Before, the bug happened every 3-9 videos - very random. Some videos take a little longer to start but no buffer issue anymore.

CoreELEC 19.1 / Kodi 19.1

DjDiabolik commented 2 years ago

I see the recent reply........ it's see the buffering issue it's been resolved on recent 6.8.17 ?!?!?

OMG yes.

Instead until now i have the same issue......... my case it's OSMC kodi19 runned on a Raspberry Pi2. Sometime i obtain buffer issue immediatelly after start to reproduce a video....... sometime i need to stop and restart the same video and the issue it's disappears. In somecase i have need to watch the same video after about one or two hours to watch it whitout any trouble.

If right now the 6.8.17 resolve the issue....... GREAT.

DmnzH commented 2 years ago

So I have been playing 30 odd youtube videos with 6.8.17 and the issue occured twice so far. It is definitely an improvement than before where the issue happens so often, like in every 3-5 videos.

Update: after further testing, the issue still occurs quite often. The previous testing results must be just a fluke.

gatecrasher777 commented 2 years ago

Stream urls are linked to specific players (there are a bunch of them) so I think the fix above works with one/some youtube players, but not all. To fix the problem reliably, you have to run the obfuscated javascript in the linked base.js files to transform the n parameter. That is what happens in the browser on youtube.com or in embedded videos. I get around it in my node-js project by extracting and running the actual player code. It works perfectly with no slow downloads. I know almost nothing about python, but I suspect that python can execute client-side javascript, and so a solution should be possible.

shartge commented 2 years ago

There have been new updates to the ratebypass code. I have currently manually put https://raw.githubusercontent.com/anxdpanic/plugin.video.youtube/0ba4dead0d68df3cb7b70a7589faddb95709fbca/resources/lib/youtube_plugin/youtube/helper/ratebypass/ratebypass.py into my Kodi installation and so far it looks promising.

drrak commented 2 years ago

There have been new updates to the ratebypass code. I have currently manually put https://raw.githubusercontent.com/anxdpanic/plugin.video.youtube/0ba4dead0d68df3cb7b70a7589faddb95709fbca/resources/lib/youtube_plugin/youtube/helper/ratebypass/ratebypass.py into my Kodi installation and so far it looks promising.

Translator: So far I have checked 20 videos and I had no problem with any of them. It looks like it has finally been fixed.

Thank you shartge.

pnperehod commented 2 years ago

testing on more than 10 videos in a row. So far so good. shartge thanks!

neo-neo1 commented 2 years ago

There have been new updates to the ratebypass code. I have currently manually put https://raw.githubusercontent.com/anxdpanic/plugin.video.youtube/0ba4dead0d68df3cb7b70a7589faddb95709fbca/resources/lib/youtube_plugin/youtube/helper/ratebypass/ratebypass.py into my Kodi installation and so far it looks promising.

Currently, trying it out. Thanks.

If anyone is curious here's the file location on Linux (CoreELEC).

/Addons/plugin.video.youtube/resources/lib/youtube_plugin/youtube/helper/ratebypass/ratebypass.py

pnperehod commented 2 years ago

Two days it worked fine, but today it all over again, buffering every other video.

drrak commented 2 years ago

Two days it worked fine, but today it all over again, buffering every other video.

So far it works for me. Maybe it was the "normal" buffering problem?

shartge commented 2 years ago

Problem here is obviously the usual problem of needing to play cat-and-mouse with Youtube (or any service, for that matter), when you are interfacing with their website and APIs in more ... unintended ways.

So what works one day may suddenly break for some or all users the next day. It is unfortunate but until someone implements or transplants a full JavaScript runtime into Kodi or the plugin, stuff like this will continue to happen.

Durlyn commented 2 years ago

Two days it worked fine, but today it all over again, buffering every other video.

I have similar behavior

DjDiabolik commented 2 years ago

After a lot of day of usage this last 6.8.17 on my rasp pi2 (whit latest osmc) i can say that the situation with me has remained almost unchanged from previous version of addons. Until today every 3 or 4 videos viewed i obtain this same buffering issue immediatelly after about 5 or 6 seconds of vision.

Simply press on "STOP" restart to watch same exact video and every buffer issue it's disappears.

Maybe whit the previous version of addons the situation was worse but surely this latest version as not fixed the issue completely on my kodi setup.

drrak commented 2 years ago

Two days it worked fine, but today it all over again, buffering every other video.

I have similar behavior

Me too 😥

gc248 commented 2 years ago

i can say that the situation with me has remained almost unchanged from previous version of addons.

This is not quite in line with my experience.

Simply press on "STOP" restart to watch same exact video and every buffer issue it's disappears.

This is a HUGE improvement from the situation which persisted for many weeks before anxdpanic's alpha build 27 days ago. Before that build the slowness/buffering started sooner and was not resolved without a restart - and sometimes not even then. Since that build even when the buffering has returned a simple stop and retry has quite reliably resolved it. This makes the plugin a lot less frustrating to use from my point of view. Watching youtube on my TV is pleasant again now.

It seems that some people's experiences have been a lot worse than mine, however. I have no idea if this is due to differences in Kodi versions and setups, or maybe something geographical or some other factor we haven't thought of. Or maybe it's something more subjective.

Either way, thanks to those working on it! I think good progress is being made, even if there is further to go.

MMan1982 commented 2 years ago

For me too. Crash kodi fully :( kodi_crashlog-20210912_153040.log

RNavega commented 2 years ago

@MMan1982 from your log:

[plugin.video.youtube] Finding throttling function name

There's no such error message in the code anymore in the master branch (the "latest" branch), so you're using a slightly older plugin version than the people in here.

Such a patched version would be this, 6.8.17~master, you can transfer it to your Kodi device to install: plugin.video.youtube-master.zip

Edit: ..or wait until a 6.8.18 is released.

Zynth-dev commented 2 years ago

I can confirm the issue on 6.8.17 Often, stopping, starting another video, stopping that, and starting the original one solves the problem. Sometimes then also waiting for a minute helps. But no strategy gives reproducible good results at the moment.

jmkristofzski commented 2 years ago

6.8.17 as well. Maybe 10% of the time a video has the issue where it buffers in the first 10 seconds of the video, usually faster.

If I send up a playlist, opening the playlist menu then restarting the same video usually resolves it, sometimes it takes 2-5 times before the video loads correctly. Once the video is working once on the playlist it will continue to work if shuffle is on.

An example sequence of events:

  1. 10 item playlist
  2. 2 random videos of playlist buffer within a few seconds
  3. I restart the video from the Kodi playlist menu (navigate to the playlist menu then hit enter on the video), sometimes takes a few attempts
  4. I have repeat all selected on the playlist
  5. After the first full play through of each video (even if you skip one halfway through if it didn't have the buffer issue) each video works every time without the buffer issue
  6. Add a new video to queue, sometimes the buffer issue occurs and you have to restart the video

I have tried VPN on and off in various parts of the US.

I tried the rate bypass code someone else posted and it didn't work: https://raw.githubusercontent.com/anxdpanic/plugin.video.youtube/0ba4dead0d68df3cb7b70a7589faddb95709fbca/resources/lib/youtube_plugin/youtube/helper/ratebypass/ratebypass.py

I tried playing videos within the YouTube add-on, from a favorites playlist, and from the YATSE app on Android. All options have the same issue at the same frequency.

I also have set up the API keys through my Google account, and tried without doing that, neither helps the frequency.

Hope this helps.

Zynth-dev commented 2 years ago

Update: Noticed that when selecting "play, ask for quality" and then selecting for example 720p, sometimes helps. It sometimes helps in case the 1080p (standard selected) version has buffering issues.

-edit; after some bad additional experiences it still seems not to make much of a difference. Sometimes it helps, sometimes not. Not consistent enough to eliminate "chance" as being the reason why.

gatecrasher777 commented 2 years ago
  1. extract JavaScript n-transform function from watch page linked base.js provided by YT.
  2. execute it in this project using a JavaScript parser passing the n value from the YT media streams.
  3. replace the n values in the media streams with the results.
  4. no more throttling.

Each base.js has a different n-transform function, and there are dozens of them. Emulating a single n-transform is not going to cut it - that's why you have to execute YT's JavaScript code on the fly if you want to solve this issue.