Skip to content

Commit 5e3c9cf

Browse files
committed
Remove useless arguments from playlist-related functions
1 parent 2ae074a commit 5e3c9cf

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

src/invidious/playlists.cr

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct Playlist
9090
property updated : Time
9191
property thumbnail : String?
9292

93-
def to_json(offset, locale, json : JSON::Builder, video_id : String? = nil)
93+
def to_json(offset, json : JSON::Builder, video_id : String? = nil)
9494
json.object do
9595
json.field "type", "playlist"
9696
json.field "title", self.title
@@ -125,7 +125,7 @@ struct Playlist
125125

126126
json.field "videos" do
127127
json.array do
128-
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
128+
videos = get_playlist_videos(self, offset: offset, video_id: video_id)
129129
videos.each do |video|
130130
video.to_json(json)
131131
end
@@ -134,13 +134,9 @@ struct Playlist
134134
end
135135
end
136136

137-
def to_json(offset, locale, json : JSON::Builder? = nil, video_id : String? = nil)
138-
if json
139-
to_json(offset, locale, json, video_id: video_id)
140-
else
141-
JSON.build do |json|
142-
to_json(offset, locale, json, video_id: video_id)
143-
end
137+
def to_json(offset, _json : Nil = nil, video_id : String? = nil)
138+
JSON.build do |json|
139+
to_json(offset, json, video_id: video_id)
144140
end
145141
end
146142

@@ -179,7 +175,7 @@ struct InvidiousPlaylist
179175
end
180176
end
181177

182-
def to_json(offset, locale, json : JSON::Builder, video_id : String? = nil)
178+
def to_json(offset, json : JSON::Builder, video_id : String? = nil)
183179
json.object do
184180
json.field "type", "invidiousPlaylist"
185181
json.field "title", self.title
@@ -205,7 +201,7 @@ struct InvidiousPlaylist
205201
offset = self.index.index(index) || 0
206202
end
207203

208-
videos = get_playlist_videos(self, offset: offset, locale: locale, video_id: video_id)
204+
videos = get_playlist_videos(self, offset: offset, video_id: video_id)
209205
videos.each_with_index do |video, index|
210206
video.to_json(json, offset + index)
211207
end
@@ -214,13 +210,9 @@ struct InvidiousPlaylist
214210
end
215211
end
216212

217-
def to_json(offset, locale, json : JSON::Builder? = nil, video_id : String? = nil)
218-
if json
219-
to_json(offset, locale, json, video_id: video_id)
220-
else
221-
JSON.build do |json|
222-
to_json(offset, locale, json, video_id: video_id)
223-
end
213+
def to_json(offset, _json : Nil = nil, video_id : String? = nil)
214+
JSON.build do |json|
215+
to_json(offset, json, video_id: video_id)
224216
end
225217
end
226218

@@ -320,19 +312,19 @@ def produce_playlist_continuation(id, index)
320312
return continuation
321313
end
322314

323-
def get_playlist(plid, locale, refresh = true, force_refresh = false)
315+
def get_playlist(plid : String)
324316
if plid.starts_with? "IV"
325317
if playlist = Invidious::Database::Playlists.select(id: plid)
326318
return playlist
327319
else
328320
raise InfoException.new("Playlist does not exist.")
329321
end
330322
else
331-
return fetch_playlist(plid, locale)
323+
return fetch_playlist(plid)
332324
end
333325
end
334326

335-
def fetch_playlist(plid, locale)
327+
def fetch_playlist(plid : String)
336328
if plid.starts_with? "UC"
337329
plid = "UU#{plid.lchop("UC")}"
338330
end
@@ -402,7 +394,7 @@ def fetch_playlist(plid, locale)
402394
})
403395
end
404396

405-
def get_playlist_videos(playlist, offset, locale = nil, video_id = nil)
397+
def get_playlist_videos(playlist : InvidiousPlaylist | Playlist, offset : Int32, video_id = nil)
406398
# Show empy playlist if requested page is out of range
407399
# (e.g, when a new playlist has been created, offset will be negative)
408400
if offset >= playlist.video_count || offset < 0

src/invidious/routes/api/v1/authenticated.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module Invidious::Routes::API::V1::Authenticated
125125
JSON.build do |json|
126126
json.array do
127127
playlists.each do |playlist|
128-
playlist.to_json(0, locale, json)
128+
playlist.to_json(0, json)
129129
end
130130
end
131131
end

src/invidious/routes/api/v1/misc.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Invidious::Routes::API::V1::Misc
1414
# APIv1 currently uses the same logic for both
1515
# user playlists and Invidious playlists. This means that we can't
1616
# reasonably split them yet. This should be addressed in APIv2
17-
def self.get_playlist(env)
17+
def self.get_playlist(env : HTTP::Server::Context)
1818
locale = env.get("preferences").as(Preferences).locale
1919

