try formatting itunes feed
This commit is contained in:
parent
49cc36ef31
commit
ea3ff90349
@ -7,12 +7,14 @@ local hotmixes = autoload("hotmixes")
|
|||||||
local function RSShandler(self)
|
local function RSShandler(self)
|
||||||
|
|
||||||
local path = config.get().mount .. self.titles.url
|
local path = config.get().mount .. self.titles.url
|
||||||
local latest_path, latest_name = hotmixes.utils.these_latest( path )
|
local latest_path, latest_name, latest_size, latest_date = hotmixes.utils.rss_latest( path )
|
||||||
|
|
||||||
local host = self.req.parsed_url.scheme .. '://' .. self.req.parsed_url.host
|
local host = self.req.parsed_url.scheme .. '://' .. self.req.parsed_url.host
|
||||||
self.datapath = host .. '/data/' .. self.titles.url .. '/'
|
self.datapath = host .. '/data/' .. self.titles.url .. '/'
|
||||||
self.latestpath = latest_path
|
self.latestpath = latest_path
|
||||||
self.latestname = latest_name
|
self.latestname = latest_name
|
||||||
|
self.latestsize = latest_size
|
||||||
|
self.latestdate = latest_date
|
||||||
|
|
||||||
return { content_type = "application/rss+xml", layout = require "views.rss" }
|
return { content_type = "application/rss+xml", layout = require "views.rss" }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,6 +26,7 @@ local data_path = data_dir .. request_path
|
|||||||
|
|
||||||
local type_image = { jpg=true, jpeg=true, png=true, gif=true }
|
local type_image = { jpg=true, jpeg=true, png=true, gif=true }
|
||||||
local type_media = { mp3=true, flac=true, wav=true, mp4=true }
|
local type_media = { mp3=true, flac=true, wav=true, mp4=true }
|
||||||
|
local type_audio = { mp3=true, flac=true, wav=true }
|
||||||
local type_allowed = { jpg=true, jpeg=true, png=true, gif=true, mp3=true, flac=true, wav=true, mp4=true }
|
local type_allowed = { jpg=true, jpeg=true, png=true, gif=true, mp3=true, flac=true, wav=true, mp4=true }
|
||||||
|
|
||||||
local utils = {}
|
local utils = {}
|
||||||
@ -60,6 +61,19 @@ utils['latest_files'] = function( directory )
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
utils['latest_audio'] = function( directory )
|
||||||
|
local i, t, popen = 0, {}, io.popen
|
||||||
|
local pfile = popen('find -L "'..directory..'" -type f ! -name \'*.filepart\' ! -name \'*.mp4\' ! -name \'*.png\' ! -name \'*.jpg\' ! -name \'*.jpeg\' ! -name \'*.gif\' -printf \'%C@ %p\n\'| sort -nr | head -7 | cut -f2- -d" "| sed s:"'..directory..'/"::')
|
||||||
|
for filename in pfile:lines() do
|
||||||
|
if utils.match_ext ( filename, type_audio ) then
|
||||||
|
i = i + 1
|
||||||
|
t[i] = filename
|
||||||
|
end
|
||||||
|
end
|
||||||
|
pfile:close()
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
utils['these_files'] = function( path )
|
utils['these_files'] = function( path )
|
||||||
local files, dirs, images = {}, {}, {}
|
local files, dirs, images = {}, {}, {}
|
||||||
for file in lfs.dir( path ) do
|
for file in lfs.dir( path ) do
|
||||||
@ -120,6 +134,51 @@ utils['these_latest'] = function( path )
|
|||||||
return latest_path, latest_name
|
return latest_path, latest_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
utils['rss_latest'] = function( path )
|
||||||
|
local latest_path, latest_name, latest_size, latest_date = {}, {}, {}, {}
|
||||||
|
|
||||||
|
for i, file_path in ipairs( utils.latest_files( path ) ) do
|
||||||
|
local popen = io.popen
|
||||||
|
|
||||||
|
-- get the size of the file
|
||||||
|
local psize = popen('wc -c <'..path..'/'..file_path)
|
||||||
|
for size in psize:lines() do
|
||||||
|
ngx.log(ngx.INFO, size)
|
||||||
|
table.insert( latest_size, size)
|
||||||
|
end
|
||||||
|
psize:close()
|
||||||
|
|
||||||
|
-- get the date of the file
|
||||||
|
local pdate = popen('date -d @$(stat -c "%Y" '..path..'/'..file_path..') "+%a, %-d %b %Y %H:%M:%S %Z"')
|
||||||
|
for date in pdate:lines() do
|
||||||
|
table.insert( latest_date, date )
|
||||||
|
end
|
||||||
|
pdate:close()
|
||||||
|
|
||||||
|
local escpath = hotesc(file_path)
|
||||||
|
table.insert( latest_path, escpath )
|
||||||
|
|
||||||
|
local temp = ""
|
||||||
|
local result = ""
|
||||||
|
for i = file_path:len(), 1, -1 do
|
||||||
|
if file_path:sub(i,i) ~= "/" then
|
||||||
|
temp = temp..file_path:sub(i,i)
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for j = temp:len(), 1, -1 do
|
||||||
|
result = result..temp:sub(j,j)
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert( latest_name, result )
|
||||||
|
end
|
||||||
|
|
||||||
|
return latest_path, latest_name, latest_size, latest_date
|
||||||
|
end
|
||||||
|
|
||||||
utils['total_files_dir'] = function( path )
|
utils['total_files_dir'] = function( path )
|
||||||
local i, t, popen = 0, {}, io.popen
|
local i, t, popen = 0, {}, io.popen
|
||||||
local pfile = popen('find "'..path..'" -type f | wc -l')
|
local pfile = popen('find "'..path..'" -type f | wc -l')
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
<rss version="2.0"
|
||||||
|
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
|
||||||
|
xmlns:content="http://purl.org/rss/1.0/modules/content/">
|
||||||
|
|
||||||
<channel>
|
<channel>
|
||||||
<atom:link href="https://<%= titles['url'] %>/latest.xml" rel="self" type="application/rss+xml" />
|
|
||||||
<title><%= titles['name'] %></title>
|
<title><%= titles['name'] %></title>
|
||||||
<link>https://<%= titles['url'] %></link>
|
<link>https://<%= titles['url'] %></link>
|
||||||
|
<language>en-us</language>
|
||||||
|
<itunes:author>Intergalactic FM</itunes:author>
|
||||||
<description>Latest uploads</description>
|
<description>Latest uploads</description>
|
||||||
|
<itunes:explicit>no</itunes:explicit>
|
||||||
|
|
||||||
<% for i, file in ipairs(latestpath) do %>
|
<% for i, file in ipairs(latestpath) do %>
|
||||||
<item>
|
<item>
|
||||||
<title><%= latestname[i] %></title>
|
<title><%= latestname[i] %></title>
|
||||||
<link><%= datapath .. file:gsub("#", "%%23") %></link>
|
<enclosure url="<%= datapath .. file %>" length="<%= latestsize[i] %>" type="audio/mpeg"/>
|
||||||
|
<guid><%= datapath .. file %></guid>
|
||||||
|
<pubDate><%= latestdate[i] %></pubDate>
|
||||||
<description><![CDATA[<%= latestname[i] %>]]></description>
|
<description><![CDATA[<%= latestname[i] %>]]></description>
|
||||||
<guid><%= datapath .. file:gsub("#", "%%23") %></guid>
|
|
||||||
</item>
|
</item>
|
||||||
<% end %>
|
<% end %>
|
||||||
</channel>
|
</channel>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user