Completed
Push — master ( 222f63...75778e )
by Angus
02:21
created

GameOfScanlation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
1
<?php declare(strict_types=1); defined('BASEPATH') OR exit('No direct script access allowed');
2
3
class GameOfScanlation extends Base_Site_Model {
4
	public $titleFormat   = '/^[a-z0-9\.-]+$/';
5
	public $chapterFormat = '/^[a-z0-9\.-]+$/';
6
7
	public function getFullTitleURL(string $title_url) : string {
8
		/* NOTE: GoS is a bit weird in that it has two separate title URL formats. One uses /projects/ and the other uses /fourms/.
9
		         The bad thing is these are interchangeable, despite them showing the exact same listing page.
10
		         Thankfully the title_url of manga which use /forums/ seem to be appended with ".%ID%" which means we can easily check them. */
11
12
		if (strpos($title_url, '.') !== FALSE) {
13
			$format = "https://gameofscanlation.moe/forums/{$title_url}/";
14
		} else {
15
			$format = "https://gameofscanlation.moe/projects/{$title_url}/";
16
		}
17
		return $format;
18
	}
19
20
	public function getChapterData(string $title_url, string $chapter) : array {
21
		return [
22
			'url'    => "https://gameofscanlation.moe/projects/".preg_replace("/\\.[0-9]+$/", "", $title_url).'/'.$chapter.'/',
23
			'number' => preg_replace("/chapter-/", "c", preg_replace("/\\.[0-9]+$/", "", $chapter))
24
		];
25
	}
26
27
	public function getTitleData(string $title_url, bool $firstGet = FALSE) : ?array {
28
		$titleData = [];
29
30
		$fullURL = $this->getFullTitleURL($title_url);
31
32
		$content = $this->get_content($fullURL);
33
34
		$data = $this->parseTitleDataDOM(
35
			$content,
36
			$title_url,
37
			"//meta[@property='og:title']",
38
			"//ol[@class='discussionListItems']/li[1]/div[@class='home_list']/ul/li/div[@class='list_press_text']",
39
			"p[@class='author']/span|p[@class='author']/abbr",
40
			"p[@class='text_work']/a"
41
		);
42
		if($data) {
43
			$titleData['title'] = trim(html_entity_decode($data['nodes_title']->getAttribute('content')));
44
45
			$titleData['latest_chapter'] = preg_replace('/^projects\/.*?\/(.*?)\/$/', '$1', (string) $data['nodes_chapter']->getAttribute('href'));
46
47
			$titleData['last_updated'] =  date("Y-m-d H:i:s",(int) $data['nodes_latest']->getAttribute('title'));
48
		}
49
50
		return (!empty($titleData) ? $titleData : NULL);
51
	}
52
}
53