This addon will replace "youtube.com" with the chosen Invidious instance #1441

Merged
MrPetovan merged 19 commits from :develop into 2023.09-rc 2023-12-08 20:50:23 +01:00
Contributor
No description provided.
loma-one added 13 commits 2023-12-04 11:13:56 +01:00
b547cf8908 Coloured box added
Among other things, I use the page header to inform about current maintenance work or other upcoming work. The information should therefore be provided within an appropriate framework. With a little CSS, the page header gets a frame in green. The font was adjusted to an appropriate size.
8cdb5a5ae3 [pageheader] Improve visibility
Removed commented out code from your pull request
7822515bc8 Dateien nach "invidious" hochladen
Replaces links to youtube.com to an invidious instance in all displays of postings on a node.
9f5da18020 invidious/invidious.php aktualisiert
Redirects from youtu.be do not work reliably. Therefore this one has been removed.
heluecht reviewed 2023-12-04 21:41:28 +01:00
@ -0,0 +50,4 @@
$b['html'] = str_replace('https://www.youtube.com', $invidious, $b['html']);
$replaced = true;
}
if (strstr($b['html'], 'https://youtube.com')) {
Owner

Why is this block duplicated?

Why is this block duplicated?
Author
Contributor

To ensure that different spellings with www and without are intercepted and redirected.

To ensure that different spellings with **www** and without are intercepted and redirected.
Owner

Thanks for the reply, the indentation still needs to be corrected.

Thanks for the reply, the indentation still needs to be corrected.
Owner

you could combine the str_replace with an array as first parameter.

you could combine the `str_replace` with an array as first parameter.
loma-one added 1 commit 2023-12-04 22:01:48 +01:00
Owner

I just saw: You could even make it user configurable. You just have to use DI::userSession()->getLocalUserId() to fetch the user id.

I just saw: You could even make it user configurable. You just have to use `DI::userSession()->getLocalUserId()` to fetch the user id.
Author
Contributor

@heluecht That would be great. The user should be able to control it themselves. I'm just afraid that my skills are not sufficient for these changes.

@heluecht That would be great. The user should be able to control it themselves. I'm just afraid that my skills are not sufficient for these changes.
loma-one added 1 commit 2023-12-05 09:08:38 +01:00
Author
Contributor

@heluecht Here is a suggestion as to how the URLs can be combined with each other.

@heluecht Here is a suggestion as to how the URLs can be combined with each other.
heluecht reviewed 2023-12-05 22:14:15 +01:00
@ -0,0 +54,4 @@
foreach ($youtubeUrls as $youtubeUrl) {
if (strstr($b['html'], $youtubeUrl)) {
$b['html'] = str_replace($youtubeUrl, $invidious, $b['html']);
Owner

You can simply do

            $b['html'] = str_replace(['https://www.youtube.com', 'https://youtube.com'], $invidious, $b['html']);
You can simply do ``` $b['html'] = str_replace(['https://www.youtube.com', 'https://youtube.com'], $invidious, $b['html']); ```
loma-one added 1 commit 2023-12-05 22:40:52 +01:00
MrPetovan requested changes 2023-12-06 15:30:01 +01:00
@ -0,0 +46,4 @@
// this needs to be a system setting
$replaced = false;
$invidious = DI::config()->get('invidious', 'server', 'https://invidio.us');
if (strstr($b['html'], 'https://www.youtube.com')) {
Owner

You need to also check for 'https://youtube.com' now that the replacement has been combined. Additionally strpos() has better performance for what you're trying to do here.

And what about https://youtu.be/[video id] links? They need to be replaced by [Invidious domain]/?watch=[video id].

Lastly, I added an ending slash to the needle strings to match video links. If someone just mentions youtube.com and links to it, it shouldn't be replaced with an Invidious link.

if (strpos($b['html'], 'https://www.youtube.com/') !== false || strpos($b['html'], 'https://youtube.com/') !== false || strpos($b['html'], 'https://youtu.be/') !== false) {
    $b['html'] = str_replace('https://youtu.be/', $invidious . '/?watch=', $b['html']);
    $b['html'] = str_replace(['https://www.youtube.com/', 'https://youtube.com/'], $invidious . '/', $b['html']);
You need to also check for `'https://youtube.com'` now that the replacement has been combined. Additionally `strpos()` has better performance for what you're trying to do here. And what about `https://youtu.be/[video id]` links? They need to be replaced by `[Invidious domain]/?watch=[video id]`. Lastly, I added an ending slash to the needle strings to match video links. If someone just mentions youtube.com and links to it, it shouldn't be replaced with an Invidious link. ```php if (strpos($b['html'], 'https://www.youtube.com/') !== false || strpos($b['html'], 'https://youtube.com/') !== false || strpos($b['html'], 'https://youtu.be/') !== false) { $b['html'] = str_replace('https://youtu.be/', $invidious . '/?watch=', $b['html']); $b['html'] = str_replace(['https://www.youtube.com/', 'https://youtube.com/'], $invidious . '/', $b['html']); ```
loma-one added 1 commit 2023-12-06 18:00:37 +01:00
f2023a5eb9 https://youtu.be Link
Many thanks for the hint. With a small change '/watch?v=' the link to https://youtu.be now also works
loma-one added 1 commit 2023-12-06 18:03:50 +01:00
loma-one added 1 commit 2023-12-06 18:07:23 +01:00
MrPetovan approved these changes 2023-12-06 18:22:46 +01:00
MrPetovan left a comment
Owner

Looks good to me. @heluecht ?

Looks good to me. @heluecht ?
MrPetovan added the
2023.09
label 2023-12-06 18:23:16 +01:00
MrPetovan merged commit 3b518462ab into 2023.09-rc 2023-12-08 20:50:23 +01:00
Sign in to join this conversation.
No description provided.