~ubuntu-branches/ubuntu/trusty/libquvi/trusty-proposed

« back to all changes in this revision

Viewing changes to share/lua/website/cctv.lua

  • Committer: Bazaar Package Importer
  • Author(s): Alejandro Garrido Mota
  • Date: 2010-05-16 12:12:51 UTC
  • Revision ID: james.westby@ubuntu.com-20100516121251-oku70h33ycn8m6xe
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--[[
 
2
/* 
 
3
* Copyright (C) 2010 Toni Gundogdu.
 
4
*
 
5
* This file is part of quvi, see http://quvi.googlecode.com/
 
6
*
 
7
* This program is free software: you can redistribute it and/or modify
 
8
* it under the terms of the GNU General Public License as published by
 
9
* the Free Software Foundation, either version 3 of the License, or
 
10
* (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
*
 
17
* You should have received a copy of the GNU General Public License
 
18
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
]]--
 
21
 
 
22
-- If you make improvements to this script, drop a line. Thanks.
 
23
--   <http://quvi.googlecode.com/>
 
24
 
 
25
-- Returns script details.
 
26
function ident (page_url)
 
27
    
 
28
    -- This is what I return.
 
29
    local t = {}
 
30
 
 
31
    -- This is my domain.
 
32
    t.domain = "cctv.com"
 
33
 
 
34
    -- This is my formats-string.
 
35
    t.formats = "default"
 
36
 
 
37
    -- This is my response to "Will you handle this URL?"
 
38
    -- Note that page_url may be nil.
 
39
    t.will_handle = (page_url ~= nil and page_url:find(t.domain) ~= nil)
 
40
 
 
41
    -- Here are my details.
 
42
    return t
 
43
 
 
44
end
 
45
 
 
46
-- Fetches video page and parses the video URL.
 
47
function parse (video)
 
48
 
 
49
    -- This is my "host ID".
 
50
    video.host_id = "cctv"
 
51
 
 
52
    -- Fetch video page.
 
53
    local page = quvi.fetch(video.page_url)
 
54
 
 
55
    -- This is my video title.
 
56
    local _,_,s = page:find('<meta name="description"%s+content="(.-)"')
 
57
    video.title = s or error ("no match: video title")
 
58
 
 
59
    -- This is my video ID.
 
60
    local _,_,s = page:find("videoId=(.-)&")
 
61
    video.id    = s or error ("no match: video id")
 
62
 
 
63
    -- This is the domain string used to fetch the config.
 
64
    local _,_,s = video.page_url:find("http://(.-)/")
 
65
    local domain = s or error ("no match: domain")
 
66
 
 
67
    -- This is the config URL.
 
68
    local config_url =
 
69
        string.format("http://%s/playcfg/flv_info_new.jsp?videoId=%s",
 
70
            domain, video.id)
 
71
 
 
72
    -- Fetch the config.
 
73
    local config = quvi.fetch(config_url, "config")
 
74
 
 
75
    -- These are my other details used to construct the video URL.
 
76
    local _,_,s    = config:find('"chapters":%[(.-)%]')
 
77
    local chapters = s or error ("no match: chapters")
 
78
    video.url      = {} -- Array. Make a mental note of this.
 
79
 
 
80
    -- Some of the cctv videos have "segments", include all of them.
 
81
    for path in chapters:gfind('{"url":"(.-)",') do
 
82
        table.insert(video.url,
 
83
            string.format("http://v.cctv.com/flash/%s", path))
 
84
    end
 
85
 
 
86
    -- We should have at least one in the array.
 
87
    if (table.getn(video.url) == 0) then
 
88
        error ("no match: chapter url path")
 
89
    end
 
90
 
 
91
    -- Return the updated video properties.
 
92
    return video
 
93
 
 
94
end
 
95
 
 
96