Skip to content

Commit

Permalink
V : 0.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu committed Jun 21, 2017
1 parent 373a84d commit db6cd42
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 57 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changelog :

0.12.5 : stability fix : fixed a wrong path for the covers ( they were not displayed correctly on the local website ) + corrected a few errors with the todo elements and the related display<br />
0.12.4 : stability fix : corrected an error with the instruction parsing<br />
0.12.3 : stability fix : fixed an issue with the instrction parser + an issue where MangaScrap would download 0 pages for a chapter<br />
0.12.2 : stability fix : fixed an issue when setting a param with a number<br />
Expand Down
19 changes: 12 additions & 7 deletions sources/DB/Manga_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,33 @@ def get_manga_list(site = nil)

# _todo database
def add_todo(manga_data, volume_value, chapter_value, page_nb)
insert = [manga_data.id, volume_value, chapter_value, page_nb, now]
if manga_data == nil || volume_value == nil || chapter_value == nil || page_nb == nil
puts 'Error while trying to insert element in todo database => nil'
p insert
puts '(manga_name, volume, chapter, page)'
puts '(manga_name, volume, chapter, page, date)'
exit 2
end
todo = get_todo(manga_data)
insert = [manga_data.id, volume_value, chapter_value, page_nb]
todo.each do |elem|
elem.pop
elem.shift
if elem == insert
if elem[:manga_id] == manga_data.id && elem[:volume] == volume_value && elem[:chapter] == chapter_value && elem[:page] == page_nb
return false
end
end
insert << now
Utils_database::db_exec('INSERT INTO manga_todo VALUES (NULL, ?, ?, ?, ?, ?)', 'could not add todo for ' + manga_data.name, @db, insert)
true
end

def get_todo(manga_data)
Utils_database::db_exec('SELECT * FROM manga_todo WHERE mangaId=?', 'exception on database while getting todo of ' + manga_data.name, @db, [manga_data.id])
raw_todo = Utils_database::db_exec('SELECT * FROM manga_todo WHERE mangaId=?', 'exception on database while getting todo of ' + manga_data.name, @db, [manga_data.id])
if raw_todo.size == 0
return raw_todo
end
ret = []
raw_todo.each do |todo|
ret << Struct::Todo_value.new(*todo)
end
ret
end

def delete_todo(id)
Expand Down
43 changes: 26 additions & 17 deletions sources/Download/base_downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def link_err(data, chapter, disp)

def validate_data(description, author, artist, type, status, genres, release, html_name, alternative_names, rank, rating, rating_max, cover_xpath)
Utils_file::dir_create(@dir)
Utils_connection::write_cover(@doc, cover_xpath, @dir + 'cover.jpg', @params[:manga_path] + @manga_data.site_dir + @manga_data.name + '.jpg')
Utils_connection::write_cover(@doc, cover_xpath, @dir + 'cover.jpg', @params[:manga_path] + @manga_data.site_dir + 'mangas/' + @manga_data.name + '.jpg')
File.open(@dir + 'description.txt', 'w') do |txt|
txt << Utils_file::data_concatenation(@manga_data, Utils_file::description_manipulation(description), author, artist, type, status, genres, release, html_name, alternative_names)
end
Expand Down Expand Up @@ -135,22 +135,15 @@ def todo
todo = @db.get_todo(@manga_data)
if todo.size != 0
@aff.prepare_todo
biggest = todo.map { |a| [a[2], 0].max }.max
todo = todo.sort_by! { |a| [(a[2] < 0) ? (biggest + a[2] * -1) : a[2], -a[3]] }
todo.each do |elem|
@aff.display_todo('downloading ' + values_to_string(elem[2], elem[3], elem[4]))
if elem[4] != -1 # if chapter
data = [] << elem[2] << elem[3] << elem[4]
if page_link(link_generator(elem[2], elem[3], elem[4]), data)
@db.delete_todo(elem[0])
else
@aff.todo_err('failed to download ' + values_to_string(elem[2], elem[3], elem[4]))
Utils_misc::sort_chapter_list(todo, true).each do |elem|
if elem[:page] != -1 # if page
data = [] << elem[:volume] << elem[:chapter] << elem[:page]
if page_link(link_generator(elem[:volume], elem[:chapter], elem[:page]), data)
@db.delete_todo(elem[:id])
end
else # if not a chapter
if chapter_link(link_generator(elem[2], elem[3], 1))
@db.delete_todo(elem[0])
else
@aff.todo_err('failed to download ' + values_to_string(elem[2], elem[3], nil), true)
else # if chapter
if chapter_link(link_generator(elem[:volume], elem[:chapter], 1))
@db.delete_todo(elem[:id])
end
end
end
Expand All @@ -162,17 +155,33 @@ def todo
# checks witch are the chapters that have not been downloaded ( they are not in the traces database )
# the method first gets all of the links from the database and then compares with the links of the website
def missing_chapters
=begin
traces = @db.get_trace(@manga_data)
i = 0
@links.each do |link|
data = Utils_website_specific::Mangafox::data_extractor(link)
data = @manga_data.extract_values_from_link(link)
if traces.count{|_id, _manga_name, vol_value, chap_value| vol_value == data[0] && chap_value == data[1]} == 0
prep_display = " ( link #{i + 1} / #{@links.size} )"
chapter_link(link, prep_display)
end
i += 1
end
@aff.dump
=end
traces = @db.get_trace(@manga_data)
i = 0
all_data = []
@links.each do |link|
all_data << Struct::Data.new(*@manga_data.extract_values_from_link(link), link)
end
Utils_misc::sort_chapter_list(all_data).each do |data|
if traces.count{|_id, _manga_name, vol_value, chap_value| vol_value == data[:volume] && chap_value == data[:chapter]} == 0
prep_display = " ( link #{i + 1} / #{@links.size} )"
chapter_link(data[:link], prep_display)
end
i += 1
end
@aff.dump
end

