summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorveer <bveer428@gmail.com>2018-06-06 00:10:49 +0530
committerVictor Toso <me@victortoso.com>2018-07-17 12:27:40 +0200
commit13157fde3f274609f48d9e7dc590023d318dc7ee (patch)
treedad8966d7233fa5029e0eddbf617146021c4b25b
parentd9df3871d45a23b87dfe39ecc1c03661f0115f41 (diff)
downloadgrilo-plugins-13157fde3f274609f48d9e7dc590023d318dc7ee.tar.gz
euronews: Fix parsing of metadata
The base url of euronews source might depend on the language now. The url previously pointed to flash stream as now it points to a m3u8 playlist, like: | #EXTM3U | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2000000,RESOLUTION=1280x720 | ewnsabrdepri_ger_720p.m3u8 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1200000,RESOLUTION=960x540 | ewnsabrdepri_ger_540p.m3u8 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=750000,RESOLUTION=640x360 | ewnsabrdepri_ger_360p.m3u8 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=512000,RESOLUTION=400x224 | ewnsabrdepri_ger_224p.m3u8 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=350000,RESOLUTION=320x180 | ewnsabrdepri_ger_180p.m3u8 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=200000,RESOLUTION=160x90 | ewnsabrdepri_ger_90p.m3u8 Closes #3 Signed-off-by: Victor Toso <victortoso@redhat.com>
-rw-r--r--src/lua-factory/sources/grl-euronews.lua119
1 files changed, 80 insertions, 39 deletions
diff --git a/src/lua-factory/sources/grl-euronews.lua b/src/lua-factory/sources/grl-euronews.lua
index 643b702..a904186 100644
--- a/src/lua-factory/sources/grl-euronews.lua
+++ b/src/lua-factory/sources/grl-euronews.lua
@@ -20,7 +20,25 @@
*
--]]
-EURONEWS_URL = 'http://euronews.hexaglobe.com/json/'
+LANG_EN = "en"
+EURONEWS_URL = 'http://%s.euronews.com/api/watchlive.json'
+
+local langs = {
+ arabic = "Arabic",
+ de = "German",
+ en = "English",
+ es = "Spanish; Castilian",
+ fa = "Persian",
+ fr = "French",
+ gr = "Greek, Modern (1453-)",
+ hu = "Hungarian",
+ it = "Italian",
+ pt = "Portuguese",
+ ru = "Russian",
+ tr = "Turkish",
+}
+
+local num_callbacks = 0
---------------------------
-- Source initialization --
@@ -43,8 +61,16 @@ source = {
function grl_source_browse(media_id)
if grl.get_options("skip") > 0 then
grl.callback()
- else
- grl.fetch(EURONEWS_URL, euronews_fetch_cb)
+ return
+ end
+
+ for lang in pairs(langs) do
+ num_callbacks = num_callbacks + 1
+ end
+
+ for lang in pairs(langs) do
+ local api_url = get_api_url(lang)
+ grl.fetch(api_url, euronews_initial_fetch_cb, lang)
end
end
@@ -52,47 +78,71 @@ end
-- Callback functions --
------------------------
--- return all the media found
-function euronews_fetch_cb(results)
+function euronews_initial_fetch_cb(results, lang)
local json = {}
+ json = grl.lua.json.string_to_table(results)
+ if not json or not json.url then
+ local api_url = get_api_url(lang)
+ grl.warning ("Initial fetch failed for: " .. api_url)
+ callback_done()
+ return
+ end
+
+ local streaming_lang = json.url:match("://euronews%-(..)%-p%-api")
+ if lang ~= LANG_EN and streaming_lang == LANG_EN then
+ grl.debug("Skipping " .. langs[lang] .. " as it redirects to " .. langs[LANG_EN] .. " stream.")
+ callback_done()
+ return
+ end
+
+ grl.fetch(json.url, euronews_fetch_cb, lang)
+end
+
+
+-- return all the media found
+function euronews_fetch_cb(results, lang)
+ local json = {}
json = grl.lua.json.string_to_table(results)
- if not json or json.stat == "fail" or not json.primary then
- grl.callback()
+
+ if not json or json.status ~= "ok" or not json.primary then
+ local api_url = get_api_url(lang)
+ grl.warning("Fetch failed for: " .. api_url)
+ callback_done()
return
end
- for index, item in pairs(json.primary) do
- local media = create_media(index, item)
- if media ~= nil then
- grl.callback(media, -1)
- end
+ local media = create_media(lang, json)
+ if media ~= nil then
+ grl.callback(media, -1)
end
- grl.callback()
+ callback_done()
end
-------------
-- Helpers --
-------------
-function get_lang(id)
- local langs = {}
- langs.ru = "Russian"
- langs.hu = "Hungarian"
- langs.de = "German"
- langs.fa = "Persian"
- langs.ua = "Ukrainian"
- langs.ar = "Arabic"
- langs.es = "Spanish; Castilian"
- langs.gr = "Greek, Modern (1453-)"
- langs.tr = "Turkish"
- langs.pe = "Persian" -- Duplicate?
- langs.en = "English"
- langs.it = "Italian"
- langs.fr = "French"
- langs.pt = "Portuguese"
+function callback_done()
+ num_callbacks = num_callbacks - 1
+
+ -- finalize operation
+ if num_callbacks == 0 then
+ grl.callback()
+ end
+end
+
+function get_api_url(id)
+ if not langs[id] then
+ grl.warning('Could not find language ' .. id)
+ return id
+ end
+ return string.format(EURONEWS_URL, id == LANG_EN and "www" or id)
+end
+
+function get_lang(id)
if not langs[id] then
grl.warning('Could not find language ' .. id)
return id
@@ -104,19 +154,10 @@ end
function create_media(lang, item)
local media = {}
- if item.rtmp_flash["750"].name == 'UNAVAILABLE' then
- return nil
- end
-
media.type = "video"
media.id = lang
media.title = "Euronews " .. get_lang(lang)
- media.url = item.rtmp_flash["750"].server ..
- item.rtmp_flash["750"].name ..
- " playpath=" .. item.rtmp_flash["750"].name ..
- " swfVfy=1 " ..
- "swfUrl=http://euronews.com/media/player_live_1_14.swf "..
- "live=1"
+ media.url = item.primary
return media
end