|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://angg.twu.net/LUA/youtube-tags.lua
-- http://angg.twu.net/LUA/youtube-tags.lua.html
-- (find-angg "LUA/youtube-tags.lua")
--
-- (find-lua51manualw3m "")
-- (find-books "__comp/__comp.el" "ierusalimschy")
-- (find-pil2page 8 "Contents")
-- (find-pil2text 8 "Contents")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
fname = "~/varda/TODO"
dofile "youtube-tags.lua"
demo1(ee_readfile "~/varda/TODO")
-- print(allcmds())
c = '(find-fline "'..fname..'")\n'
-- writefile("/tmp/o.el", c..allcmds())
* (load "/tmp/o.el")
--]]
-- (find-blogme3file "youtube.lua" "youtube_split_url0 =")
youtube_make_url = function (hash, time)
return "http://www.youtube.com/watch?v=" .. hash
end
youtube_split_url0 = function (li)
local a, url, b, title, c = li:match "^(.-)(https?://%S*)(%s*)(.-)(%s*)$"
if not url then return end
local hash, time
for key,value in url:gmatch "[?&](%w*)=([^?&]*)" do
if key == "v" then hash = value end
if key == "t" then time = value end -- not being used now
end
if not hash then return end
return a, hash, b, title, c
end
youtube_split_url = function (li)
local a, hash, b, title, c = youtube_split_url0(li)
if a then return hash, youtube_make_url(hash), title end
end
bigstr = ee_readfile(fname)
cmds = {}
settag0 = function (s, e, tag)
return format("(set-text-properties %d %d '(face %s))\n", s, e,
tag or "tag-politics")
end
settag = function (s, e, tag) table.insert(cmds, settag0(s, e, tag)) end
allcmds = function () return table.concat(cmds) end
demo = function ()
for s,li,e in bigstr:gmatch("()([^\n]+)()") do
if li:match "youtu" then
settag(s, e)
-- printf("(set-text-properties %d %d '(face tag-politics))\n", s, e)
end
end
end
sec0 = function (li) return "\n"..li.."\n"..string.rep("=", #li).."\n" end
sec = function (li) io.write(sec0(li)) end
demo1 = function (bigstr)
local lines = {}
local oldli = ""
for s,li,e in bigstr:gmatch("()([^\n]+)()") do
if li:match"^=+$" then sec(oldli) end
oldli = li
if li:find("youtu", 1, "plain") then
local hash, url, title = youtube_split_url(li)
if hash then print(url.." "..title) end
end
end
end
-- Local Variables:
-- coding: raw-text-unix
-- End: