Created
June 13, 2020 21:34
-
-
Save zph/ef9f1f25e13f3e76eedec9eee6cc84e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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