rss-bridge/bridges/PornhubBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.7 KiB
PHP
Raw Permalink Normal View History

2020-02-15 02:03:29 +03:00
<?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';
2020-02-15 02:03:29 +03:00
const PARAMETERS = [[
'q' => [
'name' => 'User name',
'exampleValue' => 'asa-akira',
2020-02-15 02:03:29 +03:00
'required' => true,
],
'type' => [
'name' => 'User type',
'type' => 'list',
'values' => [
'user' => 'users',
'model' => 'model',
'pornstar' => 'pornstar',
],
'defaultValue' => 'pornstar',
2020-02-15 02:03:29 +03:00
],
'sort' => [
'name' => 'Sort by',
'type' => 'list',
'values' => [
'Most recent' => '?',
2020-02-15 02:03:29 +03:00
'Most views' => '?o=mv',
'Top rated' => '?o=tr',
'Longest' => '?o=lg',
],
'defaultValue' => '?',
2020-02-15 02:03:29 +03:00
],
'show_images' => [
'name' => 'Show thumbnails',
'type' => 'checkbox',
],
]];
2020-02-15 02:03:29 +03:00
public function getName()
{
if (!is_null($this->getInput('type')) && !is_null($this->getInput('q'))) {
return 'PornHub ' . $this->getInput('type') . ':' . $this->getInput('q');
}
2020-02-15 02:03:29 +03:00
return parent::getName();
}
2020-02-15 02:03:29 +03:00
public function collectData()
{
$uri = 'https://www.pornhub.com/' . $this->getInput('type') . '/';
switch ($this->getInput('type')) { // select proper permalink format per user type...
case 'model':
2020-02-15 02:03:29 +03:00
$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;
}
2020-02-15 02:03:29 +03:00
$show_images = $this->getInput('show_images');
2023-07-05 18:06:23 +03:00
$html = getSimpleHTMLDOM($uri, [
'cookie: accessAgeDisclaimerPH=1'
]);
2020-02-15 02:03:29 +03:00
foreach ($html->find('div.videoUList ul.videos li.videoblock') as $element) {
$item = [];
2020-02-15 02:03:29 +03:00
$item['author'] = $this->getInput('q');
2020-02-15 02:03:29 +03:00
// Title
$title = $element->find('a', 0)->getAttribute('title');
if (is_null($title)) {
continue;
}
$item['title'] = $title;
2020-02-15 02:03:29 +03:00
// Url
$url = $element->find('a', 0)->href;
$item['uri'] = 'https://www.pornhub.com' . $url;
2023-09-24 01:03:21 +03:00
// Duration
$marker = $element->find('div.marker-overlays var', 0);
$duration = $marker->innertext ?? '';
2020-02-15 02:03:29 +03:00
// Content
2023-09-24 00:49:01 +03:00
$videoImage = $element->find('img', 0);
$image = $videoImage->getAttribute('data-src') ?: $videoImage->getAttribute('src');
if ($show_images === true) {
2023-09-24 01:03:21 +03:00
$item['content'] = sprintf('<a href="%s"><img src="%s"></a><br>%s', $item['uri'], $image, $duration);
2020-02-15 02:03:29 +03:00
}
2020-02-15 02:03:29 +03:00
$uploaded = explode('/', $image);
if (isset($uploaded[4])) {
// date hack, guess upload YYYYMMDD from thumbnail URL (format: https://ci.phncdn.com/videos/201907/25/--- )
$uploadTimestamp = strtotime($uploaded[4] . $uploaded[5]);
$item['timestamp'] = $uploadTimestamp;
} else {
// The thumbnail url did not have a date in it for some unknown reason
}
2020-02-15 02:03:29 +03:00
$this->items[] = $item;
}
}
}