Skip to content

Instantly share code, notes, and snippets.

@Sakurina
Created August 15, 2013 19:33
Show Gist options
  • Save Sakurina/6244021 to your computer and use it in GitHub Desktop.
Save Sakurina/6244021 to your computer and use it in GitHub Desktop.
spits out a tab-separated file of video duration / # of videos with that duration, expects to be run in a folder containing the output of youtube-dl's --write-info-json flag
#!/usr/bin/env ruby
require "rubygems"
require "json"
duration_map = {}
Dir.glob("*.json") do |fn|
File.open(fn) do |f|
obj = JSON.parse(f.read())
duration = obj["duration"]
if duration_map[duration]
duration_map[duration] += 1
else
duration_map[duration] = 1
end
end
end
sorted_durations = duration_map.keys.sort { |x,y| x.to_i <=> y.to_i }
sorted_durations.each do |dur|
count = duration_map[dur]
puts "#{dur}\t#{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment