diff options
| author | Krystof Pistek <krystof1119@gmail.com> | 2024-07-09 18:24:10 +0200 |
|---|---|---|
| committer | Krystof Pistek <krystof1119@gmail.com> | 2024-08-07 20:58:08 +0200 |
| commit | 5f590dda80927fd867b184cbc41065818abada9a (patch) | |
| tree | cdcd70388f6611f9cb582722b36ee33b5517b4dd | |
| parent | 90e94d4e6cc126a8b7a091d12d7a5556bfe369d5 (diff) | |
| download | invidious-5f590dda80927fd867b184cbc41065818abada9a.tar.gz invidious-5f590dda80927fd867b184cbc41065818abada9a.tar.bz2 invidious-5f590dda80927fd867b184cbc41065818abada9a.zip | |
Carry over audio-only mode in playlist links
| -rw-r--r-- | assets/js/watch.js | 4 | ||||
| -rw-r--r-- | src/invidious/mixes.cr | 4 | ||||
| -rw-r--r-- | src/invidious/playlists.cr | 4 | ||||
| -rw-r--r-- | src/invidious/routes/api/v1/misc.cr | 10 |
4 files changed, 16 insertions, 6 deletions
diff --git a/assets/js/watch.js b/assets/js/watch.js index 26ad138f..d869d40d 100644 --- a/assets/js/watch.js +++ b/assets/js/watch.js @@ -67,6 +67,10 @@ function get_playlist(plid) { '&format=html&hl=' + video_data.preferences.locale; } + if (video_data.params.listen) { + plid_url += '&listen=1' + } + helpers.xhr('GET', plid_url, {retries: 5, entity_name: 'playlist'}, { on200: function (response) { playlist.innerHTML = response.playlistHtml; diff --git a/src/invidious/mixes.cr b/src/invidious/mixes.cr index 823ca85b..28ff0ff6 100644 --- a/src/invidious/mixes.cr +++ b/src/invidious/mixes.cr @@ -81,7 +81,7 @@ def fetch_mix(rdid, video_id, cookies = nil, locale = nil) }) end -def template_mix(mix) +def template_mix(mix, listen) html = <<-END_HTML <h3> <a href="/mix?list=#{mix["mixId"]}"> @@ -95,7 +95,7 @@ def template_mix(mix) mix["videos"].as_a.each do |video| html += <<-END_HTML <li class="pure-menu-item"> - <a href="/watch?v=#{video["videoId"]}&list=#{mix["mixId"]}"> + <a href="/watch?v=#{video["videoId"]}&list=#{mix["mixId"]}#{listen ? "&listen=1" : ""}"> <div class="thumbnail"> <img loading="lazy" class="thumbnail" src="/vi/#{video["videoId"]}/mqdefault.jpg" alt="" /> <p class="length">#{recode_length_seconds(video["lengthSeconds"].as_i)}</p> diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index a227f794..0fb6657f 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -498,7 +498,7 @@ def extract_playlist_videos(initial_data : Hash(String, JSON::Any)) return videos end -def template_playlist(playlist) +def template_playlist(playlist, listen) html = <<-END_HTML <h3> <a href="/playlist?list=#{playlist["playlistId"]}"> @@ -512,7 +512,7 @@ def template_playlist(playlist) playlist["videos"].as_a.each do |video| html += <<-END_HTML <li class="pure-menu-item" id="#{video["videoId"]}"> - <a href="/watch?v=#{video["videoId"]}&list=#{playlist["playlistId"]}&index=#{video["index"]}"> + <a href="/watch?v=#{video["videoId"]}&list=#{playlist["playlistId"]}&index=#{video["index"]}#{listen ? "&listen=1" : ""}"> <div class="thumbnail"> <img loading="lazy" class="thumbnail" src="/vi/#{video["videoId"]}/mqdefault.jpg" alt="" /> <p class="length">#{recode_length_seconds(video["lengthSeconds"].as_i)}</p> diff --git a/src/invidious/routes/api/v1/misc.cr b/src/invidious/routes/api/v1/misc.cr index 0c79692d..b34df446 100644 --- a/src/invidious/routes/api/v1/misc.cr +++ b/src/invidious/routes/api/v1/misc.cr @@ -42,6 +42,9 @@ module Invidious::Routes::API::V1::Misc format = env.params.query["format"]? format ||= "json" + listenParam = env.params.query["listen"]? + listen = (listenParam == "true" || listenParam == "1") + if plid.starts_with? "RD" return env.redirect "/api/v1/mixes/#{plid}" end @@ -85,7 +88,7 @@ module Invidious::Routes::API::V1::Misc end if format == "html" - playlist_html = template_playlist(json_response) + playlist_html = template_playlist(json_response, listen) index, next_video = json_response["videos"].as_a.skip(1 + lookback).select { |video| !video["author"].as_s.empty? }[0]?.try { |v| {v["index"], v["videoId"]} } || {nil, nil} response = { @@ -111,6 +114,9 @@ module Invidious::Routes::API::V1::Misc format = env.params.query["format"]? format ||= "json" + listenParam = env.params.query["listen"]? + listen = (listenParam == "true" || listenParam == "1") + begin mix = fetch_mix(rdid, continuation, locale: locale) @@ -157,7 +163,7 @@ module Invidious::Routes::API::V1::Misc if format == "html" response = JSON.parse(response) - playlist_html = template_mix(response) + playlist_html = template_mix(response, listen) next_video = response["videos"].as_a.select { |video| !video["author"].as_s.empty? }[0]?.try &.["videoId"] response = { |