# the update method will first check for _todo elements to download then check for missing chapters
Expand Down
1 change: 1 addition & 0 deletions sources/Download/mangafox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def chapter_link(link, prep_display = '')
true
end

public
def data
unless @extracted_data
@extracted_data = true
Expand Down
35 changes: 19 additions & 16 deletions sources/Download/mangareader_mangapanda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ def page_link(link, data)

def chapter_link(link, prep_display = '')
data = @manga_data.extract_values_from_link(link)
@aff.prepare_chapter("downloading chapter #{data[1]} of #{@manga_data.name}" + prep_display)
begin
if (page = Utils_connection::get_page(link, true)) == nil
return link_err(data, true, 'X')
end
rescue RuntimeError
return link_err(data, true, 'R')
end
@aff.prepare_chapter("downloading chapter #{data[1]} of #{@manga_data.name}" + prep_display)
number_of_pages = page.xpath('//option').last.text.to_i
if number_of_pages == 0
return link_err(data, true, '?')
Expand All @@ -60,21 +60,24 @@ def chapter_link(link, prep_display = '')
true
end

public
def data
@extracted_data = true
tmp = @doc.xpath('//div[@id="mangaproperties"]/table/tr')
alternative_names = tmp[1].text.split(':')[1].strip
release = tmp[2].text.split(':')[1].strip.to_i
author = tmp[4].text.split(':')[1].strip
artist = tmp[5].text.split(':')[1].strip
genres = tmp[7].text.split(':')[1].strip
description = @doc.xpath('//div[@id="readmangasum"]/p')[0].text
status = tmp[3].text.split(':')[1].strip
rank = -1
rating = -1
rating_max = -1
type = (tmp[6].text.split(':')[1].strip == 'Right to Left') ? 'Manga' : 'Manhwa'
html_name = @doc.xpath('//h2')[0].text
validate_data(description, author, artist, type, status, genres, release, html_name, alternative_names, rank, rating, rating_max, '//div[@id="mangaimg"]/img')
unless @extracted_data
@extracted_data = true
tmp = @doc.xpath('//div[@id="mangaproperties"]/table/tr')
alternative_names = tmp[1].text.split(':')[1].strip
release = tmp[2].text.split(':')[1].strip.to_i
author = tmp[4].text.split(':')[1].strip
artist = tmp[5].text.split(':')[1].strip
genres = tmp[7].text.split(':')[1].strip
description = @doc.xpath('//div[@id="readmangasum"]/p')[0].text
status = tmp[3].text.split(':')[1].strip
rank = -1
rating = -1
rating_max = -1
type = (tmp[6].text.split(':')[1].strip == 'Right to Left') ? 'Manga' : 'Manhwa'
html_name = @doc.xpath('//h2')[0].text
validate_data(description, author, artist, type, status, genres, release, html_name, alternative_names, rank, rating, rating_max, '//div[@id="mangaimg"]/img')
end
end
end
21 changes: 8 additions & 13 deletions sources/DownloadDisplay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def dump_chapter
puts ('downloaded ' + @pages.to_s + ' page' + ((@pages > 1) ? 's' : '')).green
if @failed != 0
puts 'could not download '.yellow + @failed.to_s.red + ' out of '.yellow + @pages.to_s
puts 'all pages were added to the todo database'
unless @todo
puts 'all pages were added to the todo database'
end
end
@failed = 0
@pages = 0
Expand Down Expand Up @@ -70,13 +72,7 @@ def prepare_todo
introduce_manga
end
puts ''
puts 'downloading todo pages'
end

