-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthieu
committed
Feb 24, 2018
1 parent
0818b32
commit dfd5c4e
Showing
14 changed files
with
215 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "ALTER TABLE Download ADD loop_on_todo_times INT; | ||
.exit | ||
" | sqlite3 ~/.MangaScrap/db/params.db | ||
|
||
ruby ./../MangaScrap.rb param set ltt 5 | ||
|
||
ruby ../tools/mangafox_to_fanfox.rb | ||
|
||
echo "" | ||
echo "done" | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
1. update the params database with this instruction : | ||
ALTER TABLE Download ADD loop_on_todo_times INT; | ||
|
||
2. give the new parameter ( ltt ) a value. Recommended is 5 | ||
|
||
3. use the tool to update the database and ensure that MangaScrap will be able to continue to update your mangas | ||
ruby tools/mangafox_to_fanfox.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
class Download_Mangafox | ||
include Base_downloader | ||
|
||
private | ||
def extract_links(manga) | ||
links = @manga_data[:index_page].xpath('//a[@class="tips"]').map{ |link| link['href'] } | ||
if links == nil || links.size == 0 | ||
raise ('failed to get manga '.red + manga[:name].yellow + ' chapter index'.red) | ||
end | ||
links | ||
end | ||
|
||
public | ||
def self.volume_string_to_int(string) | ||
case string | ||
when 'TBD' | ||
volume = -2 | ||
when 'NA' | ||
volume = -3 | ||
when 'ANT' | ||
volume = -4 | ||
else | ||
volume = string.to_i | ||
end | ||
volume | ||
end | ||
|
||
def self.data_extractor(link) | ||
link += '1.html' | ||
link_split = link.split('/') | ||
page = link_split[link_split.size - 1].chomp('.html').to_i | ||
link_split[link_split.size - 2][0] = '' | ||
chapter = link_split[link_split.size - 2].to_f | ||
if chapter % 1 == 0 | ||
chapter = chapter.to_i | ||
end | ||
if link_split.size == 8 | ||
link_split[link_split.size - 3][0] = '' | ||
if link_split[link_split.size - 3] =~ /\A\d+\z/ | ||
volume = link_split[link_split.size - 3].to_i | ||
else | ||
if link_split[link_split.size - 3] == 'NA' | ||
volume = -3 | ||
elsif link_split[link_split.size - 3] == 'TBD' | ||
volume = -2 | ||
elsif link_split[link_split.size - 3] == 'ANT' | ||
volume = -4 | ||
else | ||
volume = -42 # error value | ||
end | ||
end | ||
else | ||
volume = -1 # no volume | ||
end | ||
ret = Array.new | ||
ret << volume << chapter << page | ||
ret | ||
end | ||
|
||
def link_generator(volume, chapter, page) | ||
chapter = chapter.to_i if chapter % 1 == 0 | ||
link = @manga_data[:website][:link] + 'manga/' + @manga_data[:name] + '/' | ||
if volume >= 0 | ||
vol_buffer = ((volume >= 10) ? '' : '0') | ||
link += 'v' + vol_buffer + volume.to_s + '/' | ||
elsif volume == -2 | ||
link += 'vTBD/' | ||
elsif volume == -3 | ||
link += 'vNA/' | ||
elsif volume == -4 | ||
link += 'vANT/' | ||
end | ||
chap_buffer = ((chapter < 10) ? '00' : ((chapter < 100) ? '0' : '')) | ||
link += 'c' + chap_buffer | ||
if chapter % 1 == 0 | ||
link += chapter.to_i.to_s | ||
else | ||
link += chapter.to_s | ||
end | ||
link + '/' + ((page < 10) ? '0' : '') + page.to_s + '.html' | ||
end | ||
|
||
# downloads a page, with link = the link, data = [volume, chapter, page] | ||
def page_link(link, data) | ||
get_page_from_link(link, data, '//img[@id="image"]') | ||
end | ||
|
||
# downloads a chapter with link = the link and prep_display = small string displayed when announcing the download of the chapter | ||
def chapter_link(link, prep_display = '') | ||
get_chapter_from_link(link, prep_display, '.html') do |page| | ||
page.xpath('//div[@class="l"]').text.split.last.to_i | ||
end | ||
end | ||
|
||
def data | ||
alternative_names = @manga_data[:index_page].xpath('//div[@id="title"]/h3').text | ||
release_author_artist_genres = @manga_data[:index_page].xpath('//td[@valign="top"]') | ||
release = release_author_artist_genres[0].text.to_i | ||
author = release_author_artist_genres[1].text.gsub(/\s+/, '').gsub(',', ', ') | ||
artist = release_author_artist_genres[2].text.gsub(/\s+/, '').gsub(',', ', ') | ||
genres = release_author_artist_genres[3].text.gsub(/\s+/, '').gsub(',', ', ') | ||
description = @manga_data[:index_page].xpath('//p[@class="summary"]').text | ||
data = @manga_data[:index_page].xpath('//div[@class="data"]/span') | ||
status = data[0].text.gsub(/\s+/, '').split(',')[0] | ||
rank = data[1].text[/\d+/] | ||
rating = data[2].text[/\d+[.,]\d+/] | ||
rating_max = 5 # rating max is a constant in mangafox | ||
tmp_type = @manga_data[:index_page].xpath('//div[@id="title"]/h1')[0].text.split(' ') | ||
type = tmp_type[tmp_type.size - 1] | ||
html_name = tmp_type.take(tmp_type.size - 1).join(' ') | ||
validate_data(description, author, artist, type, status, genres, release, html_name, alternative_names, rank, rating, rating_max, '//div[@class="cover"]/img') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env ruby | ||
# coding: utf-8 | ||
|
||
require_relative '../sources/../sources/init' | ||
|
||
$0="MangaScrap's mangafox migration" | ||
|
||
def get_mangafox_mangas(db) | ||
db.exec_query('SELECT * FROM manga_list WHERE site=? ORDER BY name COLLATE NOCASE', 'error while getting the manga list', ['http://mangafox.la/']) | ||
end | ||
|
||
def update_mangafox_mangas(db, mangas) | ||
if mangas.size != 0 | ||
puts 'updating + ' + mangas.size.to_s + ' mangas(s)' | ||
i = 1 | ||
mangas.each do |manga| | ||
puts 'updating ' + i.to_s + ' / ' + mangas.size.to_s + ' ' + manga[1] | ||
# update website | ||
# update link | ||
args = ['http://fanfox.net/', manga[4].gsub('mangafox.la', 'fanfox.net'), manga[0]] | ||
if args[1][-1, 1] != '/' | ||
args[1] += '/' | ||
end | ||
db.exec_query('UPDATE manga_list SET site=?, link=? WHERE id=?', | ||
'could not update ' + manga[1], args) | ||
i += 1 | ||
end | ||
puts '' | ||
puts 'done' | ||
else | ||
puts 'nothing to update' | ||
end | ||
end | ||
|
||
begin | ||
Init::initialize_mangascrap | ||
db = Manga_database.instance | ||
mangas = get_mangafox_mangas(db) | ||
update_mangafox_mangas(db, mangas) | ||
rescue Interrupt | ||
puts '' | ||
puts '' | ||
puts 'MangaScrap was interrupted by user'.magenta | ||
puts '' | ||
puts 'backtrace'.yellow + ' is :' | ||
pp $!.backtrace | ||
puts '' | ||
exit 7 | ||
end |