diff --git a/src/invidious.cr b/src/invidious.cr index cbcba12e..5764a239 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2374,7 +2374,6 @@ get "/channel/:ucid" do |env| continuation = env.params.query["continuation"]? sort_by = env.params.query["sort_by"]?.try &.downcase - sort_by ||= "newest" begin author, ucid, auto_generated, sub_count = get_about_info(ucid, locale) @@ -2392,11 +2391,17 @@ get "/channel/:ucid" do |env| end if auto_generated + sort_options = {"last", "oldest", "newest"} + sort_by ||= "last" + items, continuation = fetch_channel_playlists(ucid, author, auto_generated, continuation, sort_by) items.select! { |item| item.is_a?(SearchPlaylist) && !item.videos.empty? } items = items.map { |item| item.as(SearchPlaylist) } items.each { |item| item.author = "" } else + sort_options = {"newest", "oldest", "popular"} + sort_by ||= "newest" + items, count = get_60_videos(ucid, page, auto_generated, sort_by) items.select! { |item| !item.paid } end @@ -2419,6 +2424,42 @@ get "/channel/:ucid/videos" do |env| env.redirect "/channel/#{ucid}#{params}" end +get "/channel/:ucid/playlists" do |env| + locale = LOCALES[env.get("locale").as(String)]? + + user = env.get? "user" + if user + user = user.as(User) + subscriptions = user.subscriptions + end + subscriptions ||= [] of String + + ucid = env.params.url["ucid"] + + continuation = env.params.query["continuation"]? + + sort_by = env.params.query["sort_by"]?.try &.downcase + sort_by ||= "last" + + begin + author, ucid, auto_generated, sub_count = get_about_info(ucid, locale) + rescue ex + error_message = ex.message + next templated "error" + end + + if auto_generated + next env.redirect "/channel/#{ucid}" + end + + items, continuation = fetch_channel_playlists(ucid, author, auto_generated, continuation, sort_by) + items.select! { |item| item.is_a?(SearchPlaylist) && !item.videos.empty? } + items = items.map { |item| item.as(SearchPlaylist) } + items.each { |item| item.author = "" } + + templated "playlists" +end + # API Endpoints get "/api/v1/stats" do |env| diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr index 65c289c5..897c2b3a 100644 --- a/src/invidious/views/channel.ecr +++ b/src/invidious/views/channel.ecr @@ -21,12 +21,20 @@
<%= translate(locale, "View channel on YouTube") %> +
+ <%= translate(locale, "Videos") %> +
+
+ <% if !auto_generated %> + <%= translate(locale, "Playlists") %> + <% end %> +
- <% {"newest", "oldest", "popular"}.each do |sort| %> + <% sort_options.each do |sort| %>
<% if sort_by == sort %> <%= translate(locale, sort) %> diff --git a/src/invidious/views/playlists.ecr b/src/invidious/views/playlists.ecr new file mode 100644 index 00000000..3f661494 --- /dev/null +++ b/src/invidious/views/playlists.ecr @@ -0,0 +1,80 @@ +<% content_for "header" do %> +<%= author %> - Invidious +<% end %> + +
+
+

<%= author %>

+
+
+

+ +

+
+
+ +
+<% sub_count_text = number_to_short_text(sub_count) %> +<%= rendered "components/subscribe_widget" %> +
+ +
+
+ + +
+ <% if !auto_generated %> + <%= translate(locale, "Playlists") %> + <% end %> +
+
+
+
+
+
+ <% {"last", "oldest", "newest"}.each do |sort| %> +
+ <% if sort_by == sort %> + <%= translate(locale, sort) %> + <% else %> + + <%= translate(locale, sort) %> + + <% end %> +
+ <% end %> +
+
+
+ +
+
+
+ +
+<% items.each_slice(4) do |slice| %> + <% slice.each do |item| %> + <%= rendered "components/item" %> + <% end %> +<% end %> +
+ + + +