summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-03-22 10:32:42 -0500
committerOmar Roth <omarroth@hotmail.com>2019-03-22 14:52:57 -0500
commitf0658bbd092af23e097ac52a1587688ec9ee17df (patch)
treea88a692bc58e5b516216f1bcc007321d49624bb8
parent661e07c8dbe046c2f43849efe7fb24477b547061 (diff)
downloadinvidious-f0658bbd092af23e097ac52a1587688ec9ee17df.tar.gz
invidious-f0658bbd092af23e097ac52a1587688ec9ee17df.tar.bz2
invidious-f0658bbd092af23e097ac52a1587688ec9ee17df.zip
Add 'liveNow' to subscription feed
-rwxr-xr-xconfig/migrate-scripts/migrate-db-6e51189.sh4
-rwxr-xr-xconfig/migrate-scripts/migrate-db-8e884fe.sh (renamed from config/migrate-scripts/migrate-db-8e884fe1.sh)0
-rw-r--r--src/invidious.cr18
-rw-r--r--src/invidious/channels.cr12
-rw-r--r--src/invidious/videos.cr30
5 files changed, 48 insertions, 16 deletions
diff --git a/config/migrate-scripts/migrate-db-6e51189.sh b/config/migrate-scripts/migrate-db-6e51189.sh
new file mode 100755
index 00000000..80f222bb
--- /dev/null
+++ b/config/migrate-scripts/migrate-db-6e51189.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+psql invidious -c "ALTER TABLE channel_videos ADD COLUMN live_now bool;"
+psql invidious -c "UPDATE channel_videos SET live_now = false;" \ No newline at end of file
diff --git a/config/migrate-scripts/migrate-db-8e884fe1.sh b/config/migrate-scripts/migrate-db-8e884fe.sh
index 095c7632..095c7632 100755
--- a/config/migrate-scripts/migrate-db-8e884fe1.sh
+++ b/config/migrate-scripts/migrate-db-8e884fe.sh
diff --git a/src/invidious.cr b/src/invidious.cr
index af810bd2..8707461e 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -2372,7 +2372,7 @@ post "/feed/webhook/:token" do |env|
updated = Time.parse_rfc3339(entry.xpath_node("updated").not_nil!.content)
video = get_video(id, PG_DB, proxies, region: nil)
- video = ChannelVideo.new(id, video.title, published, updated, video.ucid, video.author, video.length_seconds)
+ video = ChannelVideo.new(id, video.title, published, updated, video.ucid, video.author, video.length_seconds, video.live_now)
PG_DB.exec("UPDATE users SET notifications = notifications || $1 \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, video.ucid)
@@ -2382,7 +2382,7 @@ post "/feed/webhook/:token" do |env|
PG_DB.exec("INSERT INTO channel_videos VALUES (#{args}) \
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
- updated = $4, ucid = $5, author = $6, length_seconds = $7", video_array)
+ updated = $4, ucid = $5, author = $6, length_seconds = $7, live_now = $8", video_array)
end
end
@@ -2895,16 +2895,10 @@ get "/api/v1/videos/:id" do |env|
json.field "subCountText", video.sub_count_text
json.field "lengthSeconds", video.info["length_seconds"].to_i
- if video.info["allow_ratings"]?
- json.field "allowRatings", video.info["allow_ratings"] == "1"
- else
- json.field "allowRatings", false
- end
+ json.field "allowRatings", video.allow_ratings
json.field "rating", video.info["avg_rating"].to_f32
-
- if video.info["is_listed"]?
- json.field "isListed", video.info["is_listed"] == "1"
- end
+ json.field "isListed", video.is_listed
+ json.field "liveNow", video.live_now
if video.player_response["streamingData"]?.try &.["hlsManifestUrl"]?
host_url = make_host_url(config, Kemal.config)
@@ -4011,7 +4005,7 @@ get "/api/manifest/dash/id/:id" do |env|
halt env, status_code: 403
end
- if dashmpd = video.player_response["streamingData"]["dashManifestUrl"]?.try &.as_s
+ if dashmpd = video.player_response["streamingData"]?.try &.["dashManifestUrl"]?.try &.as_s
manifest = client.get(dashmpd).body
manifest = manifest.gsub(/<BaseURL>[^<]+<\/BaseURL>/) do |baseurl|
diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr
index 3ecfe529..ef1bfc5e 100644
--- a/src/invidious/channels.cr
+++ b/src/invidious/channels.cr
@@ -17,6 +17,7 @@ class ChannelVideo
ucid: String,
author: String,
length_seconds: {type: Int32, default: 0},
+ live_now: {type: Bool, default: false},
})
end
@@ -120,7 +121,10 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
length_seconds = videos.select { |video| video.id == video_id }[0]?.try &.length_seconds
length_seconds ||= 0
- video = ChannelVideo.new(video_id, title, published, Time.now, ucid, author, length_seconds)
+ live_now = videos.select { |video| video.id == video_id }[0]?.try &.live_now
+ live_now ||= false
+
+ video = ChannelVideo.new(video_id, title, published, Time.now, ucid, author, length_seconds, live_now)
db.exec("UPDATE users SET notifications = notifications || $1 \
WHERE updated < $2 AND $3 = ANY(subscriptions) AND $1 <> ALL(notifications)", video.id, video.published, ucid)
@@ -130,7 +134,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
db.exec("INSERT INTO channel_videos VALUES (#{args}) \
ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
- updated = $4, ucid = $5, author = $6, length_seconds = $7", video_array)
+ updated = $4, ucid = $5, author = $6, length_seconds = $7, live_now = $8", video_array)
end
else
page = 1
@@ -157,7 +161,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
end
count = nodeset.size
- videos = videos.map { |video| ChannelVideo.new(video.id, video.title, video.published, Time.now, video.ucid, video.author, video.length_seconds) }
+ videos = videos.map { |video| ChannelVideo.new(video.id, video.title, video.published, Time.now, video.ucid, video.author, video.length_seconds, video.live_now) }
videos.each do |video|
ids << video.id
@@ -171,7 +175,7 @@ def fetch_channel(ucid, db, pull_all_videos = true, locale = nil)
args = arg_array(video_array)
db.exec("INSERT INTO channel_videos VALUES (#{args}) ON CONFLICT (id) DO UPDATE SET title = $2, \
- published = $3, updated = $4, ucid = $5, author = $6, length_seconds = $7", video_array)
+ published = $3, updated = $4, ucid = $5, author = $6, length_seconds = $7, live_now = $8", video_array)
end
end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 78dd1e5a..75f7417f 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -250,6 +250,36 @@ class Video
end
end
+ def allow_ratings
+ allow_ratings = player_response["videoDetails"].try &.["allowRatings"]?.try &.as_bool
+
+ if !allow_ratings
+ return true
+ end
+
+ return allow_ratings
+ end
+
+ def live_now
+ live_now = self.player_response["videoDetails"]?.try &.["isLive"]?.try &.as_bool
+
+ if !live_now
+ return false
+ end
+
+ return live_now
+ end
+
+ def is_listed
+ is_listed = player_response["videoDetails"].try &.["isCrawlable"]?.try &.as_bool
+
+ if !is_listed
+ return true
+ end
+
+ return is_listed
+ end
+
def keywords
keywords = self.player_response["videoDetails"]?.try &.["keywords"]?.try &.as_a
keywords ||= [] of String