File: golem.lua

package info (click to toggle)
libquvi 0.2.0-1.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,284 kB
  • ctags: 491
  • sloc: sh: 11,898; ansic: 2,864; makefile: 202; perl: 187
file content (96 lines) | stat: -rw-r--r-- 2,526 bytes parent folder | download
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--[[
/* 
* Copyright (C) 2010 Toni Gundogdu.
*
* This file is part of quvi, see http://quvi.googlecode.com/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
]]--

-- If you make improvements to this script, drop a line. Thanks.
--   <http://quvi.googlecode.com/>

-- Returns script details.
function ident (page_url)
    
    -- This is what I return.
    local t = {}

    -- This is my domain.
    t.domain = "golem.de"

    -- This is my formats-string.
    t.formats = "default|best|ipod|high"

    -- This is my response to "Will you handle this URL?"
    -- Note that page_url may be nil.
    t.will_handle = (page_url ~= nil and page_url:find(t.domain) ~= nil)

    -- Here are my details.
    return t

end

-- Fetches video page and parses the video URL.
function parse (video)

    -- This is my "host ID".
    video.host_id = "golem"

    -- Fetch video page.
    local page = quvi.fetch(video.page_url)

    -- This is my video ID.
    local _,_,s = page:find('"id", "(.-)"')
    video.id    = s or error ("no match: video id")

    -- Fetch config.

    local config_url =
        string.format("http://video.golem.de/xml/%s", video.id)

    local config = quvi.fetch(config_url, "config")

    -- This is my video title.
    local _,_,s = config:find("<title>(.-)</")
    video.title = s or error ("no match: video title")

    -- This is my video URL.
    video_url =
        string.format("http://video.golem.de/download/%s", video.id)

    -- Choose correct format.
    format = "medium" -- This is the default.

    if (video.requested_format == "best") then
        format = "high"
    else
        for _,v in pairs({"ipod","high"}) do
            if (v == video.requested_format) then
                format = v
                break
            end
        end
    end

    -- Append format string.
    video.url = {video_url .. "?q=" .. format}

    -- Return the updated video properties.
    return video

end