Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract metadata from images and videos #30944

Merged
merged 6 commits into from Oct 22, 2017
Merged

Extract metadata from images and videos #30944

merged 6 commits into from Oct 22, 2017

Conversation

georgeclaghorn
Copy link
Contributor

Provide two built-in analyzers, one for images and the other for videos. Analyze a blob when it’s attached for the first time.

private
def read_image
download_blob_to_tempfile do |file|
require "mini_magick"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is mini_magick a dependency of Rails now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s an optional Active Storage dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we gracefully fail for this require here telling people to include the gem if they don't have?

end

def probe_from(file)
IO.popen([ "ffprobe", "-print_format", "json", "-show_streams", "-v", "error", file.path ]) do |output|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the machines doesn't have ffprobe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Errno::ENOENT exception would have been raised. FFmpeg commonly won’t be installed at first, so I switched to logging an informative message and failing gracefully in 1d4b6db.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small concern about gracefully failing when the libraries are not available but this looks good to me.

private
def read_image
download_blob_to_tempfile do |file|
require "mini_magick"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we gracefully fail for this require here telling people to include the gem if they don't have?

end

def probe_from(file)
IO.popen([ "ffprobe", "-print_format", "json", "-show_streams", "-v", "error", file.path ]) do |output|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@georgeclaghorn georgeclaghorn merged commit 6054840 into rails:master Oct 22, 2017
@georgeclaghorn georgeclaghorn deleted the activestorage-metadata branch Oct 22, 2017
@@ -0,0 +1,13 @@
# frozen_string_literal: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no strings in this file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop doesn't make that distinction. And even if it could, of two bad options, I think I'd prefer to always add this when creating new files than add it when a later edit happens to introduce a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants