mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
403 lines
9.4 KiB
PHP
Executable File
403 lines
9.4 KiB
PHP
Executable File
<?php
|
|
namespace nntmux;
|
|
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
use GuzzleHttp\Cookie\SetCookie;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
use GuzzleHttp\Client;
|
|
use nntmux\db\DB;
|
|
|
|
class AEBN
|
|
{
|
|
/**
|
|
* Cookie File location used in curl
|
|
*
|
|
* @var string
|
|
*/
|
|
public $cookie = "";
|
|
|
|
/**
|
|
* Keyword to search
|
|
*
|
|
* @var string
|
|
*/
|
|
public $searchTerm = "";
|
|
|
|
/**
|
|
* Url Constants used within this class
|
|
*/
|
|
const AEBNGURL = 'http://gay.theater.aebn.net';
|
|
const AEBNSURL = 'http://straight.theater.aebn.net';
|
|
const IF18 = 'http://straight.theater.aebn.net/dispatcher/frontDoor?genreId=101&theaterId=13992&locale=en&refid=AEBN-000001';
|
|
const TRAILINGSEARCH = '/dispatcher/fts?theaterId=13992&genreId=101&locale=en&count=30&imageType=Large&targetSearchMode=basic&isAdvancedSearch=false&isFlushAdvancedSearchCriteria=false&sortType=Relevance&userQuery=title%3A+%2B';
|
|
const TRAILERURL = '/dispatcher/previewPlayer?locale=en&theaterId=13992&genreId=101&movieId=';
|
|
|
|
/**
|
|
* Sets the current site to search
|
|
* @var string
|
|
*/
|
|
protected $_currentSite = 'straight';
|
|
|
|
/**
|
|
* Direct Url in getAll method
|
|
* @var string
|
|
*/
|
|
protected $_directUrl = '';
|
|
|
|
/**
|
|
* Simple Html Dom Object
|
|
* @var \simple_html_dom
|
|
*/
|
|
protected $_html;
|
|
|
|
/**
|
|
* @var Client
|
|
*/
|
|
protected $client;
|
|
|
|
/**
|
|
* @var DB
|
|
*/
|
|
protected $pdo;
|
|
|
|
/**
|
|
* Post Parameters to use with curl
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $_postParams = [];
|
|
|
|
/**
|
|
* Raw Html response from curl
|
|
*
|
|
*/
|
|
protected $_response;
|
|
|
|
/**
|
|
* Returned results in all methods except search/geturl
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $_res = [
|
|
'backcover' => [],
|
|
'boxcover' => [],
|
|
'cast' => [],
|
|
'director' => [],
|
|
'genres' => [],
|
|
'productinfo' => [],
|
|
'synopsis' => [],
|
|
'trailers' => ['url' =>[]],
|
|
];
|
|
|
|
/**
|
|
* If searchTerm is found
|
|
* @var bool
|
|
*/
|
|
protected $_searchFound = false;
|
|
|
|
/**
|
|
* Sets title in getAll method
|
|
* @var string
|
|
*/
|
|
protected $_title = '';
|
|
|
|
/**
|
|
* Trailing Url
|
|
* @var string
|
|
*/
|
|
protected $_trailUrl = '';
|
|
|
|
/**
|
|
* Used in __construct
|
|
* @var array - straight, gay
|
|
*/
|
|
protected $_whichSite = [];
|
|
|
|
|
|
|
|
/**
|
|
* Sets the variables that used throughout the class
|
|
*
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->_whichSite = ['straight' => self::AEBNSURL, 'gay' => self::AEBNGURL];
|
|
$this->_html = new \simple_html_dom();
|
|
$this->client = new Client();
|
|
$this->cookiejar = new CookieJar();
|
|
$this->pdo = new DB();
|
|
if (!empty($this->cookie)) {
|
|
$cookieJar = $this->cookiejar->setCookie(SetCookie::fromString($this->cookie));
|
|
$this->client = new Client(['cookies' => $cookieJar]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* If they arent' removed from memory. Force them.
|
|
*/
|
|
public function __destruct()
|
|
{
|
|
$this->_html->clear();
|
|
unset($this->_response, $this->_res);
|
|
}
|
|
|
|
/**
|
|
* Gets Trailer URL .. will be processed in XXX insertswf
|
|
*
|
|
* @return array|bool
|
|
*/
|
|
public function trailers()
|
|
{
|
|
$ret = $this->_html->find('a[itemprop=trailer]', 0);
|
|
if (preg_match('/movieId=(?<movieid>\d+)&/', trim($ret->href), $matches)) {
|
|
$movieid = $matches['movieid'];
|
|
$this->_res['trailers']['url'] = $this->_whichSite[$this->_currentSite] . self::TRAILERURL . $movieid;
|
|
}
|
|
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Gets the front and back cover of the box
|
|
*
|
|
* @return array
|
|
*/
|
|
public function covers()
|
|
{
|
|
if ($ret = $this->_html->find('div#md-boxCover, img[itemprop=thumbnailUrl]', 1)) {
|
|
$ret = trim($ret->src);
|
|
if (strpos($ret, '//') === 0) {
|
|
$ret = 'http:' . $ret;
|
|
}
|
|
$this->_res['boxcover'] = str_ireplace('160w.jpg', 'xlf.jpg', $ret);
|
|
$this->_res['backcover'] = str_ireplace('160w.jpg', 'xlb.jpg', $ret);
|
|
}
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Gets the Genres "Categories".
|
|
*
|
|
* @return array
|
|
*/
|
|
public function genres()
|
|
{
|
|
if ($ret = $this->_html->find('div.md-detailsCategories', 0)) {
|
|
foreach ($ret->find('a[itemprop=genre]') as $genre) {
|
|
$this->_res['genres'][] = trim($genre->plaintext);
|
|
}
|
|
}
|
|
$this->_res['genres'] = array_unique($this->_res['genres']);
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Gets the Cast Members "Stars" and Director if any
|
|
*
|
|
* @return array
|
|
*/
|
|
public function cast()
|
|
{
|
|
if ($ret = $this->_html->find('div.starsFull', 0)) {
|
|
foreach ($ret->find('span[itemprop=name]') as $star) {
|
|
$this->_res['cast'][] = trim($star->plaintext);
|
|
}
|
|
} else {
|
|
if ($ret = $this->_html->find('div.detailsLink', 0)) {
|
|
foreach ($ret->find('span') as $star) {
|
|
if (strpos($star->plaintext, '/More/') !== false && strpos($star->plaintext, '/Stars/') !== false) {
|
|
$this->_res['cast'][] = trim($star->plaintext);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Gets the product information
|
|
*
|
|
* @return array
|
|
*/
|
|
public function productInfo()
|
|
{
|
|
if ($ret = $this->_html->find('div#md-detailsLeft', 0)) {
|
|
foreach ($ret->find('div') as $div) {
|
|
foreach ($div->find('span') as $span) {
|
|
$span->plaintext = rawurldecode($span->plaintext);
|
|
$span->plaintext = preg_replace('/ /', '', $span->plaintext);
|
|
$this->_res['productinfo'][] = trim($span->plaintext);
|
|
}
|
|
}
|
|
if (false !== $key = array_search('Running Time:', $this->_res['productinfo'])) {
|
|
unset($this->_res['productinfo'][$key + 2]);
|
|
}
|
|
if (false !== $key = array_search("Director:", $this->_res['productinfo'])) {
|
|
$this->_res['director'] = $this->_res['productinfo'][$key + 1];
|
|
unset($this->_res['productinfo'][$key], $this->_res['productinfo'][$key + 1]);
|
|
}
|
|
$this->_res['productinfo'] = array_chunk($this->_res['productinfo'], 2, false);
|
|
}
|
|
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Gets the synopsis "plot"
|
|
*
|
|
* @return array
|
|
*
|
|
*/
|
|
public function synopsis()
|
|
{
|
|
if ($ret = $this->_html->find('span[itemprop=about]', 0)) {
|
|
if ($ret === null) {
|
|
if ($ret = $this->_html->find('div.movieDetailDescription', 0)) {
|
|
$this->_res['synopsis'] = trim($ret->plaintext);
|
|
$this->_res['synopsis'] = preg_replace('/Description:\s/', "", $this->_res['plot']);
|
|
}
|
|
} else {
|
|
$this->_res['synopsis'] = trim($ret->plaintext);
|
|
}
|
|
}
|
|
|
|
return $this->_res;
|
|
}
|
|
|
|
/**
|
|
* Searches for a XXX name
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function search()
|
|
{
|
|
if (empty($this->searchTerm)) {
|
|
return false;
|
|
}
|
|
$this->_trailUrl = self::TRAILINGSEARCH . urlencode($this->searchTerm);
|
|
if ($this->getUrl($this->_currentSite) === false) {
|
|
return false;
|
|
} else {
|
|
if ($count = count($this->_html->find('div.movie'))) {
|
|
$i = 1;
|
|
foreach ($this->_html->find('div.movie') as $movie) {
|
|
$string = 'a#FTSMovieSearch_link_title_detail_' . $i;
|
|
if ($ret = $movie->find($string, 0)) {
|
|
$title = str_replace('/XXX/', '', $ret->title);
|
|
$title = preg_replace('/\(.*?\)|[-._]/', ' ', $title);
|
|
$title = trim($title);
|
|
similar_text(strtolower($this->searchTerm), strtolower($title), $p);
|
|
if ($p >= 90) {
|
|
$this->_title = trim($ret->title);
|
|
$this->_trailUrl = html_entity_decode($ret->href);
|
|
$this->_directUrl = $this->_whichSite[$this->_currentSite] . $this->_trailUrl;
|
|
$this->getUrl($this->_currentSite);
|
|
return true;
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
$i++;
|
|
}
|
|
if ($i === $count || $count === 0) {
|
|
if ($this->_currentSite === 'gay') {
|
|
return false;
|
|
}
|
|
$this->_currentSite = 'gay';
|
|
$this->search();
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Gets all the information
|
|
*
|
|
* @return array|bool
|
|
*/
|
|
public function getAll()
|
|
{
|
|
$results = [];
|
|
if (!empty($this->_directUrl)) {
|
|
$results['title'] = $this->_title;
|
|
$results['directurl'] = $this->_directUrl;
|
|
}
|
|
if (is_array($this->synopsis())) {
|
|
$results = array_merge($results, $this->synopsis());
|
|
}
|
|
if (is_array($this->productInfo())) {
|
|
$results = array_merge($results, $this->productInfo());
|
|
}
|
|
if (is_array($this->cast())) {
|
|
$results = array_merge($results, $this->cast());
|
|
}
|
|
if (is_array($this->genres())) {
|
|
$results = array_merge($results, $this->genres());
|
|
}
|
|
$covers = $this->covers();
|
|
if (is_array($covers)) {
|
|
$results = array_merge($results, $covers);
|
|
}
|
|
if (is_array($this->trailers())) {
|
|
$results = array_merge($results, $this->trailers());
|
|
}
|
|
if (empty($results) === true) {
|
|
return false;
|
|
} else {
|
|
return $results;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get Raw html of webpage
|
|
*
|
|
* @param string $site
|
|
*
|
|
* @return bool
|
|
*/
|
|
private function getUrl($site = 'straight')
|
|
{
|
|
if (!empty($this->_trailUrl)) {
|
|
try {
|
|
$this->_response = $this->client->get($this->_whichSite[$site] . $this->_trailUrl)->getBody()->getContents();
|
|
} catch (RequestException $e) {
|
|
if ($e->hasResponse()) {
|
|
if($e->getCode() === 404) {
|
|
ColorCLI::doEcho(ColorCLI::notice('Data not available on server'));
|
|
} else if ($e->getCode() === 503) {
|
|
ColorCLI::doEcho(ColorCLI::notice('Service unavailable'));
|
|
} else {
|
|
ColorCLI::doEcho(ColorCLI::notice('Unable to fetch data, http error reported: ' . $e->getCode()));
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
try {
|
|
$this->_response = $this->client->get(self::IF18)->getBody()->getContents();
|
|
} catch (RequestException $e) {
|
|
if ($e->hasResponse()) {
|
|
if($e->getCode() === 404) {
|
|
ColorCLI::doEcho(ColorCLI::notice('Data not available on server'));
|
|
} else if ($e->getCode() === 503) {
|
|
ColorCLI::doEcho(ColorCLI::notice('Service unavailable'));
|
|
} else {
|
|
ColorCLI::doEcho(ColorCLI::notice('Unable to fetch data, http error reported: ' . $e->getCode()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$this->_response) {
|
|
return false;
|
|
}
|
|
|
|
$this->_html->load($this->_response);
|
|
return true;
|
|
}
|
|
}
|