mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-25 15:07:22 +00:00
Remove useless arguments from playlist-related functions
This commit is contained in:
parent
2ae074a9a4
commit
5e3c9cf290
@ -90,7 +90,7 @@ struct Playlist
|
||||
property updated : Time
|
||||
property thumbnail : String?
|
||||
|
||||
def to_json(offset, locale, json : JSON::Builder, video_id : String? = nil)
|
||||
def to_json(offset, json : JSON::Builder, video_id : String? = nil)
|
||||
json.object do
|
||||
json.field "type", "playlist"
|
||||
json.field "title", self.title
|
||||
@ -125,7 +125,7 @@ struct Playlist
|
||||
|
||||
json.field "videos" do
|
||||
json.array do
|
||||
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
|
||||
videos = get_playlist_videos(self, offset: offset, video_id: video_id)
|
||||
videos.each do |video|
|
||||
video.to_json(json)
|
||||
end
|
||||
@ -134,13 +134,9 @@ struct Playlist
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(offset, locale, json : JSON::Builder? = nil, video_id : String? = nil)
|
||||
if json
|
||||
to_json(offset, locale, json, video_id: video_id)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(offset, locale, json, video_id: video_id)
|
||||
end
|
||||
def to_json(offset, _json : Nil = nil, video_id : String? = nil)
|
||||
JSON.build do |json|
|
||||
to_json(offset, json, video_id: video_id)
|
||||
end
|
||||
end
|
||||
|
||||
@ -179,7 +175,7 @@ struct InvidiousPlaylist
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(offset, locale, json : JSON::Builder, video_id : String? = nil)
|
||||
def to_json(offset, json : JSON::Builder, video_id : String? = nil)
|
||||
json.object do
|
||||
json.field "type", "invidiousPlaylist"
|
||||
json.field "title", self.title
|
||||
@ -205,7 +201,7 @@ struct InvidiousPlaylist
|
||||
offset = self.index.index(index) || 0
|
||||
end
|
||||
|
||||
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
|
||||
videos = get_playlist_videos(self, offset: offset, video_id: video_id)
|
||||
videos.each_with_index do |video, index|
|
||||
video.to_json(json, offset + index)
|
||||
end
|
||||
@ -214,13 +210,9 @@ struct InvidiousPlaylist
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(offset, locale, json : JSON::Builder? = nil, video_id : String? = nil)
|
||||
if json
|
||||
to_json(offset, locale, json, video_id: video_id)
|
||||
else
|
||||
JSON.build do |json|
|
||||
to_json(offset, locale, json, video_id: video_id)
|
||||
end
|
||||
def to_json(offset, _json : Nil = nil, video_id : String? = nil)
|
||||
JSON.build do |json|
|
||||
to_json(offset, json, video_id: video_id)
|
||||
end
|
||||
end
|
||||
|
||||
@ -320,7 +312,7 @@ def produce_playlist_continuation(id, index)
|
||||
return continuation
|
||||
end
|
||||
|
||||
def get_playlist(plid, locale, refresh = true, force_refresh = false)
|
||||
def get_playlist(plid : String)
|
||||
if plid.starts_with? "IV"
|
||||
if playlist = Invidious::Database::Playlists.select(id: plid)
|
||||
return playlist
|
||||
@ -328,11 +320,11 @@ def get_playlist(plid, locale, refresh = true, force_refresh = false)
|
||||
raise InfoException.new("Playlist does not exist.")
|
||||
end
|
||||
else
|
||||
return fetch_playlist(plid, locale)
|
||||
return fetch_playlist(plid)
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_playlist(plid, locale)
|
||||
def fetch_playlist(plid : String)
|
||||
if plid.starts_with? "UC"
|
||||
plid = "UU#{plid.lchop("UC")}"
|
||||
end
|
||||
@ -402,7 +394,7 @@ def fetch_playlist(plid, locale)
|
||||
})
|
||||
end
|
||||
|
||||
def get_playlist_videos(playlist, offset, locale = nil, video_id = nil)
|
||||
def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32, video_id = nil)
|
||||
# Show empy playlist if requested page is out of range
|
||||
# (e.g, when a new playlist has been created, offset will be negative)
|
||||
if offset >= playlist.video_count || offset < 0
|
||||
|
@ -125,7 +125,7 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
playlists.each do |playlist|
|
||||
playlist.to_json(0, locale, json)
|
||||
playlist.to_json(0, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ module Invidious::Routes::API::V1::Misc
|
||||
# APIv1 currently uses the same logic for both
|
||||
# user playlists and Invidious playlists. This means that we can't
|
||||
# reasonably split them yet. This should be addressed in APIv2
|
||||
def self.get_playlist(env)
|
||||
def self.get_playlist(env : HTTP::Server::Context)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
@ -34,7 +34,7 @@ module Invidious::Routes::API::V1::Misc
|
||||
end
|
||||
|
||||
begin
|
||||
playlist = get_playlist(plid, locale)
|
||||
playlist = get_playlist(plid)
|
||||
rescue ex : InfoException
|
||||
return error_json(404, ex)
|
||||
rescue ex
|
||||
@ -49,7 +49,7 @@ module Invidious::Routes::API::V1::Misc
|
||||
# includes into the playlist a maximum of 20 videos, before the offset
|
||||
if offset > 0
|
||||
lookback = offset < 50 ? offset : 50
|
||||
response = playlist.to_json(offset - lookback, locale)
|
||||
response = playlist.to_json(offset - lookback)
|
||||
json_response = JSON.parse(response)
|
||||
else
|
||||
# Unless the continuation is really the offset 0, it becomes expensive.
|
||||
@ -58,13 +58,13 @@ module Invidious::Routes::API::V1::Misc
|
||||
# it shouldn't happen often though
|
||||
|
||||
lookback = 0
|
||||
response = playlist.to_json(offset, locale, video_id: video_id)
|
||||
response = playlist.to_json(offset, video_id: video_id)
|
||||
json_response = JSON.parse(response)
|
||||
|
||||
if json_response["videos"].as_a[0]["index"] != offset
|
||||
offset = json_response["videos"].as_a[0]["index"].as_i
|
||||
lookback = offset < 50 ? offset : 50
|
||||
response = playlist.to_json(offset - lookback, locale)
|
||||
response = playlist.to_json(offset - lookback)
|
||||
json_response = JSON.parse(response)
|
||||
end
|
||||
end
|
||||
|
@ -6,9 +6,9 @@ module Invidious::Routes::Embed
|
||||
|
||||
if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
||||
begin
|
||||
playlist = get_playlist(plid, locale: locale)
|
||||
playlist = get_playlist(plid)
|
||||
offset = env.params.query["index"]?.try &.to_i? || 0
|
||||
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
|
||||
videos = get_playlist_videos(playlist, offset: offset)
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
@ -60,9 +60,9 @@ module Invidious::Routes::Embed
|
||||
|
||||
if plid
|
||||
begin
|
||||
playlist = get_playlist(plid, locale: locale)
|
||||
playlist = get_playlist(plid)
|
||||
offset = env.params.query["index"]?.try &.to_i? || 0
|
||||
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
|
||||
videos = get_playlist_videos(playlist, offset: offset)
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
|
@ -265,7 +265,7 @@ module Invidious::Routes::Feeds
|
||||
|
||||
if plid.starts_with? "IV"
|
||||
if playlist = Invidious::Database::Playlists.select(id: plid)
|
||||
videos = get_playlist_videos(playlist, offset: 0, locale: locale)
|
||||
videos = get_playlist_videos(playlist, offset: 0)
|
||||
|
||||
return XML.build(indent: " ", encoding: "UTF-8") do |xml|
|
||||
xml.element("feed", "xmlns:yt": "http://www.youtube.com/xml/schemas/2015",
|
||||
|
@ -66,7 +66,7 @@ module Invidious::Routes::Playlists
|
||||
user = user.as(User)
|
||||
|
||||
playlist_id = env.params.query["list"]
|
||||
playlist = get_playlist(playlist_id, locale)
|
||||
playlist = get_playlist(playlist_id)
|
||||
subscribe_playlist(user, playlist)
|
||||
|
||||
env.redirect "/playlist?list=#{playlist.id}"
|
||||
@ -161,7 +161,7 @@ module Invidious::Routes::Playlists
|
||||
end
|
||||
|
||||
begin
|
||||
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
|
||||
videos = get_playlist_videos(playlist, offset: (page - 1) * 100)
|
||||
rescue ex
|
||||
videos = [] of PlaylistVideo
|
||||
end
|
||||
@ -314,7 +314,7 @@ module Invidious::Routes::Playlists
|
||||
|
||||
begin
|
||||
playlist_id = env.params.query["playlist_id"]
|
||||
playlist = get_playlist(playlist_id, locale).as(InvidiousPlaylist)
|
||||
playlist = get_playlist(playlist_id).as(InvidiousPlaylist)
|
||||
raise "Invalid user" if playlist.author != user.email
|
||||
rescue ex
|
||||
if redirect
|
||||
@ -405,7 +405,7 @@ module Invidious::Routes::Playlists
|
||||
end
|
||||
|
||||
begin
|
||||
playlist = get_playlist(plid, locale)
|
||||
playlist = get_playlist(plid)
|
||||
rescue ex
|
||||
return error_template(500, ex)
|
||||
end
|
||||
@ -422,7 +422,7 @@ module Invidious::Routes::Playlists
|
||||
end
|
||||
|
||||
begin
|
||||
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
|
||||
videos = get_playlist_videos(playlist, offset: (page - 1) * 100)
|
||||
rescue ex
|
||||
return error_template(500, "Error encountered while retrieving playlist videos.<br>#{ex.message}")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user