summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-05-07 20:38:13 -0500
committerOmar Roth <omarroth@hotmail.com>2018-05-07 20:38:13 -0500
commit75f8fcd40b2a3bd8209e0aa44e82ff6fe431ec5c (patch)
treea56646c63a46bc8c35ab279a5207603db36bede1
parentfef2cbc0b22c1a5ef4c0563fbbf57b31bcf5e313 (diff)
downloadinvidious-75f8fcd40b2a3bd8209e0aa44e82ff6fe431ec5c.tar.gz
invidious-75f8fcd40b2a3bd8209e0aa44e82ff6fe431ec5c.tar.bz2
invidious-75f8fcd40b2a3bd8209e0aa44e82ff6fe431ec5c.zip
Add support for AAhBBmCCsDDms in video start and end params
-rw-r--r--src/helpers.cr22
-rw-r--r--src/invidious.cr16
-rw-r--r--src/views/watch.ecr4
3 files changed, 35 insertions, 7 deletions
diff --git a/src/helpers.cr b/src/helpers.cr
index 2a962724..4c9a0ece 100644
--- a/src/helpers.cr
+++ b/src/helpers.cr
@@ -643,3 +643,25 @@ def fetch_user(sid, client, headers)
user = User.new(sid, Time.now, [] of String, channels, email)
return user
end
+
+def decode_time(string)
+ time = string.try &.to_f?
+
+ if !time
+ hours = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i
+ hours ||= 0
+
+ minutes = /(?<minutes>\d+)m/.match(string).try &.["minutes"].try &.to_i
+ minutes ||= 0
+
+ seconds = /(?<seconds>\d+)s/.match(string).try &.["seconds"].try &.to_i
+ seconds ||= 0
+
+ millis = /(?<millis>\d+)ms/.match(string).try &.["millis"].try &.to_i
+ millis ||= 0
+
+ time = hours * 3600 + minutes * 60 + seconds + millis / 1000
+ end
+
+ return time
+end
diff --git a/src/invidious.cr b/src/invidious.cr
index 02eaec6b..7af339ed 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -242,17 +242,23 @@ get "/watch" do |env|
next env.redirect "/"
end
- video_start = env.params.query["start"]?.try &.to_i
- video_start ||= 0
+ if env.params.query["start"]?
+ video_start = decode_time(env.params.query["start"])
+ else
+ video_start = 0
+ end
- video_end = env.params.query["end"]?.try &.to_i
- video_end ||= -1
+ if env.params.query["end"]?
+ video_end = decode_time(env.params.query["end"])
+ else
+ video_end = -1
+ end
- listen = false
if env.params.query["listen"]? && env.params.query["listen"] == "true"
listen = true
env.params.query.delete_all("listen")
end
+ listen ||= false
authorized = env.get? "authorized"
if authorized
diff --git a/src/views/watch.ecr b/src/views/watch.ecr
index 5e9196dd..082acdf6 100644
--- a/src/views/watch.ecr
+++ b/src/views/watch.ecr
@@ -74,10 +74,10 @@ var player = videojs('player', options, function() {
}
});
});
+
player.offset({
start: <%= video_start %>,
- end: <%= video_end %>,
- restart_beginning: true
+ end: <%= video_end %>
});
function toggle(target) {