m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/recording.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/recording.rb b/lib/recording.rb
index 68b0428..f2ee251 100644
--- a/lib/recording.rb
+++ b/lib/recording.rb
@@ -13,10 +13,24 @@ class YouTubeRecording
@vid = parse_vid link
end
- def parse_vid link
+ def parse_id link
/\?v=(.{11})/.match(link)[1]
end
+ # Timecodes in links have to be specified in seconds (the "start" query for
+ # embeds doesn't understand "XmYs" like "t" on regular links).
+ def parse_timequery link
+ match = /&t=([0-9]+)/.match(link)
+
+ match ? "?start=#{match[1]}" : ""
+ end
+
+ def parse_vid link
+ id = parse_id link
+ timequery = parse_timequery link
+ "#{id}#{timequery}"
+ end
+
def render
template = ERB.new(File.read('templates/youtube.html.erb'), trim_mode: '-')
template.result binding