7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/mrmanga/parser.rb', line 7
def get_manga(link)
parsed = parse_link(link)
noko = Nokogiri::HTML(Faraday.get(link).body)
metadata = {
Title: noko.css('h1.names > .name').first.text,
Author: noko.css('.elem_author > a.person-link').map(&:text).join(', '),
Keywords: noko.css('.elem_genre > a.element-link').map(&:text).join(', ')
}
some_chapter_link = noko.css('.chapters-link a').attr('href').value
some_chapter_link.sub!(/\?mature=.?/, '')
noko_first = Nokogiri::HTML(Faraday.get("http://#{parsed[:site]}#{some_chapter_link}?mature=1").body)
volch_with_orig = noko_first.css('#chapterSelectorSelect > option').map { |el| [el.attr('value'), el.text] }
volch = volch_with_orig.map(&:first)
regex_volch = /^\/[\w]+\/vol(-?\d+)\/(-?\d+).*$/
volch.map! do |vl|
match = regex_volch.match vl
raise "Wrong url: #{vl}" unless match
match.to_a.drop(1).map(&:to_i)
end
volch.reverse!
orig_names = {}
volch.each do |item|
orig_names[item[0]] = {} unless orig_names.key?(item[0])
orig_names[item[0]][item[1]] = volch_with_orig.pop.last
end
manga = Mrmanga::Manga.new
manga.add_original_chapters(orig_names)
manga.add_info(
site: parsed[:site],
name: parsed[:name]
)
manga.add_metadata(metadata)
manga.add_volumes_and_chapters(volch)
manga
end
|