Skip to content
This repository has been archived by the owner on Aug 1, 2019. It is now read-only.

Adds support for manganelo #415

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions application/migrations/data/tracker_sites.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@
"site_class" : "NaniScans",
"status" : "enabled",
"use_custom" : "Y"
},
{
"id" : "69",
"site" : "manganelo.com",
"site_class" : "MangaNelo",
"status" : "enabled",
"use_custom" : "Y"
}
]
}
104 changes: 104 additions & 0 deletions application/models/Tracker/Sites/MangaNelo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');

class MangaNelo extends Base_Site_Model {
public $titleFormat = '/^[a-zA-Z_\-0-9]+$/';
public $chapterFormat = '/^[0-9\.]+$/';

public $customType = 2;

public function getFullTitleURL(string $title_url) : string {
return "https://manganelo.com/manga/{$title_url}/";
}

public function getChapterData(string $title_url, string $chapter) : array {
return [
'url' => "https://manganelo.com/chapter/{$title_url}/chapter_{$chapter}",
'number' => "c{$chapter}"
];
}

public function getTitleData(string $title_url, bool $firstGet = FALSE) : ?array {
$titleData = [];

$fullURL = $this->getFullTitleURL($title_url);
$content = $this->get_content($fullURL);

$data = $this->parseTitleDataDOM(
$content,
$title_url,
"//ul[@class='manga-info-text']/li[1]/h1[1]",
"//div[@class='chapter-list']/div[1]",
'span[3]',
'span[1]/a'
);
if($data) {
$titleData['title'] = html_entity_decode($data['nodes_title']->textContent);

preg_match('/[0-9\.]+$/', (string) $data['nodes_chapter']->getAttribute('href'),$chapter);
$titleData['latest_chapter'] = $chapter[0];

//FIXME: We can't properly use the time provided by the site as they don't include year :|
$titleData['last_updated'] = date('Y-m-d H:i:s', now());
}

return (!empty($titleData) ? $titleData : NULL);
}

public function doCustomUpdate() {
$titleDataList = [];

//FIXME: latest list does not work as no timestamp, use http://manganelo.com/
$updateURL = "http://manganelo.com";
if(($content = $this->get_content($updateURL)) && $content['status_code'] == 200) {
$data = $content['body'];

$dom = new DOMDocument();
libxml_use_internal_errors(TRUE);
$dom->loadHTML($data);
libxml_use_internal_errors(FALSE);

$xpath = new DOMXPath($dom);
$nodes_rows = $xpath->query("//div[@class='doreamon']/div[@class='itemupdate first']/ul");
if($nodes_rows->length > 0) {
foreach($nodes_rows as $row) {
$titleData = [];

$nodes_title = $xpath->query("li[1]/h3/a[1]", $row);
$nodes_chapter = $xpath->query("li[2]/span/a", $row);
$nodes_latest = $xpath->query("li[2]/i", $row);

if($nodes_title->length === 1 && $nodes_chapter->length === 1 && $nodes_latest->length === 1) {
$title = $nodes_title->item(0);

preg_match('/(?<url>[^\/]+(?=\/$|$))/', $title->getAttribute('href'), $title_url_arr);
$title_url = $title_url_arr['url'];

if(!array_key_exists($title_url, $titleDataList)) {
$titleData['title'] = trim($title->textContent);

$chapter = $nodes_chapter->item(0);
preg_match('/(?<chapter>[^\/]+(?=\/$|$))/', $chapter->getAttribute('href'), $chapter_arr);
$titleData['latest_chapter'] = str_replace('chapter_', '', $chapter_arr['chapter']);

$dateString = trim($nodes_latest->item(0)->textContent);
if(strpos($dateString, 'ago') === FALSE) {
$dateString = date('Y-').$dateString;
}
$titleData['last_updated'] = date("Y-m-d H:i:s", strtotime($dateString));

$titleDataList[$title_url] = $titleData;
}
} else {
log_message('error', "{$this->site}/Custom | Invalid amount of nodes (TITLE: {$nodes_title->length} | CHAPTER: {$nodes_chapter->length}) | LATEST: {$nodes_latest->length})");
}
}
} else {
log_message('error', "{$this->site} | Following list is empty?");
}
} else {
log_message('error', "{$this->site} - Custom updating failed.");
}

return $titleDataList;
}
}
24 changes: 24 additions & 0 deletions application/tests/models/Tracker/Sites/MangaNelo_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* @coversDefaultClass MangaNelo
*/
class MangaNelo_test extends SiteTestCase {
public function test_success() {
$testSeries = [
'pn918005' => 'Solo Leveling',
'the_scholars_reincarnation' => 'The Scholar\'s Reincarnation',
'star_martial_god_technique' => 'Star Martial God Technique',
'tomochan_wa_onnanoko' => 'Tomo-chan wa Onnanoko!',
'domestic_na_kanojo' => 'Domestic na Kanojo'
];
$this->_testSiteSuccessRandom($testSeries);
}
public function test_failure() {
$this->_testSiteFailure('Invalid amount of nodes (TITLE: 0)');
}

public function test_custom() {
$this->_testSiteCustom();
}
}
1 change: 1 addition & 0 deletions application/views/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<li>MangaFox</li>
<li>MangaHere</li>
<li>MangaKakalot</li>
<li>MangaNelo</li>
<li>MangaPanda</li>
<li>MangaRock</li>
<li>MangaStream</li>
Expand Down
Binary file added public/assets/img/site_icons/manganelo-com.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading