Skip to content

Instantly share code, notes, and snippets.

@zph
Created June 13, 2020 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zph/ef9f1f25e13f3e76eedec9eee6cc84e9 to your computer and use it in GitHub Desktop.
Save zph/ef9f1f25e13f3e76eedec9eee6cc84e9 to your computer and use it in GitHub Desktop.
require 'json'
def get_links(file)
body = File.read(file)
json = JSON.parse(body)
kv = json.dig("store", "pluginStates").to_a
JSON.parse(kv.first[1])["requests"]
.map { |k,v| v["url"] }
.reject { |l| l[/clients3\.google\.com|doubleclick|localhost|googleapis\.com/] }
.sort
end
def get_length(url)
maybe_length = `curl --silent --HEAD "#{url}"`
.split("\r\n")
.grep(/Content-Length/)
.first
if maybe_length
maybe_length
.split(" ", 2)[1]
.to_i
else
# TODO: download and check
0
end
end
def main(file)
links = get_links(file)
links_with_length = links.each_with_object({}) do |l, acc|
if !acc[l]
acc[l] = get_length(l)
end
acc
end
.sort_by { |k, v| v }
.reverse
puts JSON.generate(links_with_length)
end
main(ARGV.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment