lua-users home
lua-l archive

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


Hello all,
Cultura FM radio has some interesting audios about classical music.
I'd like to download it automatically.
The steps are:
1. To get the page with http.request;
2. To match urls started with 'http://' and ended with '.mp3';
3. To record the urls in a file.
My problem is the step 2. I could not find a pattern to match urls like:
http://midia.cmais.com.br/assets/audio/default/CENA_00087___P___24_12_10_1293450448.mp3

Let me show to you my attempt:

local http = require('socket.http')

local target = 'http://culturafm.cmais.com.br/cena-brasileira/cena-brasileira'

local content, status = http.request(target)

if status == 200 then
	local file = io.open('url.txt', 'w')
	local pattern = '(http://[a-zA-Z0-9_/]-%.mp3)'
	for url in content:gmatch(pattern) do
		file:write(url)
	end
	file:close()
end

Would someone know a lua pattern to match urls started with "http://";
and ended with '.mp3'?
Best regards,

-- 
Luciano de Souza