Compare commits

...

17 Commits

Author SHA1 Message Date
ChunkyProgrammer
f65627f55f encode parameters retrieved from url 2024-09-30 22:03:30 -04:00
ChunkyProgrammer
7e752eece4 Add missing semicolons, remove unused code 2024-09-30 22:03:30 -04:00
ChunkyProgrammer
6d654e1bdf use dom manipulation instead of regex to update reply links 2024-09-30 22:03:30 -04:00
ChunkyProgrammer
003b0fc54c Use javascript to replace reply links, simplify community.js 2024-09-30 22:03:30 -04:00
ChunkyProgrammer
51bb18ff66 Fix YT link for post comments 2024-09-30 22:03:30 -04:00
ChunkyProgrammer
17bc9349a8 Allow viewing more comments when js is disabled 2024-09-30 22:03:30 -04:00
TheFrenchGhosty
53e8a5d62d
Remove myself from CODEOWNERS on the config file (#4942) 2024-09-28 23:54:52 +02:00
Émilien (perso)
a021b93063
Update latest version WEB_CREATOR + fix comment web embed (#4930)
* Update to latest version WEB_CREATOR

* fix comment about using web embed as a fallback
2024-09-20 00:05:41 +00:00
Émilien (perso)
d9df90b5e3
use WEB_CREATOR when po_token with WEB_EMBED as a fallback (#4928)
* use WEB_CREATOR when po_token with WEB_EMBEDDED_PLAYER as a fallback

* remove unrelated comment

Co-authored-by: syeopite <70992037+syeopite@users.noreply.github.com>

---------

Co-authored-by: syeopite <70992037+syeopite@users.noreply.github.com>
2024-09-20 00:19:13 +02:00
Emilien Devos
cec3cfba77 Revert "use web screen embed for fixing potoken functionality (#4923)"
This reverts commit de918b9234.
The code doesn't work as expected. Reverting
2024-09-17 00:22:06 +02:00
Émilien (perso)
de918b9234
use web screen embed for fixing potoken functionality (#4923)
* use web screen embed for fixing potoken functionality

* use web screen embed only for getting streamingData + disable tv screen on po_token
2024-09-16 23:42:43 +02:00
Samantaz Fox
4782a67038
Release v2.20240825.2 2024-08-26 22:52:50 +02:00
Samantaz Fox
5baaedfa39
CI: Fix docker container tags (#4883)
Closes issue 4880
2024-08-26 22:48:14 +02:00
Samantaz Fox
4f066e880c
CI: Fix docker container tags 2024-08-26 21:55:43 +02:00
Samantaz Fox
3e17d04875
Release v2.20240825.1 2024-08-25 22:30:46 +02:00
syeopite
cec905e95e
Allow manual trigger of release-container build (#4877) 2024-08-25 19:55:52 +00:00
Samantaz Fox
80958aa0d8
Release v2.20240825 2024-08-25 21:25:48 +02:00
18 changed files with 346 additions and 86 deletions

2
.github/CODEOWNERS vendored
View File

@ -6,7 +6,7 @@ docker/ @unixfox
kubernetes/ @unixfox kubernetes/ @unixfox
README.md @thefrenchghosty README.md @thefrenchghosty
config/config.example.yml @thefrenchghosty @SamantazFox @unixfox config/config.example.yml @SamantazFox @unixfox
scripts/ @syeopite scripts/ @syeopite
shards.lock @syeopite shards.lock @syeopite

View File

@ -1,6 +1,7 @@
name: Build and release container name: Build and release container
on: on:
workflow_dispatch:
push: push:
tags: tags:
- "v*" - "v*"
@ -46,9 +47,11 @@ jobs:
uses: docker/metadata-action@v5 uses: docker/metadata-action@v5
with: with:
images: quay.io/invidious/invidious images: quay.io/invidious/invidious
flavor: |
latest=false
tags: | tags: |
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} type=raw,value=latest
labels: | labels: |
quay.expires-after=12w quay.expires-after=12w
@ -70,10 +73,11 @@ jobs:
with: with:
images: quay.io/invidious/invidious images: quay.io/invidious/invidious
flavor: | flavor: |
latest=false
suffix=-arm64 suffix=-arm64
tags: | tags: |
type=semver,pattern={{version}} type=semver,pattern={{version}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} type=raw,value=latest
labels: | labels: |
quay.expires-after=12w quay.expires-after=12w

View File

@ -1,6 +1,189 @@
# CHANGELOG # CHANGELOG
## 2024-04-26
## v2.20240825.2 (2024-08-26)
This releases fixes the container tags pushed on quay.io.
Previously, the ARM64 build was released under the `latest` tag, instead of `latest-arm64`.
### Full list of pull requests merged since the last release (newest first)
CI: Fix docker container tags ([#4883], by @SamantazFox)
[#4877]: https://github.com/iv-org/invidious/pull/4877
## v2.20240825.1 (2024-08-25)
Add patch component to be [semver] compliant and make github actions happy.
[semver]: https://semver.org/
### Full list of pull requests merged since the last release (newest first)
Allow manual trigger of release-container build ([#4877], thanks @syeopite)
[#4877]: https://github.com/iv-org/invidious/pull/4877
## v2.20240825.0 (2024-08-25)
### New features & important changes
#### For users
* The search bar now has a button that you can click!
* Youtube URLs can be pasted directly in the search bar. Prepend search query with a
backslash (`\`) to disable that feature (useful if you need to search for a video whose
title contains some youtube URL).
* On the channel page the "streams" tab can be sorted by either: "newest", "oldest" or "popular"
* Lots of translations have been updated (thanks to our contributors on Weblate!)
* Videos embedded in local HTML files (e.g: a webpage saved from a blog) can now be played
#### For instance owners
* Invidious now has the ability to provide a `po_token` and `visitordata` to Youtube in order to
circumvent current Youtube restrictions.
* Invidious can use an (optional) external signature server like [inv_sig_helper]. Please note that
some videos can't be played without that signature server.
* The Helm charts were moved to a separate repo: https://github.com/iv-org/invidious-helm-chart
* We have changed how containers are released: the `latest` tag now tracks tagged releases, whereas
the `master` tag tracks the most recent commits of the `master` branch ("nightly" builds).
[inv_sig_helper]: https://github.com/iv-org/inv_sig_helper
#### For developpers
* The versions of Crystal that we test in CI/CD are now: `1.9.2`, `1.10.1`, `1.11.2`, `1.12.1`.
Please note that due to a bug in the `libxml` bindings (See [#4256]), versions prior to `1.10.0`
are not recommended to use.
* Thanks to @syeopite, the code is now [ameba] compliant.
* Ameba is part of our CI/CD pipeline, and its rules will be enforced in future PRs.
* The transcript code has been rewritten to permit transcripts as a feature rather than being
only a workaround for captions. Trancripts feature is coming soon!
* Various fixes regarding the logic interacting with Youtube
* The `sort_by` parameter can be used on the `/api/v1/channels/{id}/streams` endpoint. Accepted
values are: "newest", "oldest" and "popular"
[ameba]: https://github.com/crystal-ameba/ameba
[#4256]: https://github.com/iv-org/invidious/issues/4256
### Bugs fixed
#### User-side
* Channels: fixed broken "subscribers" and "views" counters
* Watch page: playback position is reset at the end of a video, so that the next time this video
is watched, it will start from the beginning rather than 15 seconds before the end
* Watch page: the items in the "add to playlist" drop down are now sorted alphabetically
* Videos: the "genre" URL is now always pointing to a valid webpage
* Playlists: Fixed `Could not parse N episodes` error on podcast playlists
* All external links should now have the [`rel`] attibute set to `noreferrer noopener` for
increased privacy.
* Preferences: Fixed the admin-only "modified source code" input being ignored
* Watch/channel pages: use the full image URL in `og:image` and `twitter:image` meta tags
[`rel`]: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel
#### API
* fixed the `local` parameter not applying to `formatStreams` on `/api/v1/videos/{id}`
* fixed an `Index out of bounds` error hapenning when a playlist had no videos
* fixed duplicated query parameters in proxied video URLs
* Return actual video height/width/fps rather than hard coded values
* Fixed the `/api/v1/popular` endpoint not returning a proper error code/message when the
popular page/endpoint are disabled.
### Full list of pull requests merged since the last release (newest first)
* HTML: Sort playlists alphabetically in watch page drop down ([#4853], by @SamantazFox)
* Videos: Fix XSS vulnerability in description/comments ([#4852], thanks _anonymous_)
* YtAPI: Bump client versions ([#4849], by @SamantazFox)
* SigHelper: Fix inverted time comparison in 'check_update' ([#4845], by @SamantazFox)
* Storyboards: Various fixes and code cleaning ([#4153], by SamantazFox)
* Fix lint errors introduced in #4146 and #4295 ([#4876], thanks @syeopite)
* Search: Add support for Youtube URLs ([#4146], by @SamantazFox)
* Channel: Render age restricted channels ([#4295], thanks @ChunkyProgrammer)
* Ameba: Miscellaneous fixes ([#4807], thanks @syeopite)
* API: Proxy formatStreams URLs too ([#4859], thanks @colinleroy)
* UI: Add search button to search bar ([#4706], thanks @thansk)
* Add ability to set po_token and visitordata ID ([#4789], thanks @unixfox)
* Add support for an external signature server ([#4772], by @SamantazFox)
* Ameba: Fix Naming/VariableNames ([#4790], thanks @syeopite)
* Translations update from Hosted Weblate ([#4659])
* Ameba: Fix Lint/UselessAssign ([#4795], thanks @syeopite)
* HTML: Add rel="noreferrer noopener" to external links ([#4667], thanks @ulmemxpoc)
* Remove unused methods in Invidious::LogHandler ([#4812], thanks @syeopite)
* Ameba: Fix Lint/NotNilAfterNoBang ([#4796], thanks @syeopite)
* Ameba: Fix unused argument Lint warnings ([#4805], thanks @syeopite)
* Ameba: i18next.cr fixes ([#4806], thanks @syeopite)
* Ameba: Disable rules ([#4792], thanks @syeopite)
* Channel: parse subscriber count and channel banner ([#4785], thanks @ChunkyProgrammer)
* Player: Fix playback position of already watched videos ([#4731], thanks @Fijxu)
* Videos: Fix genre url being unusable ([#4717], thanks @meatball133)
* API: Fix out of bound error on empty playlists ([#4696], thanks @Fijxu)
* Handle playlists cataloged as Podcast ([#4695], thanks @Fijxu)
* API: Fix duplicated query parameters in proxied video URLs ([#4587], thanks @absidue)
* API: Return actual stream height, width and fps ([#4586], thanks @absidue)
* Preferences: Fix handling of modified source code URL ([#4437], thanks @nooptek)
* API: Fix URL for vtt subtitles ([#4221], thanks @karelrooted)
* Channels: Add sort options to streams ([#4224], thanks @src-tinkerer)
* API: Fix error code for disabled popular endpoint ([#4296], thanks @iBicha)
* Allow embedding videos in local HTML files ([#4450], thanks @tomasz1986)
* CI: Bump Crystal version matrix ([#4654], by @SamantazFox)
* YtAPI: Remove API keys like official clients ([#4655], by @SamantazFox)
* HTML: Use full URL in the og:image property ([#4675], thanks @Fijxu)
* Rewrite transcript logic to be more generic ([#4747], thanks @syeopite)
* CI: Run Ameba ([#4753], thanks @syeopite)
* CI: Add release based containers ([#4763], thanks @syeopite)
* move helm chart to a dedicated github repository ([#4711], thanks @unixfox)
[#4146]: https://github.com/iv-org/invidious/pull/4146
[#4153]: https://github.com/iv-org/invidious/pull/4153
[#4221]: https://github.com/iv-org/invidious/pull/4221
[#4224]: https://github.com/iv-org/invidious/pull/4224
[#4295]: https://github.com/iv-org/invidious/pull/4295
[#4296]: https://github.com/iv-org/invidious/pull/4296
[#4437]: https://github.com/iv-org/invidious/pull/4437
[#4450]: https://github.com/iv-org/invidious/pull/4450
[#4586]: https://github.com/iv-org/invidious/pull/4586
[#4587]: https://github.com/iv-org/invidious/pull/4587
[#4654]: https://github.com/iv-org/invidious/pull/4654
[#4655]: https://github.com/iv-org/invidious/pull/4655
[#4659]: https://github.com/iv-org/invidious/pull/4659
[#4667]: https://github.com/iv-org/invidious/pull/4667
[#4675]: https://github.com/iv-org/invidious/pull/4675
[#4695]: https://github.com/iv-org/invidious/pull/4695
[#4696]: https://github.com/iv-org/invidious/pull/4696
[#4706]: https://github.com/iv-org/invidious/pull/4706
[#4711]: https://github.com/iv-org/invidious/pull/4711
[#4717]: https://github.com/iv-org/invidious/pull/4717
[#4731]: https://github.com/iv-org/invidious/pull/4731
[#4747]: https://github.com/iv-org/invidious/pull/4747
[#4753]: https://github.com/iv-org/invidious/pull/4753
[#4763]: https://github.com/iv-org/invidious/pull/4763
[#4772]: https://github.com/iv-org/invidious/pull/4772
[#4785]: https://github.com/iv-org/invidious/pull/4785
[#4789]: https://github.com/iv-org/invidious/pull/4789
[#4790]: https://github.com/iv-org/invidious/pull/4790
[#4792]: https://github.com/iv-org/invidious/pull/4792
[#4795]: https://github.com/iv-org/invidious/pull/4795
[#4796]: https://github.com/iv-org/invidious/pull/4796
[#4805]: https://github.com/iv-org/invidious/pull/4805
[#4806]: https://github.com/iv-org/invidious/pull/4806
[#4807]: https://github.com/iv-org/invidious/pull/4807
[#4812]: https://github.com/iv-org/invidious/pull/4812
[#4845]: https://github.com/iv-org/invidious/pull/4845
[#4849]: https://github.com/iv-org/invidious/pull/4849
[#4852]: https://github.com/iv-org/invidious/pull/4852
[#4853]: https://github.com/iv-org/invidious/pull/4853
[#4859]: https://github.com/iv-org/invidious/pull/4859
[#4876]: https://github.com/iv-org/invidious/pull/4876
## v2.20240427 (2024-04-27)
Major bug fixes: Major bug fixes:
* Videos: Use android test suite client (#4650, thanks @SamantazFox) * Videos: Use android test suite client (#4650, thanks @SamantazFox)

View File

@ -10,6 +10,14 @@ String.prototype.supplant = function (o) {
}); });
}; };
function updateReplyLinks() {
document.querySelectorAll("a[href^='/comment_viewer']").forEach(function (replyLink) {
replyLink.setAttribute("href", "javascript:void(0)");
replyLink.removeAttribute("target");
});
}
updateReplyLinks();
function toggle_comments(event) { function toggle_comments(event) {
var target = event.target; var target = event.target;
var body = target.parentNode.parentNode.parentNode.children[1]; var body = target.parentNode.parentNode.parentNode.children[1];
@ -104,6 +112,7 @@ function get_youtube_comments() {
}) })
}); });
comments.innerHTML = commentInnerHtml; comments.innerHTML = commentInnerHtml;
updateReplyLinks();
comments.children[0].children[0].children[0].onclick = toggle_comments; comments.children[0].children[0].children[0].onclick = toggle_comments;
if (video_data.support_reddit) { if (video_data.support_reddit) {
comments.children[0].children[1].children[0].onclick = swap_comments; comments.children[0].children[1].children[0].onclick = swap_comments;
@ -143,6 +152,7 @@ function get_youtube_replies(target, load_more, load_replies) {
body = body.parentNode.parentNode; body = body.parentNode.parentNode;
body.removeChild(body.lastElementChild); body.removeChild(body.lastElementChild);
body.insertAdjacentHTML('beforeend', response.contentHtml); body.insertAdjacentHTML('beforeend', response.contentHtml);
updateReplyLinks();
} else { } else {
body.removeChild(body.lastElementChild); body.removeChild(body.lastElementChild);
@ -161,6 +171,7 @@ function get_youtube_replies(target, load_more, load_replies) {
body.appendChild(p); body.appendChild(p);
body.appendChild(div); body.appendChild(div);
updateReplyLinks();
} }
}, },
onNon200: function (xhr) { onNon200: function (xhr) {

View File

@ -1,37 +1,20 @@
'use strict'; 'use strict';
var community_data = JSON.parse(document.getElementById('community_data').textContent); var community_data = JSON.parse(document.getElementById('community_data').textContent);
function hide_youtube_replies(event) { // first page of community posts are loaded without javascript so we need to update the Load more button
var target = event.target; var initialLoadMore = document.querySelector('a[data-onclick="get_youtube_replies"]');
initialLoadMore.setAttribute('href', 'javascript:void(0);');
initialLoadMore.removeAttribute('target');
var sub_text = target.getAttribute('data-inner-text'); function updateReplyLinks() {
var inner_text = target.getAttribute('data-sub-text'); document.querySelectorAll("a[href^='/comment_viewer']").forEach(function (replyLink) {
replyLink.setAttribute("href", "javascript:void(0)");
var body = target.parentNode.parentNode.children[1]; replyLink.removeAttribute("target");
body.style.display = 'none'; });
target.innerHTML = sub_text;
target.onclick = show_youtube_replies;
target.setAttribute('data-inner-text', inner_text);
target.setAttribute('data-sub-text', sub_text);
} }
updateReplyLinks();
function show_youtube_replies(event) { function get_youtube_replies(target) {
var target = event.target;
var sub_text = target.getAttribute('data-inner-text');
var inner_text = target.getAttribute('data-sub-text');
var body = target.parentNode.parentNode.children[1];
body.style.display = '';
target.innerHTML = sub_text;
target.onclick = hide_youtube_replies;
target.setAttribute('data-inner-text', inner_text);
target.setAttribute('data-sub-text', sub_text);
}
function get_youtube_replies(target, load_more) {
var continuation = target.getAttribute('data-continuation'); var continuation = target.getAttribute('data-continuation');
var body = target.parentNode.parentNode; var body = target.parentNode.parentNode;
@ -47,29 +30,10 @@ function get_youtube_replies(target, load_more) {
helpers.xhr('GET', url, {}, { helpers.xhr('GET', url, {}, {
on200: function (response) { on200: function (response) {
if (load_more) { body = body.parentNode.parentNode;
body = body.parentNode.parentNode; body.removeChild(body.lastElementChild);
body.removeChild(body.lastElementChild); body.insertAdjacentHTML('beforeend', response.contentHtml);
body.innerHTML += response.contentHtml; updateReplyLinks();
} else {
body.removeChild(body.lastElementChild);
var p = document.createElement('p');
var a = document.createElement('a');
p.appendChild(a);
a.href = 'javascript:void(0)';
a.onclick = hide_youtube_replies;
a.setAttribute('data-sub-text', community_data.hide_replies_text);
a.setAttribute('data-inner-text', community_data.show_replies_text);
a.textContent = community_data.hide_replies_text;
var div = document.createElement('div');
div.innerHTML = response.contentHtml;
body.appendChild(p);
body.appendChild(div);
}
}, },
onNon200: function (xhr) { onNon200: function (xhr) {
body.innerHTML = fallback; body.innerHTML = fallback;

View File

@ -279,7 +279,7 @@ def extract_channel_community(items, *, ucid, locale, format, thin_mode, is_sing
if format == "html" if format == "html"
response = JSON.parse(response) response = JSON.parse(response)
content_html = IV::Frontend::Comments.template_youtube(response, locale, thin_mode) content_html = IV::Frontend::Comments.template_youtube(response, locale, thin_mode, ucid, "community")
response = JSON.build do |json| response = JSON.build do |json|
json.object do json.object do

View File

@ -57,7 +57,7 @@ module Invidious::Comments
return initial_data return initial_data
end end
def parse_youtube(id, response, format, locale, thin_mode, sort_by = "top", is_post = false) def parse_youtube(id, response, format, locale, thin_mode, sort_by = "top", type = "video", ucid = nil)
contents = nil contents = nil
if on_response_received_endpoints = response["onResponseReceivedEndpoints"]? if on_response_received_endpoints = response["onResponseReceivedEndpoints"]?
@ -115,7 +115,11 @@ module Invidious::Comments
json.field "commentCount", comment_count json.field "commentCount", comment_count
end end
if is_post if !ucid.nil?
json.field "authorId", ucid
end
if type == "post"
json.field "postId", id json.field "postId", id
else else
json.field "videoId", id json.field "videoId", id
@ -302,7 +306,8 @@ module Invidious::Comments
if format == "html" if format == "html"
response = JSON.parse(response) response = JSON.parse(response)
content_html = Frontend::Comments.template_youtube(response, locale, thin_mode) content_html = Frontend::Comments.template_youtube(response, locale, thin_mode, id, type)
response = JSON.build do |json| response = JSON.build do |json|
json.object do json.object do
json.field "contentHtml", content_html json.field "contentHtml", content_html

View File

@ -1,7 +1,7 @@
module Invidious::Frontend::Comments module Invidious::Frontend::Comments
extend self extend self
def template_youtube(comments, locale, thin_mode, is_replies = false) def template_youtube(comments, locale, thin_mode, id, type = "video", is_replies = false)
String.build do |html| String.build do |html|
root = comments["comments"].as_a root = comments["comments"].as_a
root.each do |child| root.each do |child|
@ -13,17 +13,17 @@ module Invidious::Frontend::Comments
) )
replies_html = <<-END_HTML replies_html = <<-END_HTML
<div id="replies" class="pure-g"> <div class="pure-g replies">
<div class="pure-u-1-24"></div> <div class="pure-u-1-24"></div>
<div class="pure-u-23-24"> <div class="pure-u-23-24">
<p> <p>
<a href="javascript:void(0)" data-continuation="#{child["replies"]["continuation"]}" <a target="_blank" href="/comment_viewer?continuation=#{child["replies"]["continuation"]}&id=#{id}&type=#{type}" data-continuation="#{child["replies"]["continuation"]}"
data-onclick="get_youtube_replies" data-load-replies>#{replies_count_text}</a> data-onclick="get_youtube_replies" data-load-replies>#{replies_count_text}</a>
</p> </p>
</div> </div>
</div> </div>
END_HTML END_HTML
elsif comments["authorId"]? && !comments["singlePost"]? elsif comments["authorId"]? && !comments["singlePost"]? && type != "post"
# for posts we should display a link to the post # for posts we should display a link to the post
replies_count_text = translate_count(locale, replies_count_text = translate_count(locale,
"comments_view_x_replies", "comments_view_x_replies",
@ -147,7 +147,12 @@ module Invidious::Frontend::Comments
| |
END_HTML END_HTML
if comments["videoId"]? if type == "post" && !comments["singlePost"]?
html << <<-END_HTML
<a href="https://www.youtube.com/channel/#{comments["authorId"]}/community?lb=#{id}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
|
END_HTML
elsif comments["videoId"]?
html << <<-END_HTML html << <<-END_HTML
<a rel="noreferrer noopener" href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a> <a rel="noreferrer noopener" href="https://www.youtube.com/watch?v=#{comments["videoId"]}&lc=#{child["commentId"]}" title="#{translate(locale, "YouTube comment permalink")}">[YT]</a>
| |
@ -196,7 +201,7 @@ module Invidious::Frontend::Comments
<div class="pure-g"> <div class="pure-g">
<div class="pure-u-1"> <div class="pure-u-1">
<p> <p>
<a href="javascript:void(0)" data-continuation="#{comments["continuation"]}" <a target="_blank" href="/comment_viewer?continuation=#{comments["continuation"]}&id=#{id}&type=#{type}" data-continuation="#{comments["continuation"]}"
data-onclick="get_youtube_replies" data-load-more #{"data-load-replies" if is_replies}>#{translate(locale, "Load more")}</a> data-onclick="get_youtube_replies" data-load-more #{"data-load-replies" if is_replies}>#{translate(locale, "Load more")}</a>
</p> </p>
</div> </div>

View File

@ -394,7 +394,7 @@ module Invidious::Routes::API::V1::Channels
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
id = env.params.url["id"].to_s id = URI.encode_www_form(env.params.url["id"].to_s)
ucid = env.params.query["ucid"]? ucid = env.params.query["ucid"]?
thin_mode = env.params.query["thin_mode"]? thin_mode = env.params.query["thin_mode"]?
@ -406,9 +406,9 @@ module Invidious::Routes::API::V1::Channels
if ucid.nil? if ucid.nil?
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}") response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
return error_json(400, "Invalid post ID") if response["error"]? return error_json(400, "Invalid post ID") if response["error"]?
ucid = response.dig("endpoint", "browseEndpoint", "browseId").as_s ucid = URI.encode_www_form(response.dig("endpoint", "browseEndpoint", "browseId").as_s)
else else
ucid = ucid.to_s ucid = URI.encode_www_form(ucid.to_s)
end end
begin begin
@ -423,7 +423,7 @@ module Invidious::Routes::API::V1::Channels
env.response.content_type = "application/json" env.response.content_type = "application/json"
id = env.params.url["id"] id = URI.encode_www_form(env.params.url["id"])
thin_mode = env.params.query["thin_mode"]? thin_mode = env.params.query["thin_mode"]?
thin_mode = thin_mode == "true" thin_mode = thin_mode == "true"
@ -432,15 +432,23 @@ module Invidious::Routes::API::V1::Channels
format ||= "json" format ||= "json"
continuation = env.params.query["continuation"]? continuation = env.params.query["continuation"]?
ucid = env.params.query["ucid"]?
if ucid.nil?
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
return error_json(400, "Invalid post ID") if response["error"]?
ucid = URI.encode_www_form(response.dig("endpoint", "browseEndpoint", "browseId").as_s)
else
ucid = URI.encode_www_form(ucid.to_s)
end
case continuation case continuation
when nil, "" when nil, ""
ucid = env.params.query["ucid"]
comments = Comments.fetch_community_post_comments(ucid, id) comments = Comments.fetch_community_post_comments(ucid, id)
else else
comments = YoutubeAPI.browse(continuation: continuation) comments = YoutubeAPI.browse(continuation: continuation)
end end
return Comments.parse_youtube(id, comments, format, locale, thin_mode, is_post: true) return Comments.parse_youtube(id, comments, format, locale, thin_mode, type: "post", ucid: ucid)
end end
def self.channels(env) def self.channels(env)

View File

@ -392,7 +392,7 @@ module Invidious::Routes::API::V1::Videos
env.response.content_type = "application/json" env.response.content_type = "application/json"
clip_id = env.params.url["id"] clip_id = URI.encode_www_form(env.params.url["id"])
region = env.params.query["region"]? region = env.params.query["region"]?
proxy = {"1", "true"}.any? &.== env.params.query["local"]? proxy = {"1", "true"}.any? &.== env.params.query["local"]?

View File

@ -237,7 +237,7 @@ module Invidious::Routes::Channels
def self.post(env) def self.post(env)
# /post/{postId} # /post/{postId}
id = env.params.url["id"] id = URI.encode_www_form(env.params.url["id"])
ucid = env.params.query["ucid"]? ucid = env.params.query["ucid"]?
prefs = env.get("preferences").as(Preferences) prefs = env.get("preferences").as(Preferences)
@ -253,14 +253,14 @@ module Invidious::Routes::Channels
nojs = nojs == "1" nojs = nojs == "1"
if !ucid.nil? if !ucid.nil?
ucid = ucid.to_s ucid = URI.encode_www_form(ucid.to_s)
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode) post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode)
else else
# resolve the url to get the author's UCID # resolve the url to get the author's UCID
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}") response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
return error_template(400, "Invalid post ID") if response["error"]? return error_template(400, "Invalid post ID") if response["error"]?
ucid = response.dig("endpoint", "browseEndpoint", "browseId").as_s ucid = URI.encode_www_form(response.dig("endpoint", "browseEndpoint", "browseId").as_s)
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode) post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode)
end end
@ -268,7 +268,7 @@ module Invidious::Routes::Channels
if nojs if nojs
comments = Comments.fetch_community_post_comments(ucid, id) comments = Comments.fetch_community_post_comments(ucid, id)
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, is_post: true))["contentHtml"] comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, type: "post", ucid: ucid))["contentHtml"]
end end
templated "post" templated "post"
end end

View File

@ -332,4 +332,53 @@ module Invidious::Routes::Watch
return error_template(400, "Invalid label or itag") return error_template(400, "Invalid label or itag")
end end
end end
# used for fetching replies/ fetching more comments when js is disabled.
def self.comments(env)
locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]?
id = URI.encode_www_form(env.params.query["id"])
continuation = env.params.query["continuation"]?
source = env.params.query["source"]? || "youtube"
thin_mode = env.params.query["thin_mode"]? == "true"
comment_type = env.params.query["type"]? || "video"
parent_comment = nil
if comment_type == "community"
# community posts
comment_html = JSON.parse(fetch_channel_community(id, continuation, locale, "html", thin_mode))["contentHtml"]
elsif comment_type == "post"
# replies to a community post
ucid = env.params.query["ucid"]?
if ucid.nil?
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
return error_json(400, "Invalid post ID") if response["error"]?
ucid = URI.encode_www_form(response.dig("endpoint", "browseEndpoint", "browseId").as_s)
else
ucid = URI.encode_www_form(ucid.to_s)
end
case continuation
when nil, ""
comments = Comments.fetch_community_post_comments(ucid, id)
else
comments = YoutubeAPI.browse(continuation: continuation)
end
comment_html = JSON.parse(Comments.parse_youtube(id, comments, "html", locale, thin_mode, type: "post", ucid: ucid))["contentHtml"]
else
# video comments
if source == "youtube"
comment_html = JSON.parse(Comments.fetch_youtube(id, continuation, "html", locale, thin_mode, region))["contentHtml"]
elsif source == "reddit"
comments, reddit_thread = Comments.fetch_reddit(id)
comment_html = Frontend::Comments.template_reddit(comments, locale)
comment_html = Comments.fill_links(comment_html, "https", "www.reddit.com")
comment_html = Comments.replace_links(comment_html)
end
end
templated "comments_no_js"
end
end end

View File

@ -170,6 +170,8 @@ module Invidious::Routing
get "/embed/", Routes::Embed, :redirect get "/embed/", Routes::Embed, :redirect
get "/embed/:id", Routes::Embed, :show get "/embed/:id", Routes::Embed, :show
# currently only for fetching continuations when js is disabled.
get "/comment_viewer", Routes::Watch, :comments
end end
def register_yt_playlist_routes def register_yt_playlist_routes

View File

@ -53,6 +53,10 @@ end
def extract_video_info(video_id : String) def extract_video_info(video_id : String)
# Init client config for the API # Init client config for the API
client_config = YoutubeAPI::ClientConfig.new client_config = YoutubeAPI::ClientConfig.new
# Use the WEB_CREATOR when po_token is configured because it fully only works on this client
if CONFIG.po_token
client_config.client_type = YoutubeAPI::ClientType::WebCreator
end
# Fetch data from the player endpoint # Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config) player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
@ -102,6 +106,13 @@ def extract_video_info(video_id : String)
new_player_response = nil new_player_response = nil
# Second try in case WEB_CREATOR doesn't work with po_token.
# Only trigger if reason found and po_token configured.
if reason && CONFIG.po_token
client_config.client_type = YoutubeAPI::ClientType::WebEmbeddedPlayer
new_player_response = try_fetch_streaming_data(video_id, client_config)
end
# Don't use Android client if po_token is passed because po_token doesn't # Don't use Android client if po_token is passed because po_token doesn't
# work for Android client. # work for Android client.
if reason.nil? && CONFIG.po_token.nil? if reason.nil? && CONFIG.po_token.nil?
@ -114,10 +125,9 @@ def extract_video_info(video_id : String)
end end
# Last hope # Last hope
# Only trigger if reason found and po_token or didn't work wth Android client. # Only trigger if reason found or didn't work wth Android client.
# TvHtml5ScreenEmbed now requires sig helper for it to work but po_token is not required # TvHtml5ScreenEmbed now requires sig helper for it to work but doesn't work with po_token.
# if the IP address is not blocked. if reason && CONFIG.po_token.nil?
if CONFIG.po_token && reason || CONFIG.po_token.nil? && new_player_response.nil?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config) new_player_response = try_fetch_streaming_data(video_id, client_config)
end end
@ -185,10 +195,11 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
end end
video_details = player_response.dig?("videoDetails") video_details = player_response.dig?("videoDetails")
microformat = player_response.dig?("microformat", "playerMicroformatRenderer") if !(microformat = player_response.dig?("microformat", "playerMicroformatRenderer"))
microformat = {} of String => JSON::Any
end
raise BrokenTubeException.new("videoDetails") if !video_details raise BrokenTubeException.new("videoDetails") if !video_details
raise BrokenTubeException.new("microformat") if !microformat
# Basic video infos # Basic video infos
@ -225,7 +236,7 @@ def parse_video_info(video_id : String, player_response : Hash(String, JSON::Any
.try &.as_a.map &.as_s || [] of String .try &.as_a.map &.as_s || [] of String
allow_ratings = video_details["allowRatings"]?.try &.as_bool allow_ratings = video_details["allowRatings"]?.try &.as_bool
family_friendly = microformat["isFamilySafe"].try &.as_bool family_friendly = microformat["isFamilySafe"]?.try &.as_bool
is_listed = video_details["isCrawlable"]?.try &.as_bool is_listed = video_details["isCrawlable"]?.try &.as_bool
is_upcoming = video_details["isUpcoming"]?.try &.as_bool is_upcoming = video_details["isUpcoming"]?.try &.as_bool

View File

@ -0,0 +1,8 @@
<% content_for "header" do %>
<title>Invidious</title>
<% end %>
<!-- basic comments page for people with js disabled. -->
<div class="comments post-comments">
<%= comment_html %>
</div>

View File

@ -27,7 +27,7 @@
</div> </div>
<% else %> <% else %>
<div class="h-box pure-g comments" id="comments"> <div class="h-box pure-g comments" id="comments">
<%= IV::Frontend::Comments.template_youtube(items.not_nil!, locale, thin_mode) %> <%= IV::Frontend::Comments.template_youtube(items.not_nil!, locale, thin_mode, ucid, "community") %>
</div> </div>
<% end %> <% end %>

View File

@ -4,7 +4,7 @@
<div> <div>
<div id="post" class="comments post-comments"> <div id="post" class="comments post-comments">
<%= IV::Frontend::Comments.template_youtube(post_response.not_nil!, locale, thin_mode) %> <%= IV::Frontend::Comments.template_youtube(post_response.not_nil!, locale, thin_mode, id, "post") %>
</div> </div>
<% if nojs %> <% if nojs %>

View File

@ -29,6 +29,7 @@ module YoutubeAPI
WebEmbeddedPlayer WebEmbeddedPlayer
WebMobile WebMobile
WebScreenEmbed WebScreenEmbed
WebCreator
Android Android
AndroidEmbeddedPlayer AndroidEmbeddedPlayer
@ -80,6 +81,14 @@ module YoutubeAPI
os_version: WINDOWS_VERSION, os_version: WINDOWS_VERSION,
platform: "DESKTOP", platform: "DESKTOP",
}, },
ClientType::WebCreator => {
name: "WEB_CREATOR",
name_proto: "62",
version: "1.20240918.03.00",
os_name: "Windows",
os_version: WINDOWS_VERSION,
platform: "DESKTOP",
},
# Android # Android
@ -291,8 +300,9 @@ module YoutubeAPI
end end
if client_config.screen == "EMBED" if client_config.screen == "EMBED"
# embedUrl https://www.google.com allow loading almost all video that are configured not embeddable
client_context["thirdParty"] = { client_context["thirdParty"] = {
"embedUrl" => "https://www.youtube.com/embed/#{video_id}", "embedUrl" => "https://www.google.com/",
} of String => String | Int64 } of String => String | Int64
end end