This file is indexed.

/usr/share/libquvi-scripts/lua/website/foxnews.lua is in libquvi-scripts 0.4.21-1~deb7u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
-- libquvi-scripts v0.4.21
-- Copyright (C) 2011  Lionel Elie Mamane <lionel@mamane.lu>
--
-- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library 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
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-- 02110-1301  USA
--

local Foxnews = {} -- Utility functions unique to this script.

-- Identify the script.
function ident(self)
    package.path = self.script_dir .. '/?.lua'
    local C      = require 'quvi/const'
    local r      = {}
    r.domain     = "video%.foxnews%.com"
    r.formats    = "default|best"
    r.categories = C.proto_http
    local U      = require 'quvi/util'
    r.handles    = U.handles(self.page_url, {r.domain}, {"/v/%d+"})
                    or U.handles(self.page_url, {r.domain}, {"/v/embed%.js"},
                        {"id%=%d+"})
                    or U.handles(self.page_url, {r.domain},
                        {"/v/video%-embed%.html"}, {"video_id=%d+"})
    return r
end

-- Query available formats.
function query_formats(self)
    local U       = require 'quvi/util'
    local js      = Foxnews.fetch_feed_js(self, U)
    local formats = Foxnews.iter_formats_js(js, U)

    local t = {}
    for _,v in pairs(formats) do
        table.insert(t, Foxnews.to_s(v))
    end

    table.sort(t)
    self.formats = table.concat(t, "|")

    return self
end

-- Parse media URL.
function parse(self)
    self.host_id = "foxnews"

    local U  = require 'quvi/util'
    local js = Foxnews.fetch_feed_js(self, U)

    local item = js:match('"item":(%b{})')
                  or error("no match: item")

    self.title = js:match('"title":"(.-)"')
                  or error("no match: media title")

    do
        local thumbs = Foxnews.iter_thumbnails_js(item)
        local best_thumb_res = -1
        local best_thumb_url = ''
        for _,thumb in pairs(thumbs) do
            local res = thumb.height*thumb.width
            if res > best_thumb_res then
                best_thumb_url = thumb.url
                best_thumb_res = res
            end
        end
        self.thumbnail_url = best_thumb_url
    end

    local formats = Foxnews.iter_formats_js(item, U)
    local format  = U.choose_format(self, formats,
                                     Foxnews.choose_best,
                                     Foxnews.choose_default,
                                     Foxnews.to_s)
                        or error("unable to choose format")
    self.url      = {format.url or error("no match: media url")}
    return self
end

--
-- Utility functions
--

function Foxnews.fetch_feed_js(self, U)
    self.page_url = Foxnews.normalize(self)

    return quvi.fetch('http://video.foxnews.com/v/feed/video/'
            .. self.id .. '.js?template=grab')
end

function Foxnews.normalize(self) -- "Normalize" embedded URLs
    if self.page_url:match("/v/embed.js?id=",1,true) then
        self.page_url = self.page_url:gsub("/v/embed%.js%?id=(%d+)", "/v/%1/")
    elseif self.page_url:match("/v/video-embed.html?video_id=",1,true) then
        self.page_url =
            self.page_url:gsub("/v/video%-embed%.html%?video_id=(%d+)",
                               "/v/%1/")
    end
    local _, ie, s = self.page_url:find("/v/(%d+)")
    self.id = s or error("no match: media id")
    self.page_url = self.page_url:sub(1, ie)
end

function Foxnews.iter_formats_js(page, U)
    local formats = Foxnews.find_set(page, '"media%-content"')
    if not formats then
        error("no match: media-content")
    end

    local t = {}
    for attrs in formats:gmatch('"@attributes":(%b{})') do
        local format = {}
        for key,value in attrs:gmatch('"(.-)":"(.-)"') do
            format[key]=value
	    end
        if format.rel == "stream" then
            local a = {"framerate","bitrate","height","duration","width"}
            for _, key in pairs(a) do
                if format[key] then
                    format[key]=tonumber(format[key])
                end
            end
            local s = format.url:match('FNC_([%w%p]-)%.')
            if s then
                format.description=string.lower(s)
            end
            table.insert(t, format)
        end
    end

    return t
end

function Foxnews.iter_thumbnails_js(page, U)
    local thumbs = Foxnews.find_set(page, '"media%-thumbnail"')
    if not thumbs then
        return {}
    end

    local t = {}
    for attrs in thumbs:gmatch('"@attributes":(%b{})') do
        local thumb = {}
        for key,value in attrs:gmatch('"(.-)":"(.-)"') do
            thumb[key]=value
	    end
        table.insert(t, thumb)
    end

    return t
end

function Foxnews.choose_default(formats) -- Lowest quality available
    local r = {width=0xffff, height=0xffff, url=nil, bitrate=0xfffffffffff}
    local U = require 'quvi/util'
    for _,v in pairs(formats) do
        if U.is_lower_quality(v,r) then
            r = v
        end
    end
--    for k,v in pairs(r) do print(k,v) end
    return r
end

function Foxnews.choose_best(formats) -- Highest quality available
    local r = {width=0, height=0, url=nil, bitrate=-1}
    local U = require 'quvi/util'
    for _,v in pairs(formats) do
        if U.is_higher_quality(v,r) then
            r = v
        end
    end
--    for k,v in pairs(r) do print(k,v) end
    return r
end

function Foxnews.to_s(t)
    if t.description then
        return t.description
    else
        return string.format("%s_%sp", t.width, t.height)
    end
end

function Foxnews.find_set(str, label)
    local _, _, r = str:find(label .. ':(%b[])')
    if not r then
        _, _, r = str:find(label .. ':(%b{})')
    end
    return r
end

-- Local Variables: **
-- indent-tabs-mode: () **
-- lua-indent-level: 4 **
-- End: **
-- vim: set ts=4 sw=4 tw=72 expandtab: