Class: MangaHere

Inherits:
Mangdown::Adapter::Base
  • Object
show all
Defined in:
lib/mangdown/adapters/manga_here.rb

Constant Summary collapse

ROOT =
'http://www.mangahere.cc/'.freeze
CDNS =
[
  'http://l.mhcdn.net/store/manga/',
  'https://mhcdn.secure.footprint.net/store/manga/'
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, doc, name) ⇒ MangaHere

Returns a new instance of MangaHere.



22
23
24
25
26
# File 'lib/mangdown/adapters/manga_here.rb', line 22

def initialize(uri, doc, name)
  super

  @root = ROOT
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/mangdown/adapters/manga_here.rb', line 10

def root
  @root
end

Class Method Details

.cdn_uri?(uri) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/mangdown/adapters/manga_here.rb', line 18

def self.cdn_uri?(uri)
  CDNS.any? { |cdn| uri.to_s.start_with?(cdn) }
end

.for?(uri_or_site) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/mangdown/adapters/manga_here.rb', line 12

def self.for?(uri_or_site)
  uri_or_site.to_s.start_with?(ROOT) ||
    cdn_uri?(uri_or_site) ||
    uri_or_site.to_s == 'manga_here'
end

Instance Method Details

#chapterObject

Return Hash with keys: :uri, :name, :chapter, :manga, :site



79
80
81
82
83
84
85
# File 'lib/mangdown/adapters/manga_here.rb', line 79

def chapter
  name ||= chapter_name
  chapter ||= name.slice(/[\d\.]+$/)
  manga = name.sub(/ #{chapter}\Z/, '').strip

  { uri: uri, name: name, chapter: chapter, manga: manga, site: site }
end

#chapter_listObject

Return Array of Hash with keys: :uri, :name, :site



67
68
69
70
71
72
73
74
75
# File 'lib/mangdown/adapters/manga_here.rb', line 67

def chapter_list
  chapters = doc.css('.manga_detail .detail_list ul').first.css('li a')
  chapters.reverse.map.with_index do |a, i|
    uri = URI.join(root, a[:href]).to_s
    name = a.text.strip

    { uri: uri, name: name, chapter: i + 1, site: site }
  end
end

#hydra_optsObject



28
29
30
# File 'lib/mangdown/adapters/manga_here.rb', line 28

def hydra_opts
  { max_concurrency: 1 }
end

#is_chapter?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a chapter for adapter

Returns:

  • (Boolean)


42
43
44
# File 'lib/mangdown/adapters/manga_here.rb', line 42

def is_chapter?(uri = @uri)
  uri =~ /#{root}.+\/c\d{3}\/?/
end

#is_manga?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a manga for adapter

Returns:

  • (Boolean)


37
38
39
# File 'lib/mangdown/adapters/manga_here.rb', line 37

def is_manga?(uri = @uri)
  uri =~ /#{root}manga\//
end

#is_manga_list?(uri = @uri) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/mangdown/adapters/manga_here.rb', line 32

def is_manga_list?(uri = @uri)
  uri =~ /#{root}mangalist/
end

#is_page?(uri = @uri) ⇒ Boolean

Must return true/false if uri represents a page for adapter

Returns:

  • (Boolean)


47
48
49
# File 'lib/mangdown/adapters/manga_here.rb', line 47

def is_page?(uri = @uri)
  self.class.cdn_uri?(uri)
end

#mangaObject

Return Hash with keys: :uri, :name, :site



60
61
62
63
64
# File 'lib/mangdown/adapters/manga_here.rb', line 60

def manga
  name ||= doc.css('h1.title').first.text.strip

  { uri: uri, name: name, site: site }
end

#manga_listObject

Return Array of Hash with keys: :uri, :name, :site



52
53
54
55
56
57
# File 'lib/mangdown/adapters/manga_here.rb', line 52

def manga_list
  doc.css('.list_manga a.manga_info').map { |a|
    uri = URI.join(root, a[:href]).to_s

    { uri: uri, name: a.text.strip, site: site }}
end

#pageObject

Return Hash with keys: :uri, :name, :site



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/mangdown/adapters/manga_here.rb', line 98

def page
  if name.nil?
    option = doc.css('.wid60 option[selected]').first
    name = "#{chapter_name} - #{option.text.strip.rjust(3, '0')}"
  end

  image = doc.css('.read_img img')[1]
  uri = image[:src]

  { uri: uri, name: name, site: site }
end

#page_listObject

Return Array of Hash with keys: :uri, :name, :site



88
89
90
91
92
93
94
95
# File 'lib/mangdown/adapters/manga_here.rb', line 88

def page_list
  doc.css('.wid60').first.css('option').map do |option|
    uri = URI.join(root, option[:value]).to_s
    name = option.text

    { uri: uri, name: name, site: site }
  end
end