Last active
August 9, 2017 10:12
-
-
Save tnt/843377eb6c8628a5c1fde70b570c32d9 to your computer and use it in GitHub Desktop.
Repairing botched youtube time links in a pry session
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' | |
d = '<p><a href="https://www.youtube.com/watch?v=kSx8HJfBl7U#">00:04</a> November 20, 2013, <a href="https://www.youtube.com/watch?v=kSx8HJfBl7U#">01:13</a> … <a href="https://www.youtube.com/watch?v=kSx8HJfBl7U#">04:32:27</a> July 17, <a href="https://www.youtube.com/watch?v=kSx8HJfBl7U#">05:03:33</a> Credits</p>' | |
def str2secs st; s,m,h = st.split(':').reverse.map(&:to_i); h.to_i*3600+m*60+s;end | |
yourl = 'https://youtu.be/kSx8HJfBl7U?t=%d' | |
d.css('a').each {|a| a['href'] = yourl % str2secs(a.text) } | |
File.open('saker.txt','w') {|fh| fh.write d.to_s } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment