Skip to content

Commit 2ae074a

Browse files
authored
Merge pull request #2821 from matthewmcgarvey/channel-search
Handle invalid channel id in channel: search
2 parents 5ece07a + c5967ad commit 2ae074a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/invidious/routes/search.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module Invidious::Routes::Search
5555

5656
begin
5757
search_query, count, videos, operators = process_search_query(query, page, user, region: region)
58+
rescue ex : ChannelSearchException
59+
return error_template(404, "Unable to find channel with id of '#{HTML.escape(ex.channel)}'. Are you sure that's an actual channel id? It should look like 'UC4QobU6STFB0P71PMvOGN5A'.")
5860
rescue ex
5961
return error_template(500, ex)
6062
end

src/invidious/search.cr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
class ChannelSearchException < InfoException
2+
getter channel : String
3+
4+
def initialize(@channel)
5+
end
6+
end
7+
18
def channel_search(query, page, channel)
29
response = YT_POOL.client &.get("/channel/#{channel}")
310

411
if response.status_code == 404
512
response = YT_POOL.client &.get("/user/#{channel}")
613
response = YT_POOL.client &.get("/c/#{channel}") if response.status_code == 404
714
initial_data = extract_initial_data(response.body)
8-
ucid = initial_data["header"]["c4TabbedHeaderRenderer"]?.try &.["channelId"].as_s?
9-
raise InfoException.new("Impossible to extract channel ID from page") if !ucid
15+
ucid = initial_data.dig?("header", "c4TabbedHeaderRenderer", "channelId").try(&.as_s?)
16+
raise ChannelSearchException.new(channel) if !ucid
1017
else
1118
ucid = channel
1219
end

0 commit comments

Comments
 (0)