Example of LUA port of an XML source



Heya,

I hope that I didn't miss important things, so here goes a port of the
bbcnews XML source available at:
https://gitorious.org/~jasuarez/grilo/jasuarez-grilo-plugins/blobs/media-factory/src/media/media-factory/sources/grl-bbc-news.xml

As requested in:
https://bugzilla.gnome.org/show_bug.cgi?id=656001

I think that we could do almost everything using a single "fetch"
function implemented by grilo, along with a few helpers for the JSON
parsing (which is really not a good match for the usual XML parsing),
and actually populating the results list.

For some of the sources, the skip/count stuff is clearly overkill
because of the limited amount of items to get added.

function browse(self):
	local bootstrap_url = "http://www.bbc.co.uk/moira/feeds/iphone/news/en-GB/v1";
	local phone_user_agent = "BBC News 1.7.1 (iPhone; iPhone OS 4.0.1; en_GB)"

	xml = grilo.fetch(bootstrap_url, user_agent=phone_user_agent)
	-- TODO: Need to have JSON parsing, pattern matching with XML is easier!
	for feed in xml:gmatch('<feed .-</feed>') do
		local feed_url = feed:gmatch('feed_url": (.-)"')
		local feed_data = grilo.fetch(feed_url)

		for item in feed_data:gmatch('<entry .-</entry>') do
			local item = {}

			item["title"] = item:gmatch('<title>(.-)</title>')
			item["type"], item["url"] = item:gmatch('="bbc(.-)://(.-)" ')

			-- TODO: Do the magic with the URL based on the config
			item.url = url_fixup(item.url, self.config.device, self.config.bandwidth)

			-- Add the item to the list
			-- TODO: Make it easier to skip things?
			if item.url then
				grilo.add(item)
			end
		end
	end

	grilo.add(None, finished=True)
end

Happy to hear feedback about this. Note that the code probably doesn't
work, as I'm never sure which function to use for the pattern
matchings :)

Cheers



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]