New chapters for lost metal

This commit is contained in:
Nemo 2022-09-29 14:15:03 +05:30
parent 90bfdc76f3
commit 371677cdcc
1 changed files with 28 additions and 5 deletions

View File

@ -1,5 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'uri'
require 'date' require 'date'
require 'fileutils' require 'fileutils'
require 'nokogiri' require 'nokogiri'
@ -10,10 +11,13 @@ BASE = 'https://www.tor.com/2022/'
links = [ links = [
'09/19/read-the-lost-metal-by-brandon-sanderson-prologue-and-chapters-1-2/', '09/19/read-the-lost-metal-by-brandon-sanderson-prologue-and-chapters-1-2/',
'09/26/read-the-lost-metal-by-brandon-sanderson-chapters-3-4/'
] ]
episode = 1 episode = 1
counter = 0
links.each do |link| links.each do |link|
url = BASE + link url = BASE + link
puts "Download #{url}" puts "Download #{url}"
@ -24,17 +28,36 @@ links.each do |link|
end end
# Now we have all the files # Now we have all the files
html = '<h1>Prologue</h1>' html = ''
for i in 1..(links.length) for i in 1..(links.length)
page = Nokogiri::HTML(open("lost-metal/#{i}.html")).css('.entry-content') page = Nokogiri::HTML(open("lost-metal/#{i}.html")).css('.entry-content')
start = ending = false start = ending = false
page.children.each do |e| page.children.each do |e|
if e.name == 'h4' if ['h1', 'h2', 'h3', 'h4', 'hr'].include? e.name
e.name = 'h1' e.remove
end end
if e.name == 'h3' if e.text ==' '
e.name = 'div' e.remove
end
if e.name == 'p'
e.children.each do |ee|
if ee.name == 'img'
u = URI::parse ee['src']
if counter == 0
e.add_previous_sibling "<h1>Prologue</h1>"
else
e.add_previous_sibling "<hr><h1> Chapter #{counter}"
end
counter += 1
ee.delete 'srcset'
ee.delete 'class'
ee.delete 'loading'
ee.delete 'sizes'
ee.delete 'data-recalc-dims'
end
end
end end
start = true if e.class?('ebook-link-wrapper') start = true if e.class?('ebook-link-wrapper')