code-charity / youtube

[top~1 open YouTube & Video web-extension] Enrich your experience & choice! 🧰100+clever features📌set&forget📌Longest-standing(yet rare&tough alone. Please help/join🧩us👨‍👩‍👧‍👧) ..⋮ {playback|content discovery|player|extra buttons|distractions|related videos|shorts|ads|quality|codec|full tab|full screen}
http://improvedtube.com
Other
3.29k stars 498 forks source link

Update player.js reverting #2062, fixes #1342 #1652 #1904 #2389

Closed raszpl closed 1 week ago

raszpl commented 1 week ago

reverting implementation of https://github.com/code-charity/youtube/issues/2061 , bad idea, YT internally uses same parameter markers so we cant really distinguish between YT resuming and someone opening link with timestamp

this.elements.player.seekTo(0) rewinds, but with side effects of triggering play()

switch from this.elements.player.seekTo(0) to this.elements.video.currentTime = 0 didnt work. YT player actually reads currentTime and will hang while hammering currentTime(whatever) if it doesnt get what it wants :0. Back to seekTo(0) with optional check for paused.

Edit: further testing shows

Object.defineProperty(HTMLMediaElement.prototype, 'currentTime', {
    enumerable: true,
    configurable: true,
    get: function() {
        return ImprovedTube.HTMLMediaElement.get.apply(this, arguments);
    },
    set: function(newValue) {
        console.log('early set', newValue);
        if (newValue != 0) {
            this.currentTime = 0;
            ImprovedTube.HTMLMediaElement.set.apply(this, [0]);
        }
    }
});

video wont play at all and console shows

17:55:42.780 core.js:76 early HTMLMediaElement.prototype.play!!!!!!!!
17:55:43.870 core.js:88 early set 568
17:55:43.871 core.js:88 early set 0
17:55:47.163 core.js:88 early set 568
17:55:47.163 core.js:88 early set 0
17:55:53.249 core.js:88 early set 568.001
17:55:53.249 core.js:88 early set 0
17:55:57.360 core.js:76 early HTMLMediaElement.prototype.play!!!!!!!!
17:55:57.435 core.js:88 early set 568
17:55:57.435 core.js:88 early set 0
17:56:06.608 core.js:76 early HTMLMediaElement.prototype.play!!!!!!!!

YT knows something is wrong and keeps trying :(

To make forcedPlayVideoFromTheBeginning reliable it would have to either trigger way late causing annoying rewind every time, or finally make autoplayDisable reliably stop without playing a single frame. Second option seems better.

ImprovedTube commented 1 week ago

hi! @raszpl

can start with if (this.storage.forced_play_video_from_the_beginning , paused= inside

2061

why not check !this.video_url.match(this.regex.video_time) ?

raszpl commented 1 week ago

can start with if (this.storage.forced_play_video_from_the_beginning , paused= inside

variable declarations on top of function are more readable, reading video?.paused is free, declaring empty let paused just to fill it inside condition is more typing :)

why not check !this.video_url.match(this.regex.video_time) ?

because "reverting implementation of https://github.com/code-charity/youtube/issues/2061 , bad idea, YT internally uses same parameter markers so we cant really distinguish between YT resuming and someone opening link with timestamp"

We can either respect forced_play_video_from_the_beginning on all videos or users will complain its not working in some situations. It still fails sometime as explained in the Edit :( the later its being executed the more reliable it is, but at the cost of annoying jump if Autoplay is enabled. Bet option is to work on fully reliable autoplayDisable, I already have something almost working.

ImprovedTube commented 1 week ago

hi @raszpl, youtube will add the t= parameter to the URL bar? under which circumstance? (then can keep !this.video_url.match(this.regex.video_time), when navigation to get there happened through a link or bookmark.) (and i'm just applying the principle of preparing for later, "hoarding comments & code. While Developer time is our only limit but this project might have double the meanningful code sooner than the "existing half" took https://github.com/code-charity/youtube/issues/2233#issuecomment-2090845175 ) regex

raszpl commented 5 days ago

youtube will add the t= parameter to the URL bar? under which circumstance?

https://github.com/code-charity/youtube/issues/2061#issuecomment-1985100295

raszpl commented 4 days ago

wait, what is "#t=" ? Where did you saw "#t" usage? # (hash) is used for anchor navigation in links. Please post code links, those images are to "private-user-images" and often dont render at all :(