Class: TrueURL::Strategy::DailyMotion

Inherits:
Object
  • Object
show all
Defined in:
lib/true_url/strategy/dailymotion.rb

Instance Method Summary collapse

Instance Method Details

#clean_playlist_id(path) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/true_url/strategy/dailymotion.rb', line 43

def clean_playlist_id(path)
  cpath = path[10..-1]

  if cpath.index('_')
    cpath[0..cpath.index('_') - 1]
  elsif cpath.index('/')
    cpath[0..cpath.index('/') - 1]
  else
    cpath[0..-1]
  end
end

#clean_video_id(path) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/true_url/strategy/dailymotion.rb', line 35

def clean_video_id(path)
  if path.index('_')
    path[7..path.index('_') - 1]
  else
    path[7..-1]
  end
end

#execute(context) ⇒ Object



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
# File 'lib/true_url/strategy/dailymotion.rb', line 4

def execute(context)
  path = context.working_url.path

  if context.working_url.host == 'dai.ly'
    video_id = path[1..-1]

  elsif path[0..6] == '/video/'
    video_id = clean_video_id(path)

  elsif path[0..6] == '/embed/'
    video_id = path[13..-1]

  elsif path[0..9] == '/playlist/'
    playlist_id = clean_playlist_id(path)
  end

  unless video_id.nil?
    context.set_working_url("https://www.dailymotion.com/video/#{video_id}")
    context.finalize
    context.attributes[:embed_url] = "https://www.dailymotion.com/embed/video/#{video_id}"
  end

  unless playlist_id.nil?
    context.set_working_url("https://www.dailymotion.com/playlist/#{playlist_id}")
    context.finalize
  end

  # DailyMotion supports both HTTP and HTTPS and doesn't redirect between them, so we prefer HTTPS
  context.working_url.scheme = 'https'
end