3 -- Copyright (C) 2011 quvi project
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
12 -- This library 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 GNU
15 -- Lesser General Public License for more details.
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 -- NOTE: Media General is a company that owns many local news stations
25 -- and newspapers in the southeast US. They all use the same system for
27 -- <http://sourceforge.net/apps/trac/quvi/ticket/78>
30 local MGNetwork
= {} -- Utility functions unique to this script
32 -- Identify the script.
34 package
.path
= self
.script_dir
.. '/?.lua'
35 local C
= require
'quvi/const'
37 local domains
= {'alabamas13%.com', 'counton2%.com',
38 'dailyprogress%.com', 'dothaneagle%.com', 'eprisenow%.com',
39 'eufaulatribune%.com', 'godanriver%.com', 'hickoryrecord%.com',
40 'independenttribune%.com', 'insidenova%.com', 'jcfloridan%.com',
41 'journalnow%.com', 'oanow%.com', 'morganton%.com',
42 'nbc4i%.com', 'nbc17%.com', 'newsadvance%.com',
43 'newsvirginian%.com', 'richmond%.com', 'sceneon7%.com',
44 'scnow%.com', 'starexponent%.com', 'statesville%.com',
45 'tbo%.com', 'timesdispatch%.com', 'tricities%.com',
46 'turnto10%.com', 'wnct%.com', 'whlt%.com', 'wjbf%.com',
47 'wjtv%.com', 'wkrg%.com', 'wrbl%.com', 'wsav%.com', 'wsls%.com',
48 'wspa%.com', 'vteffect%.com'}
49 r
.domain
= 'mgnetwork%.com'
50 r
.formats
= 'default|best'
51 r
.categories
= C
.proto_http
52 local U
= require
'quvi/util'
53 r
.handles
= U
.handles(self
.page_url
,
59 -- Query available formats.
60 function query_formats(self
)
61 local config
= MGNetwork
.get_config(self
)
62 local formats
= MGNetwork
.iter_formats(config
)
65 for _
,v
in pairs(formats
) do
66 table.insert(t
, MGNetwork
.to_s(v
))
70 self
.formats
= table.concat(t
, "|")
77 self
.host_id
= 'mgnetwork'
79 local xml
= MGNetwork
.get_config(self
)
81 self
.title
= xml
:match('<item>.-<title>(.-)</title>')
82 or error("no match: media title")
84 local formats
= MGNetwork
.iter_formats(xml
)
85 local U
= require
'quvi/util'
86 local format = U
.choose_format(self
, formats
,
87 MGNetwork
.choose_best
,
88 MGNetwork
.choose_default
,
90 or error("unable to choose format")
91 self
.url
= {format.url
or error("no match: media url")}
93 -- Optional: we can live without these
95 self
.thumbnail_url
= xml
:match('<media:thumbnail url="(.-)"') or ''
97 local d
= xml
:match('duration="(.-)"') or 0
98 self
.duration
= math
.ceil(d
) * 1000 -- to msec
107 function MGNetwork
.get_config(self
)
108 -- local config_url = string.format(
109 -- 'http://%s/video/get/media_response_related_' ..
110 -- 'for_content/%s/%d/', d, v, self.id)
111 local d
,v
,s
= self
.page_url
:match("http://([%w%.]+)/.+%-(%w+)%-(%d+)/")
112 self
.id
= s
or error("no match: media id")
114 -- Ideally, we'd skip this step and just get the config.
115 -- Do this so that we can check whether the video exists.
116 local d
= quvi
.fetch(self
.page_url
)
117 local p
= "if %(!mrss_link%){ mrss_link = '(.-)'; }"
118 local s
= d
:match(p
) or error('no match: no video found on page')
120 return quvi
.fetch(s
, {fetch_type
= 'config'})
123 function MGNetwork
.iter_formats(config
)
124 local p
= 'content url="(.-)" type="%w+/(.-)"'
126 for u
,c
in config
:gmatch(p
) do
127 table.insert(t
, {url
=u
, container
=c
})
133 function MGNetwork
.choose_best(t
) -- Expect the first to be the 'best'
137 function MGNetwork
.choose_default(t
) -- Expect the last to be the 'default'
141 function MGNetwork
.to_s(t
)
145 -- vim: set ts=4 sw=4 tw=72 expandtab: