Skip to content

Instantly share code, notes, and snippets.

@kimhunter
Created June 18, 2013 04:28
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 kimhunter/5802676 to your computer and use it in GitHub Desktop.
Save kimhunter/5802676 to your computer and use it in GitHub Desktop.
WWDC2013 session video renaming script
require 'nokogiri'
doc = Nokogiri::HTML(File.open("Videoswwdc.html"))
items = {}
doc.xpath("//li[@class='session']").each do |session|
session_id = session['id'].sub('-video', '').to_i
title = session.children.xpath("li[@class='title']").text
items[session_id] = title
end
# items.each {|k,v| puts "#{k} => #{v}"}
# PREFIX="/Volumes/GTech/WWDC2013/"
PREFIX="/Users/kim/Downloads/"
files = Dir["#{PREFIX}*-[SH]D.mov"]
base_names = files.map {|d| d.sub(PREFIX, '') }
renames = files.zip base_names.map { |f|
num = f.to_i
title = items[num]
vdef = f['SD'].nil? ? 'HD' : 'SD'
new_name = "#{PREFIX}WWDC2013 #{num} - #{title} - #{vdef}.mov"
}
# would rather confirm this and copy the command into terminal
renames.each do |a,b|
puts "mv \"#{a}\" \"#{b}\""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment