Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b852ef26
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b852ef26
编写于
12月 01, 2017
作者:
G
George Claghorn
提交者:
GitHub
12月 01, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make ASt previewer/analyzer binary paths configurable
上级
32516e88
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
4 deletion
+32
-4
activestorage/lib/active_storage/analyzer/video_analyzer.rb
activestorage/lib/active_storage/analyzer/video_analyzer.rb
+3
-1
activestorage/lib/active_storage/engine.rb
activestorage/lib/active_storage/engine.rb
+18
-1
activestorage/lib/active_storage/previewer/pdf_previewer.rb
activestorage/lib/active_storage/previewer/pdf_previewer.rb
+8
-1
activestorage/lib/active_storage/previewer/video_previewer.rb
...vestorage/lib/active_storage/previewer/video_previewer.rb
+3
-1
未找到文件。
activestorage/lib/active_storage/analyzer/video_analyzer.rb
浏览文件 @
b852ef26
...
...
@@ -19,6 +19,8 @@ module ActiveStorage
# This analyzer requires the {ffmpeg}[https://www.ffmpeg.org] system library, which is not provided by Rails. You must
# install ffmpeg yourself to use this analyzer.
class
Analyzer::VideoAnalyzer
<
Analyzer
class_attribute
:ffprobe_path
,
default:
"ffprobe"
def
self
.
accept?
(
blob
)
blob
.
video?
end
...
...
@@ -68,7 +70,7 @@ def probe
end
def
probe_from
(
file
)
IO
.
popen
([
"ffprobe"
,
"-print_format"
,
"json"
,
"-show_streams"
,
"-v"
,
"error"
,
file
.
path
])
do
|
output
|
IO
.
popen
([
ffprobe_path
,
"-print_format"
,
"json"
,
"-show_streams"
,
"-v"
,
"error"
,
file
.
path
])
do
|
output
|
JSON
.
parse
(
output
.
read
)
end
rescue
Errno
::
ENOENT
...
...
activestorage/lib/active_storage/engine.rb
浏览文件 @
b852ef26
...
...
@@ -15,7 +15,8 @@ class Engine < Rails::Engine # :nodoc:
config
.
active_storage
=
ActiveSupport
::
OrderedOptions
.
new
config
.
active_storage
.
previewers
=
[
ActiveStorage
::
Previewer
::
PDFPreviewer
,
ActiveStorage
::
Previewer
::
VideoPreviewer
]
config
.
active_storage
.
analyzers
=
[
ActiveStorage
::
Analyzer
::
ImageAnalyzer
,
ActiveStorage
::
Analyzer
::
VideoAnalyzer
]
config
.
active_storage
.
analyzers
=
[
ActiveStorage
::
Analyzer
::
ImageAnalyzer
,
ActiveStorage
::
Analyzer
::
VideoAnalyzer
]
config
.
active_storage
.
paths
=
ActiveSupport
::
OrderedOptions
.
new
config
.
eager_load_namespaces
<<
ActiveStorage
...
...
@@ -68,5 +69,21 @@ class Engine < Rails::Engine # :nodoc:
end
end
end
initializer
"active_storage.paths"
do
config
.
after_initialize
do
|
app
|
if
ffprobe_path
=
app
.
config
.
active_storage
.
paths
.
ffprobe
ActiveStorage
::
Analyzer
::
VideoAnalyzer
.
ffprobe_path
=
ffprobe_path
end
if
ffmpeg_path
=
app
.
config
.
active_storage
.
paths
.
ffmpeg
ActiveStorage
::
Previewer
::
VideoPreviewer
.
ffmpeg_path
=
ffmpeg_path
end
if
mutool_path
=
app
.
config
.
active_storage
.
paths
.
mutool
ActiveStorage
::
Previewer
::
PDFPreviewer
.
mutool_path
=
mutool_path
end
end
end
end
end
activestorage/lib/active_storage/previewer/pdf_previewer.rb
浏览文件 @
b852ef26
...
...
@@ -2,16 +2,23 @@
module
ActiveStorage
class
Previewer::PDFPreviewer
<
Previewer
class_attribute
:mutool_path
,
default:
"mutool"
def
self
.
accept?
(
blob
)
blob
.
content_type
==
"application/pdf"
end
def
preview
download_blob_to_tempfile
do
|
input
|
draw
"mutool"
,
"draw"
,
"-F"
,
"png"
,
"-o"
,
"-"
,
input
.
path
,
"1"
do
|
output
|
draw
_first_page_from
input
do
|
output
|
yield
io:
output
,
filename:
"
#{
blob
.
filename
.
base
}
.png"
,
content_type:
"image/png"
end
end
end
private
def
draw_first_page_from
(
file
,
&
block
)
draw
mutool_path
,
"draw"
,
"-F"
,
"png"
,
"-o"
,
"-"
,
file
.
path
,
"1"
,
&
block
end
end
end
activestorage/lib/active_storage/previewer/video_previewer.rb
浏览文件 @
b852ef26
...
...
@@ -2,6 +2,8 @@
module
ActiveStorage
class
Previewer::VideoPreviewer
<
Previewer
class_attribute
:ffmpeg_path
,
default:
"ffmpeg"
def
self
.
accept?
(
blob
)
blob
.
video?
end
...
...
@@ -16,7 +18,7 @@ def preview
private
def
draw_relevant_frame_from
(
file
,
&
block
)
draw
"ffmpeg"
,
"-i"
,
file
.
path
,
"-y"
,
"-vcodec"
,
"png"
,
draw
ffmpeg_path
,
"-i"
,
file
.
path
,
"-y"
,
"-vcodec"
,
"png"
,
"-vf"
,
"thumbnail"
,
"-vframes"
,
"1"
,
"-f"
,
"image2"
,
"-"
,
&
block
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录