summaryrefslogtreecommitdiff
path: root/bridges/PornhubBridge.php
blob: b8da99a5e4b5766382d7142c0b202c46b291a77f (plain)
1
2
3
4
5
6
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

class PornhubBridge extends BridgeAbstract {

	const MAINTAINER = 'Mitsukarenai';
	const NAME = 'Pornhub';
	const URI = 'https://www.pornhub.com/';
	const CACHE_TIMEOUT = 3600; // 1h
	const DESCRIPTION = 'Returns videos from specified user,model,pornstar';

	const PARAMETERS = array(array(
		'q' => array(
			'name' => 'User name',
			'required' => true,
		),
		'type' => array(
			'name' => 'User type',
			'type' => 'list',
			'values' => array(
				'user' => 'users',
				'model' => 'model',
				'pornstar' => 'pornstar',
			),
			'defaultValue' => 'users',
		),
		'sort' => array(
			'name' => 'Sort by',
			'type' => 'list',
			'values' => array(
				'Most recent' => '?',
				'Most views' => '?o=mv',
				'Top rated' => '?o=tr',
				'Longest' => '?o=lg',
			),
			'defaultValue' => '?',
		),
		'show_images' => array(
			'name' => 'Show thumbnails',
			'type' => 'checkbox',
		),
	));

	public function getName(){
		if(!is_null($this->getInput('type')) && !is_null($this->getInput('q'))) {
			return 'PornHub ' . $this->getInput('type') . ':' . $this->getInput('q');
		}

		return parent::getName();
	}

	public function collectData() {

		$uri = 'https://www.pornhub.com/' . $this->getInput('type') . '/';
		switch($this->getInput('type')) {	// select proper permalink format per user type...
			case 'model':
				$uri .= urlencode($this->getInput('q')) . '/videos' . $this->getInput('sort'); break;
			case 'users':
				$uri .= urlencode($this->getInput('q')) . '/videos/public' . $this->getInput('sort'); break;
			case 'pornstar':
				$uri .= urlencode($this->getInput('q')) . '/videos/upload' . $this->getInput('sort'); break;
		}

		$show_images = $this->getInput('show_images');

		$html = getSimpleHTMLDOM($uri)
			or returnServerError('Could not request PornHub.');

		foreach($html->find('div.videoUList ul.videos li.videoblock') as $element) {

			$item = array();

			$item['author'] = $this->getInput('q');

			// Title
			$title = $element->find('a', 0)->getAttribute('title');
			if (is_null($title)) {
				continue;
			}
			$item['title'] = $title;

			// Url
			$url = $element->find('a', 0)->href;
			$item['uri'] = 'https://www.pornhub.com' . $url;

			// Content
			$image = $element->find('img', 0)->getAttribute('data-src');
			if($show_images === true) {
				$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $image . '"></a>';
			}

			// date hack, guess upload YYYYMMDD from thumbnail URL (format: https://ci.phncdn.com/videos/201907/25/--- )
			$uploaded = explode('/', $image);
			$uploaded = strtotime($uploaded[4] . $uploaded[5]);
			$item['timestamp'] = $uploaded;

			$this->items[] = $item;
		}
	}
}