Created
June 18, 2013 04:28
-
-
Save kimhunter/5802676 to your computer and use it in GitHub Desktop.
WWDC2013 session video renaming script
This file contains 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 '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