Project-wise refactoring to follow Ameba

This commit is contained in:
Alex Ling
2020-04-08 06:41:27 +00:00
parent d33cae7618
commit fcf9d39047
10 changed files with 108 additions and 121 deletions
+26 -30
View File
@@ -52,29 +52,27 @@ module MangaDex
end
def parse_json(obj, lang)
begin
parse_strings_from_json ["lang_code", "title", "volume",
"chapter"]
language = lang[@lang_code]?
@language = language if language
@time = Time.unix obj["timestamp"].as_i
suffixes = ["", "_2", "_3"]
suffixes.each do |s|
gid = obj["group_id#{s}"].as_i
next if gid == 0
gname = obj["group_name#{s}"].as_s
@groups << {gid, gname}
end
@full_title = @title
unless @chapter.empty?
@full_title = "Ch.#{@chapter} " + @full_title
end
unless @volume.empty?
@full_title = "Vol.#{@volume} " + @full_title
end
rescue e
raise "failed to parse json: #{e}"
parse_strings_from_json ["lang_code", "title", "volume",
"chapter"]
language = lang[@lang_code]?
@language = language if language
@time = Time.unix obj["timestamp"].as_i
suffixes = ["", "_2", "_3"]
suffixes.each do |s|
gid = obj["group_id#{s}"].as_i
next if gid == 0
gname = obj["group_name#{s}"].as_s
@groups << {gid, gname}
end
@full_title = @title
unless @chapter.empty?
@full_title = "Ch.#{@chapter} " + @full_title
end
unless @volume.empty?
@full_title = "Vol.#{@volume} " + @full_title
end
rescue e
raise "failed to parse json: #{e}"
end
end
@@ -108,12 +106,10 @@ module MangaDex
end
def parse_json(obj)
begin
parse_strings_from_json ["cover_url", "description", "title", "author",
"artist"]
rescue e
raise "failed to parse json: #{e}"
end
parse_strings_from_json ["cover_url", "description", "title", "author",
"artist"]
rescue e
raise "failed to parse json: #{e}"
end
end
@@ -146,7 +142,7 @@ module MangaDex
chapter = Chapter.new k, v, manga, @lang
manga.chapters << chapter
end
return manga
manga
rescue
raise "Failed to parse JSON"
end
@@ -195,7 +191,7 @@ module MangaDex
manga = self.get_manga manga_id
chapter = manga.chapters.find { |c| c.id == id }.not_nil!
self.get_chapter chapter
return chapter
chapter
end
end
end
+4 -4
View File
@@ -52,7 +52,7 @@ module MangaDex
def self.from_query_result(res : DB::ResultSet)
job = Job.allocate
job.parse_query_result res
return job
job
end
def initialize(@id, @manga_id, @title, @manga_title, @status, @time)
@@ -120,7 +120,7 @@ module MangaDex
rescue
end
end
return job
job
end
# Push an array of jobs into the queue, and return the number of jobs
@@ -203,7 +203,7 @@ module MangaDex
Job.from_query_result rs
end
end
return jobs
jobs
end
def add_success(job : Job)
@@ -338,7 +338,7 @@ module MangaDex
@logger.error msg
end
end
fail_count = page_jobs.select { |j| !j.success }.size
fail_count = page_jobs.count { |j| !j.success }
@logger.debug "Download completed. " \
"#{fail_count}/#{page_jobs.size} failed"
writer.close