-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblip_exporter.rb
35 lines (26 loc) · 1.24 KB
/
blip_exporter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'nokogiri'
require 'open-uri'
#------------------------------------------------------------------------------#
# SO YOU'D LIKE TO EXPORT YOUR BLIPS, CONGRATS! #
# #
# While fairly dumb, this script will export all track titles of your (or any- #
# one else's, really) blip.fm stream, as many pages back as you like, starting #
# from the most recent blip. #
args_err = "Please provide this script with your blip.fm permalink,
the number of pages (most recent first) of blips to export,
and a filepath to save the blip titles to, like so:
#{$0} permalink pages filename"
#------------------------------------------------------------------------------#
abort args_err if (ARGV.size != 3)
permalink = ARGV[0]
num_pages = ARGV[1].to_i
filename = ARGV[2]
file = File.open(filename, "w")
b_url = "http://blip.fm/#{permalink}?page="
for i in 1..num_pages
url = b_url + i.to_s
page = Nokogiri::HTML(open(url))
blips = page.css("div#blipsContainer a[class='clickable blipTypeIcon']")
blips.collect { |b| file.write(b["title"].sub("search for ", "").gsub(/\\/, "").gsub(/$/, "\n")) }
end
file.close