Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract image URL from Flickr Embedded Image Code for use in Google Sheets
# Example:
#
# embedded = '<a data-flickr-embed="true" href="https://www.flickr.com/photos/galtzo/32796076230/in/album-72157679012034441/" title="IMG_2054"><img src="https://c1.staticflickr.com/3/2939/32796076230_773e54a3b0_h.jpg" width="1200" height="1600" alt="IMG_2054"></a><script async src="//embedr.flickr.com/assets/client-code.js" charset="utf-8"></script>'
# extract_embedded_flickr_image_url_for_google_sheets(embedded)
#
def extract_embedded_flickr_image_url_for_google_sheets(embedded, mode: 4, aspect: "4:3", height: nil, width: nil)
options = []
url = embedded[(start = embedded.index("img src=\"https")+9)..(start+embedded[start..(-1)].index("g\" "))]
options << "\"#{url}\""
options << mode.to_s
if mode == 4
if height.nil? && width.nil?
options.concat(
case aspect
when "4:3" then
%w(100 75)
when "3:4" then
%w(75 100)
else
%w(100 100)
end
)
else
options << height.to_s
options << width.to_s
end
end
result = "=IMAGE(#{options.join(", ")})"
`printf '#{result}' | pbcopy`
puts "for Google Sheets:\n#{result}"
puts "copied to clipboard"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment