Created
January 26, 2015 19:05
-
-
Save alexito4/6bf1dd7252f65318acab to your computer and use it in GitHub Desktop.
Download youtube videos form the safari reading list. More info at: http://www.alejandromp.com/blog/2015/1/26/download-youtube-videos-from-the-safari-reading-list
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-plist' | |
require 'uri' | |
class SRLItem | |
attr_accessor :title | |
attr_accessor :url | |
attr_accessor :source | |
def initialize(dict) | |
@title = dict['URIDictionary']['title'] | |
@url = dict['URLString'] | |
@source = dict | |
end | |
def to_s | |
@title + " - " + @url | |
end | |
end | |
def loadXML() | |
xml = `plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist` | |
end | |
def loadReadingList() | |
xml = loadXML() | |
plist = Nokogiri::PList(xml) | |
items = plist["Children"] | |
list = items.select{ |e| | |
e["Title"]=="com.apple.ReadingList" | |
}[0]["Children"] | |
return list | |
end | |
def createItems() | |
rl = loadReadingList() | |
items = rl.map { |e| | |
item = SRLItem.new(e) | |
} | |
return items | |
end | |
def downloadItem(i) | |
# puts "-> " + i.url | |
query_string = URI.parse(i.url).query | |
if !query_string | |
return false | |
end | |
parameters = Hash[URI.decode_www_form(query_string)] | |
id = parameters["v"] | |
yurl = "https://www.youtube.com/watch?v=#{id}" | |
# puts yurl | |
command = "youtube-dl #{yurl} > /dev/null" | |
result = system command | |
return result | |
end | |
items = createItems() | |
yItems = items.select{|i| i.url.include? "youtu"} | |
yItems.each{|i| | |
res = downloadItem(i) | |
puts i.title + " -> "+ res.to_s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment