summaryrefslogtreecommitdiff
path: root/.local/share/libquvi-scripts/media/flashxtv.lua
blob: f7668945d22ceb0e5698614641ecd32b6d12fb5b (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
-- libquvi-scripts

local Flashx = {}

-- Identify the script.
function ident(qargs)
  return {
    domains = table.concat({'flashx.tv'}, ','),
    can_parse_url = Flashx.can_parse_url(qargs)
  }
end

-- Parse media URL.
function parse(qargs)
  local c = quvi.http.fetch(qargs.input_url).data
  qargs.title = c:match('<div class="video_title">(.-)</div>')
  local iframe_url = c:match('<iframe[^>]+src="(http://play.flashx.tv/.-)"')

  c = quvi.http.fetch(iframe_url).data
  local p = { yes = c:match('name="yes"[^>]+value="(.-)"'),
              sec = c:match('name="sec"[^>]+value="(.-)"') }
  local R = require 'soup_request'
  c = R.request("http://play.flashx.tv/player/player.php", "POST", p)
  local data_url = c:match('data="[^"]+config=(.-)"')
  c = quvi.http.fetch(data_url).data

  qargs.id = qargs.input_url:match('video/([A-Z0-9]+)')
  qargs.thumb_url = c:match('<image>(.-)</image>')
  qargs.streams = Flashx.iter_streams(c, qargs)

  return qargs
end

function Flashx.iter_streams(c, qargs)
  local S = require 'quvi/stream'

  url = c:match('<file>(.-)</file>')
  local s = S.stream_new(url)
  s.container = "flv"
  return { s }
end

function Flashx.can_parse_url(qargs)
  local U = require 'socket.url'
  local t = U.parse(qargs.input_url)

  return t and t.scheme and t.scheme:lower():match('^http$')
           and t.host and t.host:lower():match('flashx%.tv$')
           and t.path and t.path:match("^/video/[A-Z0-9]+")
           and true or false
end

-- vim: set ts=2 sw=2 tw=72 expandtab: