blob: 59cb388fb7917f32fb75ed9da1006c9e6777a65f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#!/usr/bin/env lua
require 'tokyocabinet'
json = require 'json'
http = require 'lcurl'
CACHE = "/home/bie/tmp.db"
cache = tokyocabinet.bdbnew()
cache:open(CACHE, cache.OWRITER + cache.OREADER)
function oembed(url)
local cached = cache:get(url)
if cached then
local data = json.decode(cached)
return data.html
end
local body = ""
local result = http.easy{url=url, writefunction=function(s)
body = body .. s
end}:perform()
if result:getinfo(http.INFO_RESPONSE_CODE) == 200 then
cache:put(url, body)
local data = json.decode(body)
return data.html
else
return ("<b>Klarte ikke embedde %s :(</b>"):format(url)
end
end
function twitter(id)
return oembed("https://publish.twitter.com/oembed?url=" .. id)
end
function youtube(id)
return oembed("http://www.youtube.com/oembed?url=" .. id)
end
function soundcloud(id)
return oembed("https://soundcloud.com/oembed?format=json&url=" .. id)
end
function vimeo(id)
return oembed("https://developer.vimeo.com/apis/oembed.json?url=" .. id)
end
function twitch(id)
return oembed("https://api.twitch.tv/v4/oembed?url=" .. id)
end
function instagram(id)
return oembed("https://api.instagram.com/oembed?url=" .. id)
end
function flickr(id)
return oembed("https://www.flickr.com/services/oembed?url=" .. id)
end
function facebook(id)
return oembed("https://www.facebook.com/plugins/video/oembed.json?url=" .. id)
end
-- if arg[1] then
-- print(arg[1])
-- io.input(arg[1])
-- end
for line in io.lines() do
line = line:gsub("$%s*twitter:%s*(.*)", twitter)
line = line:gsub("$%s*youtube:%s*(.*)", youtube)
line = line:gsub("$%s*soundcloud:%s*(.*)", soundcloud)
line = line:gsub("$%s*twitch:%s*(.*)", twitch)
line = line:gsub("$%s*vimeo:%s*(.*)", vimeo)
line = line:gsub("$%s*instagram:%s*(.*)", instagram)
line = line:gsub("$%s*flickr:%s*(.*)", flickr)
line = line:gsub("$%s*facebook:%s*(.*)", facebook)
print(line)
end
|