Adds windows support and URL generation
Changes from @mikealbergquist
This commit is contained in:
commit
c335bc97a1
|
@ -44,8 +44,8 @@ More details at https://www.tor.com/series/edgedancer-reread-brandon-sanderson/
|
|||
|
||||
- Ruby
|
||||
- Nokogiri gem installed (`gem install nokogiri`)
|
||||
- Unix system with `wget` installed
|
||||
- `pandoc` installed and available (for all 3 formats)
|
||||
- Paru gem installed (`gem install paru`)
|
||||
- (mobi only): `ebook-convert` (from calibre) available to generate the mobi file
|
||||
- (pdf) `wkhtmltopdf` for converting html to pdf
|
||||
- (pdf) `pdftk` to stitch the final PDF file
|
||||
|
@ -53,6 +53,7 @@ More details at https://www.tor.com/series/edgedancer-reread-brandon-sanderson/
|
|||
- The final 2 tools can be skipped if you don't care about the PDF generation.
|
||||
- You can also skip calibre if you only want the EPUB file.
|
||||
- Edit the last line in `*.rb` to `:epub` / `:mobi`, `:pdf` to only trigger the specific builds
|
||||
- Windows users need wget. Download the latest wget.exe from https://eternallybored.org/misc/wget/ and add it's directory to the PATH environment variable or put it directly in C:\Windows.
|
||||
|
||||
## Generation
|
||||
|
||||
|
|
20
methods.rb
20
methods.rb
|
@ -33,12 +33,20 @@ def format_match(format)
|
|||
end
|
||||
|
||||
def gen_epub(name, _format)
|
||||
if command?('pandoc') && format_match(:epub)
|
||||
# Convert it to epub
|
||||
`pandoc -S -o books/#{name}.epub --epub-metadata=metadata/#{name}.xml --epub-cover-image=covers/#{name}.jpg books/#{name}.html`
|
||||
puts '[epub] Generated EPUB file'
|
||||
else
|
||||
puts "[error] Can't generate EPUB without pandoc"
|
||||
if format_match(:epub)
|
||||
begin
|
||||
require "paru/pandoc"
|
||||
Paru::Pandoc.new do
|
||||
from "html"
|
||||
to "epub"
|
||||
epub_metadata "metadata/#{name}.xml"
|
||||
epub_cover_image "covers/#{name}.jpg"
|
||||
output "books/#{name}.epub"
|
||||
end.convert File.read("books/#{name}.html")
|
||||
puts '[epub] Generated EPUB file'
|
||||
rescue LoadError
|
||||
puts "[error] Can't generate EPUB without paru"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -9,16 +9,34 @@ BASE = 'https://www.tor.com/2017/'.freeze
|
|||
links = [
|
||||
'08/22/oathbringer-brandon-sanderson-prologue/',
|
||||
'08/29/oathbringer-brandon-sanderson-chapter-1-3/',
|
||||
'09/05/oathbringer-by-brandon-sanderson-chapters-4-6/',
|
||||
'09/12/oathbringer-by-brandon-sanderson-chapters-7-9/'
|
||||
'09/05/oathbringer-by-brandon-sanderson-chapters-4-6/'
|
||||
]
|
||||
|
||||
links.last.split('/')
|
||||
manually_add_links = false;
|
||||
|
||||
month = links.last.split('/').first
|
||||
day = links.last.split('/')[1]
|
||||
|
||||
next_date = Date.new(2017, month.to_i, day.to_i) + 7
|
||||
if manually_add_links
|
||||
# Only downloads links already added to array <links>
|
||||
puts 'Downloading manually added links'
|
||||
links.last.split('/')
|
||||
month = links.last.split('/').first
|
||||
day = links.last.split('/')[1]
|
||||
next_date = Date.new(2017, month.to_i, day.to_i) + 7
|
||||
else
|
||||
# Automatically adds all recent chapters
|
||||
puts 'Downloading all found links'
|
||||
chapter = Integer(links.last.split('-').last.gsub(/[^0-9]/, '')) + 1
|
||||
next_date = Date.new(1970,01,01)
|
||||
loop do
|
||||
links.last.split('/')
|
||||
month = links.last.split('/').first
|
||||
day = links.last.split('/')[1]
|
||||
next_date = Date.new(2017, month.to_i, day.to_i) + 7
|
||||
links << "#{next_date.strftime("%m")}/#{next_date.strftime("%d")}/oathbringer-by-brandon-sanderson-chapters-#{chapter}-#{chapter + 2}/"
|
||||
chapter += 3;
|
||||
break if next_date + 7 > Date.today
|
||||
end
|
||||
next_date += 7;
|
||||
end
|
||||
|
||||
episode = 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue