/
plugin.rb
63 lines (62 loc) · 1.45 KB
/
plugin.rb
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
class VideoSitePlugin
def save
name = "#{prefix}#{id}_#{title ? title : 'no_title'}.#{extension}".gsub(/[\\\/\,\;\:\*\?\"\<\>\|]/,'_')
path = "#{$conf[:cache_dir]}/#{name}"
tmp = "#{$conf[:cache_dir]}/tmp.#{name}"
File.open(WINDOWS ? tmp.tosjis : tmp, 'wb') {|f| yield f}
if WINDOWS
File.rename(tmp.tosjis, path.tosjis)
else
File.rename(tmp, path)
end
end
def cache_find
Dir.entries($conf[:cache_dir]).each do |f|
return "#{$conf[:cache_dir]}/#{f}" if f =~ /^#{prefix}#{id}_/
end
false
end
def cached?
@cache_path = cache_find
@cache_path ? true : false
end
def cache_name
if cached?
File.basename(@cache_path)
end
end
def cache_read
if cached?
File.open(WINDOWS ? @cache_path.tosjis : @cache_path, 'rb') {|f|
f.read
}
end
end
def cache_size
if cached?
File.size(WINDOWS ? @cache_path.tosjis : @cache_path)
end
end
def cache_mime_type
mime_types = {
'js' => 'application/x-javascript',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/flv',
'mp4' => 'video/mp4'
}
mime_types.default = 'plain/text'
mime_types[extension]
end
end
def load_plugins
sites = []
pd = $conf[:plugin_dir]
Dir.entries(pd).sort.each do |f|
next if f !~ /\.rb$/
File.open("#{pd}/#{f}") {|file|
tmp = eval(file.read)
sites << tmp if tmp.kind_of? VideoSitePlugin
}
end
sites
end