mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Fix downloader stuck on external chapters
This commit is contained in:
parent
17837d8a29
commit
8950c3a1ed
@ -49,6 +49,9 @@ module MangaDex
|
|||||||
@queue.set_status Queue::JobStatus::Downloading, job
|
@queue.set_status Queue::JobStatus::Downloading, job
|
||||||
begin
|
begin
|
||||||
chapter = @client.chapter job.id
|
chapter = @client.chapter job.id
|
||||||
|
# We must put the `.pages` call in a rescue block to handle external
|
||||||
|
# chapters.
|
||||||
|
pages = chapter.pages
|
||||||
rescue e
|
rescue e
|
||||||
Logger.error e
|
Logger.error e
|
||||||
@queue.set_status Queue::JobStatus::Error, job
|
@queue.set_status Queue::JobStatus::Error, job
|
||||||
@ -58,7 +61,7 @@ module MangaDex
|
|||||||
@downloading = false
|
@downloading = false
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@queue.set_pages chapter.pages.size, job
|
@queue.set_pages pages.size, job
|
||||||
lib_dir = @library_path
|
lib_dir = @library_path
|
||||||
rename_rule = Rename::Rule.new \
|
rename_rule = Rename::Rule.new \
|
||||||
Config.current.mangadex["manga_rename_rule"].to_s
|
Config.current.mangadex["manga_rename_rule"].to_s
|
||||||
@ -69,13 +72,13 @@ module MangaDex
|
|||||||
zip_path = File.join manga_dir, "#{job.title}.cbz.part"
|
zip_path = File.join manga_dir, "#{job.title}.cbz.part"
|
||||||
|
|
||||||
# Find the number of digits needed to store the number of pages
|
# Find the number of digits needed to store the number of pages
|
||||||
len = Math.log10(chapter.pages.size).to_i + 1
|
len = Math.log10(pages.size).to_i + 1
|
||||||
|
|
||||||
writer = Compress::Zip::Writer.new zip_path
|
writer = Compress::Zip::Writer.new zip_path
|
||||||
# Create a buffered channel. It works as an FIFO queue
|
# Create a buffered channel. It works as an FIFO queue
|
||||||
channel = Channel(PageJob).new chapter.pages.size
|
channel = Channel(PageJob).new pages.size
|
||||||
spawn do
|
spawn do
|
||||||
chapter.pages.each_with_index do |url, i|
|
pages.each_with_index do |url, i|
|
||||||
fn = Path.new(URI.parse(url).path).basename
|
fn = Path.new(URI.parse(url).path).basename
|
||||||
ext = File.extname fn
|
ext = File.extname fn
|
||||||
fn = "#{i.to_s.rjust len, '0'}#{ext}"
|
fn = "#{i.to_s.rjust len, '0'}#{ext}"
|
||||||
@ -99,7 +102,7 @@ module MangaDex
|
|||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
page_jobs = [] of PageJob
|
page_jobs = [] of PageJob
|
||||||
chapter.pages.size.times do
|
pages.size.times do
|
||||||
page_job = channel.receive
|
page_job = channel.receive
|
||||||
|
|
||||||
break unless @queue.exists? job
|
break unless @queue.exists? job
|
||||||
|
Loading…
x
Reference in New Issue
Block a user