mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Add support for user name in place of :ucid
This commit is contained in:
parent
fcb4f4cddb
commit
ea8aaf3145
2 changed files with 43 additions and 4 deletions
|
@ -1055,6 +1055,19 @@ get "/api/v1/channels/:ucid" do |env|
|
||||||
ucid = env.params.url["ucid"]
|
ucid = env.params.url["ucid"]
|
||||||
|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
||||||
|
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
||||||
|
rss = XML.parse_html(rss)
|
||||||
|
|
||||||
|
ucid = rss.xpath_node("//feed/channelid")
|
||||||
|
if ucid
|
||||||
|
ucid = ucid.content
|
||||||
|
else
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
next {"error" => "User does not exist"}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
channel = get_channel(ucid, client, PG_DB, pull_all_videos: false)
|
channel = get_channel(ucid, client, PG_DB, pull_all_videos: false)
|
||||||
|
|
||||||
# TODO: Integrate this into `get_channel` function
|
# TODO: Integrate this into `get_channel` function
|
||||||
|
@ -1171,8 +1184,21 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
||||||
page = env.params.query["page"]?.try &.to_i?
|
page = env.params.query["page"]?.try &.to_i?
|
||||||
page ||= 1
|
page ||= 1
|
||||||
|
|
||||||
url = produce_videos_url(ucid, page)
|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
||||||
|
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
||||||
|
rss = XML.parse_html(rss)
|
||||||
|
|
||||||
|
ucid = rss.xpath_node("//feed/channelid")
|
||||||
|
if ucid
|
||||||
|
ucid = ucid.content
|
||||||
|
else
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
next {"error" => "User does not exist"}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
url = produce_videos_url(ucid, page)
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
|
@ -2055,8 +2081,21 @@ end
|
||||||
get "/feed/channel/:ucid" do |env|
|
get "/feed/channel/:ucid" do |env|
|
||||||
ucid = env.params.url["ucid"]
|
ucid = env.params.url["ucid"]
|
||||||
|
|
||||||
url = produce_videos_url(ucid)
|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
||||||
|
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
||||||
|
rss = XML.parse_html(rss)
|
||||||
|
|
||||||
|
ucid = rss.xpath_node("//feed/channelid")
|
||||||
|
if ucid
|
||||||
|
ucid = ucid.content
|
||||||
|
else
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
next {"error" => "User does not exist"}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
url = produce_videos_url(ucid)
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
|
|
||||||
channel = get_channel(ucid, client, PG_DB, pull_all_videos: false)
|
channel = get_channel(ucid, client, PG_DB, pull_all_videos: false)
|
||||||
|
@ -2638,7 +2677,7 @@ get "/channel/:ucid" do |env|
|
||||||
|
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
|
||||||
if !ucid.starts_with? "UC"
|
if !ucid.match(/UC[a-zA-Z0-9_-]{22}/)
|
||||||
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
rss = client.get("/feeds/videos.xml?user=#{ucid}").body
|
||||||
rss = XML.parse_html(rss)
|
rss = XML.parse_html(rss)
|
||||||
|
|
||||||
|
|
|
@ -253,8 +253,8 @@ def elapsed_text(elapsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_video(id)
|
def fetch_video(id)
|
||||||
info_channel = Channel(HTTP::Params).new
|
|
||||||
html_channel = Channel(XML::Node).new
|
html_channel = Channel(XML::Node).new
|
||||||
|
info_channel = Channel(HTTP::Params).new
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
client = make_client(YT_URL)
|
client = make_client(YT_URL)
|
||||||
|
|
Loading…
Reference in a new issue