# normal display for a todo element
def display_todo(string, chapter = false)
puts ''
puts string
puts 'downloading todo pages'.magenta
end

# called when an error occured while trying to download a todo element
Expand All @@ -87,7 +83,8 @@ def todo_err(string, chapter = false)
# this is called once the todo is done ( called at the end of todo )
def end_todo
@todo = false
puts 'done'
puts ''
puts 'done'.magenta
puts ''
end

Expand Down Expand Up @@ -139,10 +136,8 @@ def error_on_page_download(error = 'X')
introduction
end
# depending on the error message a different character can be displayed
unless @todo
printf error.red
STDOUT.flush
end
printf error.red
STDOUT.flush
@total_failed_pages += 1
@failed += 1
@total_pages += 1
Expand Down
2 changes: 1 addition & 1 deletion sources/api/mangas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def self.data(mangas)
puts 'downloading data of ' + mangas.size.to_s + ' element(s)'
html = HTML.new
mangas.each do |manga|
dw = manga.get_download_class(false)
dw = manga.get_download_class
if dw == nil
next
end
Expand Down
3 changes: 1 addition & 2 deletions sources/html/html_manga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def html_generate_chapters(manga_data)
def chapter_list_to_a_list(template)
ret = ''
buff = ''
biggest = @traces.map { |a| [a[:volume], 0].max }.max
@traces = @traces.sort_by { |a| [(a[:volume] < 0) ? (biggest + a[:volume] * -1) * -1 : a[:volume] * -1, -a[:chapter]] }
@traces = Utils_misc::sort_chapter_list(@traces)
@traces.each do |chapter|
# pp chapter
# exit 42
Expand Down
3 changes: 3 additions & 0 deletions sources/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def self.get_file_list
utils/utils_errors
utils/utils_co
utils/utils_db
utils/utils_misc
utils/utils_html
utils/utils_debug
utils/utils_user_input
Expand Down Expand Up @@ -89,6 +90,8 @@ def self.initialize_mangascrap
Struct.new('Updated', :name, :downloaded)
Struct.new('Query_arg', :name, :arg_type, :sql_column, :sub_string)
Struct.new('HTML_data', :volume, :chapter, :date, :href, :nb_pages, :file_name)
Struct.new('Data', :volume, :chapter, :page, :link)
Struct.new('Todo_value', :id, :manga_id, :volume, :chapter, :page, :date)
Struct.new('Param_value', :string, :id, :type, :value, :class, :min_value, :max_value)
begin
Utils_file::dir_create(Dir.home + '/.MangaScrap/db')
Expand Down
2 changes: 1 addition & 1 deletion sources/templates/text/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.4
0.12.5
11 changes: 11 additions & 0 deletions sources/utils/utils_misc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

module Utils_misc
def self.sort_chapter_list(chapter_list, pages = false)
biggest = chapter_list.map { |a| [a[:volume], 0].max }.max
if pages # used for _todo
return chapter_list.sort_by { |a| [((a[:volume] < 0) ? (biggest + a[:volume] * -1) : a[:volume]), a[:chapter], a[:page]] }
else # used for traces
return chapter_list.sort_by { |a| [((a[:volume] < 0) ? (biggest + a[:volume] * -1) : a[:volume]), a[:chapter]] }
end
end
end

0 comments on commit db6cd42

Please sign in to comment.