Created
August 9, 2013 11:10
-
-
Save yar/6192861 to your computer and use it in GitHub Desktop.
batch-renaming files like 254--08.00-08.30--Комиссия.mp4 to
20c6655a-4b0d-11e1-8a16-001999c6cab9/1330833600-1330835400.mp4
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' | |
# batch-renaming files like | |
# 254--08.00-08.30--Комиссия.mp4 | |
# to | |
# 20c6655a-4b0d-11e1-8a16-001999c6cab9/1330833600-1330835400.mp4 | |
# | |
File.read("spec/sample_files/json_results.txt").lines.map do |line| | |
JSON.parse(line) | |
end.sort_by { |json| json["video_start"] }.each do |json| | |
json["channels"].each do |channel| | |
old_name = json["name"] + "--" + Time.at(json["video_start"]+json["utc_offset"]*60).utc.strftime("%H.%M")+"-"+Time.at(json["video_start"]+json["utc_offset"]*60+30*60).utc.strftime("%H.%M") + "--" + channel["view"] + ".mp4" | |
new_dir, new_name = channel["url"].gsub(/^.*video\/[^\/]+\/(.*\.mp4).*$/, '\\1').split("/") | |
puts "mkdir -p #{new_dir}; mv #{old_name} #{new_dir}/#{new_name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment