-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.rb
48 lines (34 loc) · 1.03 KB
/
script.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
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'down'
gem 'nokogiri'
end
require 'nokogiri'
require "down"
require "fileutils"
BASE_URL = 'https://www.eltontabs.com'
DEST_DIR = "#{__dir__}/downloads"
S3_URL = 'tabarchive.s3.us-east-2.amazonaws.com'
url = 'https://www.eltontabs.com/albumList?artistId=2'
document = Nokogiri::HTML.parse(URI.open(url))
anchors = document.xpath('//a')
dir_num = 0
anchors.each do |a|
next unless a[:href].start_with?("/songList")
puts "Downloading album: #{dir_num}"
album_url = BASE_URL + a[:href]
album_document = Nokogiri::HTML.parse(URI.open(album_url))
album_anchors = album_document.xpath('//a')
album_dir = "#{DEST_DIR}/#{dir_num}"
FileUtils.mkdir_p(album_dir)
album_anchors.each do |aa|
if aa[:href].include?(S3_URL) && aa[:href].end_with?('.txt', '.pdf')
tempfile = Down.download(aa[:href])
FileUtils.mv(tempfile.path, "#{album_dir}/#{tempfile.original_filename}")
end
end
dir_num += 1
end
puts 'Done!'