summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/stale.yml22
-rw-r--r--src/invidious.cr67
-rw-r--r--src/invidious/channels.cr4
-rw-r--r--src/invidious/routes/search.cr59
-rw-r--r--src/invidious/videos.cr14
5 files changed, 98 insertions, 68 deletions
diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml
new file mode 100644
index 00000000..e452274b
--- /dev/null
+++ b/.github/workflows/stale.yml
@@ -0,0 +1,22 @@
+# Documentation: https://github.com/marketplace/actions/close-stale-issues
+
+name: "Stale issue handler"
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: "0 */12 * * *"
+
+jobs:
+ stale:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/stale@v3
+ with:
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
+ days-before-stale: 365
+ days-before-close: 30
+ stale-issue-message: 'This issue has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this issue is still relevant and applicable, you just have to post a comment and it will be unmarked.'
+ stale-pr-message: 'This pull request has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this pull request is still relevant and applicable, you just have to post a comment and it will be unmarked.'
+ stale-issue-label: "stale"
+ stale-pr-label: "stale"
+ ascending: true
diff --git a/src/invidious.cr b/src/invidious.cr
index 4793a60a..0e8c2324 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -64,7 +64,7 @@ HTTP_CHUNK_SIZE = 10485760 # ~10MB
CURRENT_BRANCH = {{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}
CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}
-CURRENT_VERSION = {{ "#{`git log -1 --format=%cs | sed s/-/./g`.strip}" }}
+CURRENT_VERSION = {{ "#{`git log -1 --format=%ci | date -I -f - | sed s/-/./g`.strip}" }}
# This is used to determine the `?v=` on the end of file URLs (for cache busting). We
# only need to expire modified assets, so we can use this to find the last commit that changes
@@ -311,68 +311,9 @@ Invidious::Routing.get "/add_playlist_items", Invidious::Routes::Playlists, :add
Invidious::Routing.post "/playlist_ajax", Invidious::Routes::Playlists, :playlist_ajax
Invidious::Routing.get "/playlist", Invidious::Routes::Playlists, :show
Invidious::Routing.get "/mix", Invidious::Routes::Playlists, :mix
-
-# Search
-
-get "/opensearch.xml" do |env|
- locale = LOCALES[env.get("preferences").as(Preferences).locale]?
- env.response.content_type = "application/opensearchdescription+xml"
-
- XML.build(indent: " ", encoding: "UTF-8") do |xml|
- xml.element("OpenSearchDescription", xmlns: "http://a9.com/-/spec/opensearch/1.1/") do
- xml.element("ShortName") { xml.text "Invidious" }
- xml.element("LongName") { xml.text "Invidious Search" }
- xml.element("Description") { xml.text "Search for videos, channels, and playlists on Invidious" }
- xml.element("InputEncoding") { xml.text "UTF-8" }
- xml.element("Image", width: 48, height: 48, type: "image/x-icon") { xml.text "#{HOST_URL}/favicon.ico" }
- xml.element("Url", type: "text/html", method: "get", template: "#{HOST_URL}/search?q={searchTerms}")
- end
- end
-end
-
-get "/results" do |env|
- locale = LOCALES[env.get("preferences").as(Preferences).locale]?
-
- query = env.params.query["search_query"]?
- query ||= env.params.query["q"]?
- query ||= ""
-
- page = env.params.query["page"]?.try &.to_i?
- page ||= 1
-
- if query
- env.redirect "/search?q=#{URI.encode_www_form(query)}&page=#{page}"
- else
- env.redirect "/"
- end
-end
-
-get "/search" do |env|
- locale = LOCALES[env.get("preferences").as(Preferences).locale]?
- region = env.params.query["region"]?
-
- query = env.params.query["search_query"]?
- query ||= env.params.query["q"]?
- query ||= ""
-
- if query.empty?
- next env.redirect "/"
- end
-
- page = env.params.query["page"]?.try &.to_i?
- page ||= 1
-
- user = env.get? "user"
-
- begin
- search_query, count, videos = process_search_query(query, page, user, region: nil)
- rescue ex
- next error_template(500, ex)
- end
-
- env.set "search", query
- templated "search"
-end
+Invidious::Routing.get "/opensearch.xml", Invidious::Routes::Search, :opensearch
+Invidious::Routing.get "/results", Invidious::Routes::Search, :results
+Invidious::Routing.get "/search", Invidious::Routes::Search, :search
# Users
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index 93507c56..444a6eda 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -801,6 +801,10 @@ def get_about_info(ucid, locale)
raise InfoException.new(error_message)
end
+ if browse_endpoint = initdata["onResponseReceivedActions"]?.try &.[0]?.try &.["navigateAction"]?.try &.["endpoint"]?.try &.["browseEndpoint"]?
+ raise ChannelRedirect.new(channel_id: browse_endpoint["browseId"].to_s)
+ end
+
author = initdata["metadata"]["channelMetadataRenderer"]["title"].as_s
author_url = initdata["metadata"]["channelMetadataRenderer"]["channelUrl"].as_s
author_thumbnail = initdata["metadata"]["channelMetadataRenderer"]["avatar"]["thumbnails"][0]["url"].as_s
diff --git a/src/invidious/routes/search.cr b/src/invidious/routes/search.cr
new file mode 100644
index 00000000..48446161
--- /dev/null
+++ b/src/invidious/routes/search.cr
@@ -0,0 +1,59 @@
+class Invidious::Routes::Search < Invidious::Routes::BaseRoute
+ def opensearch(env)
+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?
+ env.response.content_type = "application/opensearchdescription+xml"
+
+ XML.build(indent: " ", encoding: "UTF-8") do |xml|
+ xml.element("OpenSearchDescription", xmlns: "http://a9.com/-/spec/opensearch/1.1/") do
+ xml.element("ShortName") { xml.text "Invidious" }
+ xml.element("LongName") { xml.text "Invidious Search" }
+ xml.element("Description") { xml.text "Search for videos, channels, and playlists on Invidious" }
+ xml.element("InputEncoding") { xml.text "UTF-8" }
+ xml.element("Image", width: 48, height: 48, type: "image/x-icon") { xml.text "#{HOST_URL}/favicon.ico" }
+ xml.element("Url", type: "text/html", method: "get", template: "#{HOST_URL}/search?q={searchTerms}")
+ end
+ end
+ end
+
+ def results(env)
+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?
+
+ query = env.params.query["search_query"]?
+ query ||= env.params.query["q"]?
+ query ||= ""
+
+ page = env.params.query["page"]?.try &.to_i?
+ page ||= 1
+
+ if query
+ env.redirect "/search?q=#{URI.encode_www_form(query)}&page=#{page}"
+ else
+ env.redirect "/"
+ end
+ end
+
+ def search(env)
+ locale = LOCALES[env.get("preferences").as(Preferences).locale]?
+ region = env.params.query["region"]?
+
+ query = env.params.query["search_query"]?
+ query ||= env.params.query["q"]?
+ query ||= ""
+
+ return env.redirect "/" if query.empty?
+
+ page = env.params.query["page"]?.try &.to_i?
+ page ||= 1
+
+ user = env.get? "user"
+
+ begin
+ search_query, count, videos = process_search_query(query, page, user, region: nil)
+ rescue ex
+ return error_template(500, ex)
+ end
+
+ env.set "search", query
+ templated "search"
+ end
+end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 8b20c181..edbff14e 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -816,7 +816,7 @@ end
def extract_polymer_config(body)
params = {} of String => JSON::Any
- player_response = body.match(/window\["ytInitialPlayerResponse"\]\s*=\s*(?<info>.*?);\n/)
+ player_response = body.match(/(window\["ytInitialPlayerResponse"\]|var\sytInitialPlayerResponse)\s*=\s*(?<info>{.*?});/m)
.try { |r| JSON.parse(r["info"]).as_h }
if body.includes?("To continue with your YouTube experience, please fill out the form below.") ||
@@ -914,10 +914,14 @@ def extract_polymer_config(body)
.try { |r| JSON.parse(r["info"]) }.try &.["args"]["player_response"]?
.try &.as_s?.try &.try { |r| JSON.parse(r).as_h }
- return params if !initial_data
-
- {"playabilityStatus", "streamingData"}.each do |f|
- params[f] = initial_data[f] if initial_data[f]?
+ if initial_data
+ {"playabilityStatus", "streamingData"}.each do |f|
+ params[f] = initial_data[f] if initial_data[f]?
+ end
+ else
+ {"playabilityStatus", "streamingData"}.each do |f|
+ params[f] = player_response[f] if player_response[f]?
+ end
end
params