m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/lib/recording.rb
blob: f2ee25119e2a151d259141f429bf11a9c895b249 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class NotImplemented < Exception
end

class Recording
  def render
    raise NotImplemented
  end
end

class YouTubeRecording
  attr_accessor :vid
  def initialize link
    @vid = parse_vid link
  end

  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
  end
end

class BandcampRecording
  attr_accessor :embed
  def initialize _embed
    @embed = _embed
  end

  def render
    @embed
  end
end

class SoundCloudRecording
  attr_accessor :embed
  def initialize _embed
    @embed = _embed
  end

  def render
    @embed
  end
end