2020
env.response.content_type = "application/json"
@@ -34,7 +34,7 @@ module Invidious::Routes::API::V1::Misc
3434
end
3535

3636
begin
37-
playlist = get_playlist(plid, locale)
37+
playlist = get_playlist(plid)
3838
rescue ex : InfoException
3939
return error_json(404, ex)
4040
rescue ex
@@ -49,7 +49,7 @@ module Invidious::Routes::API::V1::Misc
4949
# includes into the playlist a maximum of 20 videos, before the offset
5050
if offset > 0
5151
lookback = offset < 50 ? offset : 50
52-
response = playlist.to_json(offset - lookback, locale)
52+
response = playlist.to_json(offset - lookback)
5353
json_response = JSON.parse(response)
5454
else
5555
# Unless the continuation is really the offset 0, it becomes expensive.
@@ -58,13 +58,13 @@ module Invidious::Routes::API::V1::Misc
5858
# it shouldn't happen often though
5959

6060
lookback = 0
61-
response = playlist.to_json(offset, locale, video_id: video_id)
61+
response = playlist.to_json(offset, video_id: video_id)
6262
json_response = JSON.parse(response)
6363

6464
if json_response["videos"].as_a[0]["index"] != offset
6565
offset = json_response["videos"].as_a[0]["index"].as_i
6666
lookback = offset < 50 ? offset : 50
67-
response = playlist.to_json(offset - lookback, locale)
67+
response = playlist.to_json(offset - lookback)
6868
json_response = JSON.parse(response)
6969
end
7070
end

src/invidious/routes/embed.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module Invidious::Routes::Embed
66

77
if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
88
begin
9-
playlist = get_playlist(plid, locale: locale)
9+
playlist = get_playlist(plid)
1010
offset = env.params.query["index"]?.try &.to_i? || 0
11-
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
11+
videos = get_playlist_videos(playlist, offset: offset)
1212
rescue ex
1313
return error_template(500, ex)
1414
end
@@ -60,9 +60,9 @@ module Invidious::Routes::Embed
6060

6161
if plid
6262
begin
63-
playlist = get_playlist(plid, locale: locale)
63+
playlist = get_playlist(plid)
6464
offset = env.params.query["index"]?.try &.to_i? || 0
65-
videos = get_playlist_videos(playlist, offset: offset, locale: locale)
65+
videos = get_playlist_videos(playlist, offset: offset)
6666
rescue ex
6767
return error_template(500, ex)
6868
end

src/invidious/routes/feeds.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ module Invidious::Routes::Feeds
265265

266266
if plid.starts_with? "IV"
267267
if playlist = Invidious::Database::Playlists.select(id: plid)
268-
videos = get_playlist_videos(playlist, offset: 0, locale: locale)
268+
videos = get_playlist_videos(playlist, offset: 0)
269269

270270
return XML.build(indent: " ", encoding: "UTF-8") do |xml|
271271
xml.element("feed", "xmlns:yt": "http://www.youtube.com/xml/schemas/2015",

src/invidious/routes/playlists.cr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module Invidious::Routes::Playlists
6666
user = user.as(User)
6767

6868
playlist_id = env.params.query["list"]
69-
playlist = get_playlist(playlist_id, locale)
69+
playlist = get_playlist(playlist_id)
7070
subscribe_playlist(user, playlist)
7171

7272
env.redirect "/playlist?list=#{playlist.id}"
@@ -161,7 +161,7 @@ module Invidious::Routes::Playlists
161161
end
162162

163163
begin
164-
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
164+
videos = get_playlist_videos(playlist, offset: (page - 1) * 100)
165165
rescue ex
166166
videos = [] of PlaylistVideo
167167
end
@@ -314,7 +314,7 @@ module Invidious::Routes::Playlists
314314

315315
begin
316316
playlist_id = env.params.query["playlist_id"]
317-
playlist = get_playlist(playlist_id, locale).as(InvidiousPlaylist)
317+
playlist = get_playlist(playlist_id).as(InvidiousPlaylist)
318318
raise "Invalid user" if playlist.author != user.email
319319
rescue ex
320320
if redirect
@@ -405,7 +405,7 @@ module Invidious::Routes::Playlists
405405
end
406406

407407
begin
408-
playlist = get_playlist(plid, locale)
408+
playlist = get_playlist(plid)
409409
rescue ex
410410
return error_template(500, ex)
411411
end
@@ -422,7 +422,7 @@ module Invidious::Routes::Playlists
422422
end
423423

424424
begin
425-
videos = get_playlist_videos(playlist, offset: (page - 1) * 100, locale: locale)
425+
videos = get_playlist_videos(playlist, offset: (page - 1) * 100)
426426
rescue ex
427427
return error_template(500, "Error encountered while retrieving playlist videos.<br>#{ex.message}")
428428
end

0 commit comments

Comments
 (0)