mirror of
https://github.com/Rogiel/predb
synced 2025-12-05 23:22:48 +00:00
Compare commits
4 Commits
release/1.
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 58e8596cce | |||
| 1291322567 | |||
| d8a338d345 | |||
| 68cf6fc064 |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<buildpath>
|
|
||||||
<buildpathentry kind="src" path=""/>
|
|
||||||
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
|
|
||||||
</buildpath>
|
|
||||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.settings/
|
||||||
|
.buildpath
|
||||||
|
.project
|
||||||
22
.project
22
.project
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<projectDescription>
|
|
||||||
<name>lib-predb</name>
|
|
||||||
<comment></comment>
|
|
||||||
<projects>
|
|
||||||
</projects>
|
|
||||||
<buildSpec>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
<buildCommand>
|
|
||||||
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
|
||||||
<arguments>
|
|
||||||
</arguments>
|
|
||||||
</buildCommand>
|
|
||||||
</buildSpec>
|
|
||||||
<natures>
|
|
||||||
<nature>org.eclipse.php.core.PHPNature</nature>
|
|
||||||
</natures>
|
|
||||||
</projectDescription>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#Sat Oct 01 19:11:06 BRT 2011
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
include_path=0;/lib-predb
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapter implementation for http://orlydb.com/
|
|
||||||
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Pre_Orlydb_Adapter implements Pre_Adapter {
|
|
||||||
public function latest() {
|
|
||||||
$html = file_get_contents("http://orlydb.com/1");
|
|
||||||
return $this->parseList($html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function search($release) {
|
|
||||||
$html = file_get_contents("http://orlydb.com/?q=" . urlencode($release));
|
|
||||||
return $this->parseList($html);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function parseList($html) {
|
|
||||||
$dom = new DomDocument();
|
|
||||||
$result = @$dom->loadHTML($html); //ignore parse errors
|
|
||||||
$xpath = new DomXPath($dom);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
while (true) {
|
|
||||||
$i ++;
|
|
||||||
$node = $xpath->query("/html/body/div/div[2]/div[" . $i . "]/span");
|
|
||||||
if ($node->length == 0)
|
|
||||||
break;
|
|
||||||
$pres[] = $this->parseRelease($node);
|
|
||||||
}
|
|
||||||
return $pres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DOMNodeList $node
|
|
||||||
*/
|
|
||||||
private function parseRelease($node) {
|
|
||||||
$extra = $node->item(3)->nodeValue;
|
|
||||||
if (strlen($extra)) {
|
|
||||||
list ($size, $files) = explode("|", $extra);
|
|
||||||
$size = trim($size);
|
|
||||||
$files = trim($files);
|
|
||||||
}
|
|
||||||
$entry = new Pre_Release();
|
|
||||||
$entry->release = $node->item(2)->nodeValue;
|
|
||||||
$entry->type = $node->item(1)->nodeValue;
|
|
||||||
$entry->date = strtotime($node->item(0)->nodeValue);
|
|
||||||
$entry->size = (intval($size)) * 1024 * 1024; //as bytes
|
|
||||||
$entry->files = intval($files);
|
|
||||||
$entry->nuke = $node->item(4)->nodeValue;
|
|
||||||
|
|
||||||
return $entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adapter implementation for http://pre.scnsrc.net/
|
|
||||||
* @author Rogiel
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Pre_ScnSrc_Adapter implements Pre_Adapter {
|
|
||||||
public function latest() {
|
|
||||||
$html = file_get_contents("http://pre.scnsrc.net/index.php");
|
|
||||||
return $this->parseList($html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function search($release) {
|
|
||||||
$html = $this->download(
|
|
||||||
"http://pre.corrupt-net.org/search.php?search=" . $release);
|
|
||||||
return $this->parseList($html);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function parseList($html) {
|
|
||||||
|
|
||||||
$dom = new DomDocument();
|
|
||||||
$result = @$dom->loadHTML($html); //ignore parse errors
|
|
||||||
$xpath = new DomXPath($dom);
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
while (true) {
|
|
||||||
$i ++;
|
|
||||||
///html/body/table/tbody/tr[3]
|
|
||||||
$node = $xpath->query(
|
|
||||||
"/html/body/table/tr[" . $i . "]/td");
|
|
||||||
if ($node->length == 0) {
|
|
||||||
//die("empty!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$pres[] = &$this->parseRelease($node);
|
|
||||||
}
|
|
||||||
return $pres;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param DOMNodeList $node
|
|
||||||
*/
|
|
||||||
private function parseRelease($node) {
|
|
||||||
// $extra = $node->item(3)->nodeValue;
|
|
||||||
// if (strlen($extra)) {
|
|
||||||
// list ($size, $files) = explode("|", $extra);
|
|
||||||
// $size = trim($size);
|
|
||||||
// $files = trim($files);
|
|
||||||
// }
|
|
||||||
$entry = &new Pre_Release();
|
|
||||||
$entry->release = $node->item(1)->nodeValue;
|
|
||||||
$entry->type = $node->item(0)->nodeValue;
|
|
||||||
if ($node->length == 3) {
|
|
||||||
$entry->date = strtotime(substr($node->item(2)->nodeValue, 4)) +
|
|
||||||
$vbulletin->options['release_time_offset'];
|
|
||||||
} else {
|
|
||||||
$entry->size = (intval($node->item(2)->nodeValue)) * 1024 *
|
|
||||||
1024; //as bytes
|
|
||||||
$entry->files = intval($files);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function download($url) {
|
|
||||||
$options = array(
|
|
||||||
CURLOPT_RETURNTRANSFER => true, // return web page
|
|
||||||
CURLOPT_HEADER => false, // don't return headers
|
|
||||||
CURLOPT_FOLLOWLOCATION => true, // follow redirects
|
|
||||||
CURLOPT_HEADER => array(
|
|
||||||
'Host: pre.corrupt-net.org',
|
|
||||||
//'Accept: text/html,application/xhtml+xml,application/xml;q=0.9;q=0.8',
|
|
||||||
'User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15',
|
|
||||||
'Accept-Language: en-us,en;q=0.5',
|
|
||||||
'Accept-Encoding: gzip,deflate',
|
|
||||||
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
|
|
||||||
'Keep-Alive: 115',
|
|
||||||
'Connection: keep-alive',
|
|
||||||
'Cache-Control: max-age=0'),
|
|
||||||
//CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110303 Ubuntu/10.10 (maverick) Firefox/3.6.15", // who am i
|
|
||||||
//CURLOPT_AUTOREFERER => true, // set referer on redirect
|
|
||||||
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
|
|
||||||
CURLOPT_TIMEOUT => 120, // timeout on response
|
|
||||||
CURLOPT_MAXREDIRS => 10); // stop after 10 redirects
|
|
||||||
|
|
||||||
|
|
||||||
$ch = curl_init($url);
|
|
||||||
curl_setopt_array($ch, $options);
|
|
||||||
$content = curl_exec($ch);
|
|
||||||
$err = curl_errno($ch);
|
|
||||||
$errmsg = curl_error($ch);
|
|
||||||
$header = curl_getinfo($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
$header['errno'] = $err;
|
|
||||||
$header['errmsg'] = $errmsg;
|
|
||||||
$header['content'] = $content;
|
|
||||||
|
|
||||||
print_r($header);
|
|
||||||
die();
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This example does a simple search for an pre release
|
|
||||||
|
|
||||||
require_once '../PreDatabase_Library.php';
|
|
||||||
require_once '../Adapter/Pre_ScnSrc_Adapter.php';
|
|
||||||
|
|
||||||
$db = new Pre_DB(new Pre_ScnSrc_Adapter());
|
|
||||||
print_r($db->search("Microsoft Windows"));
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This example does a simple search for an pre release
|
|
||||||
|
|
||||||
require_once '../PreDatabase_Library.php';
|
|
||||||
|
|
||||||
$db = new Pre_DB();
|
|
||||||
print_r($db->search("Microsoft Windows"));
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// This example used the Pre_TVShow_SearchHelper to search an given
|
|
||||||
// episode of an TVShow. It can be used to filter data returned.
|
|
||||||
|
|
||||||
require_once '../PreDatabase_Library.php';
|
|
||||||
|
|
||||||
$db = new Pre_DB();
|
|
||||||
|
|
||||||
// Show: True Blood
|
|
||||||
// Season: 4
|
|
||||||
// Episode 1
|
|
||||||
print_r($db->search(new Pre_TVShow_SearchHelper(
|
|
||||||
"true blood", // the tv show name
|
|
||||||
4, // the season
|
|
||||||
1 // the episode
|
|
||||||
)));
|
|
||||||
|
|
||||||
?>
|
|
||||||
29
LICENSE.md
Normal file
29
LICENSE.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
Simplified BSD License
|
||||||
|
======================
|
||||||
|
|
||||||
|
Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
The views and conclusions contained in the software and documentation are those
|
||||||
|
of the authors and should not be interpreted as representing official policies,
|
||||||
|
either expressed or implied, of the copyright holders.
|
||||||
@@ -1,284 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of predb <gitgub.com/Rogiel/predb>.
|
|
||||||
*
|
|
||||||
* predb is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* predb is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with predb. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pre database communication class. All operations are performed trough this class.
|
|
||||||
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Pre_DB {
|
|
||||||
/**
|
|
||||||
* The Pre_Adapter implementation
|
|
||||||
* @var Pre_Adapter
|
|
||||||
*/
|
|
||||||
private $adapter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new instance
|
|
||||||
* @param Pre_Adapter $adapter the adapter to use. If none is provided an default is used.
|
|
||||||
*/
|
|
||||||
public function __construct($adapter = null) {
|
|
||||||
if ($adapter == null) {
|
|
||||||
require_once 'Adapter/Pre_Orlydb_Adapter.php';
|
|
||||||
$adapter = new Pre_Orlydb_Adapter();
|
|
||||||
}
|
|
||||||
$this->adapter = $adapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the pre database for certain releases
|
|
||||||
* @param string, Pre_SearchHelper $query the query
|
|
||||||
*/
|
|
||||||
public function search($query) {
|
|
||||||
if ($query instanceof Pre_SearchHelper) {
|
|
||||||
$query = $query->getSearchQuery();
|
|
||||||
}
|
|
||||||
return $this->adapter->search($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Searches the pre database for an certain release
|
|
||||||
* @param string $release the release name
|
|
||||||
* @return Pre_Release
|
|
||||||
*/
|
|
||||||
public function get($release) {
|
|
||||||
$releases = $this->adapter->search($release);
|
|
||||||
return predb_find_suitable_release($release, $releases);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the latest pre entries from the database
|
|
||||||
*/
|
|
||||||
public function latest() {
|
|
||||||
return $this->adapter->latest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pre entry
|
|
||||||
* @author @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Pre_Release {
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $release;
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $type;
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
var $date;
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
var $size;
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
var $files;
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $nuke;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $release
|
|
||||||
*/
|
|
||||||
public function getRelease() {
|
|
||||||
return $this->release;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $date
|
|
||||||
*/
|
|
||||||
public function getDate() {
|
|
||||||
return $this->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $size
|
|
||||||
*/
|
|
||||||
public function getSize() {
|
|
||||||
return $this->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $files
|
|
||||||
*/
|
|
||||||
public function getFiles() {
|
|
||||||
return $this->files;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $nuke
|
|
||||||
*/
|
|
||||||
public function getNuke() {
|
|
||||||
return $this->nuke;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $release
|
|
||||||
*/
|
|
||||||
public function setRelease($release) {
|
|
||||||
$this->release = $release;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $date
|
|
||||||
*/
|
|
||||||
public function setDate($date) {
|
|
||||||
$this->date = $date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $size
|
|
||||||
*/
|
|
||||||
public function setSize($size) {
|
|
||||||
$this->size = $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $files
|
|
||||||
*/
|
|
||||||
public function setFiles($files) {
|
|
||||||
$this->files = $files;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $nuke
|
|
||||||
*/
|
|
||||||
public function setNuke($nuke) {
|
|
||||||
$this->nuke = $nuke;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an search helper. It assists the creation of queries that will be used to find an given release.
|
|
||||||
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
interface Pre_SearchHelper {
|
|
||||||
function getSearchQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This Pre_SearchHelper asists searching for TVShow releases
|
|
||||||
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
class Pre_TVShow_SearchHelper implements Pre_SearchHelper {
|
|
||||||
private $name;
|
|
||||||
private $season = null;
|
|
||||||
private $episode = null;
|
|
||||||
|
|
||||||
public function __construct($name, $season = null, $episode = null) {
|
|
||||||
$this->name = $name;
|
|
||||||
$this->season = $season;
|
|
||||||
$this->episode = $episode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSearchQuery() {
|
|
||||||
$query = $this->name;
|
|
||||||
if ($this->season != null) {
|
|
||||||
$query .= " S" . predb_padding_zero($this->season);
|
|
||||||
if ($this->episode != null)
|
|
||||||
$query .= "E" . predb_padding_zero($this->episode);
|
|
||||||
}
|
|
||||||
return str_replace(" ", ".", $query);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $name
|
|
||||||
*/
|
|
||||||
public function getName() {
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $name
|
|
||||||
* @return Pre_TVShow_SearchHelper this instance
|
|
||||||
*/
|
|
||||||
public function setName($name) {
|
|
||||||
$this->name = $name;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $season
|
|
||||||
*/
|
|
||||||
public function getSeason() {
|
|
||||||
return $this->season;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $season
|
|
||||||
* @return Pre_TVShow_SearchHelper this instance
|
|
||||||
*/
|
|
||||||
public function setSeason($season) {
|
|
||||||
$this->season = $season;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the $episode
|
|
||||||
*/
|
|
||||||
public function getEpisode() {
|
|
||||||
return $this->episode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $episode
|
|
||||||
* @return Pre_TVShow_SearchHelper this instance
|
|
||||||
*/
|
|
||||||
public function setEpisode($episode) {
|
|
||||||
$this->episode = $episode;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pre adapter interface
|
|
||||||
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
|
||||||
interface Pre_Adapter {
|
|
||||||
/**
|
|
||||||
* Implements the underlying search method
|
|
||||||
* @param string $release
|
|
||||||
*/
|
|
||||||
function search($release);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements the underlying latest method
|
|
||||||
*/
|
|
||||||
function latest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $number
|
|
||||||
* @return the number with padded zeros
|
|
||||||
*/
|
|
||||||
function predb_padding_zero($number) {
|
|
||||||
if ($number < 10)
|
|
||||||
return "0" . $number;
|
|
||||||
return $number;
|
|
||||||
}
|
|
||||||
60
README.md
Normal file
60
README.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# PreDB - Scene Releases Database API
|
||||||
|
|
||||||
|
PreDB is a PHP library that allows and makes easy to retrieve scene releases data from online services. Services are plugabble and can be implemented with only two methods!
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
### Getting the latest releases
|
||||||
|
|
||||||
|
In this example we will be retrieving the latest releases that are available on the source.
|
||||||
|
|
||||||
|
```php
|
||||||
|
// configures the autoloader
|
||||||
|
require_once __DIR__ . '/PreDB/autoload.php';
|
||||||
|
|
||||||
|
// imports the PreDB class
|
||||||
|
use PreDB\PreDB;
|
||||||
|
|
||||||
|
// creates a new database instance
|
||||||
|
$db = new PreDB();
|
||||||
|
|
||||||
|
// queries the adapter for the latest releases
|
||||||
|
$result = $db->latest();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Searching for a release
|
||||||
|
|
||||||
|
In this example we perform a search for a given release. You can search for any query and the adapter will try to locate it on the remote service.
|
||||||
|
|
||||||
|
**Important**: Setup steps were ommited!
|
||||||
|
|
||||||
|
```php
|
||||||
|
// queries the adapter for the latest releases
|
||||||
|
$result = $db->search('Microsoft Office');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Get an specific release by name
|
||||||
|
In case you already know the release name, but want to retrieve more data about a given release, you can get an specific release like this:
|
||||||
|
|
||||||
|
**Important**: Setup steps were ommited!
|
||||||
|
|
||||||
|
```php
|
||||||
|
// queries the adapter for the latest releases
|
||||||
|
$result = $db->get('My.Awesome.Release-AWESOME'); // is an instanceo of \PreDB\Release
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using search helpers
|
||||||
|
Search helper can be useful when you want to search standardized data, like TV shows. Currently, only the TVShow search helper is available, but more could be created very easily.
|
||||||
|
|
||||||
|
**Important**: Setup steps were ommited!
|
||||||
|
|
||||||
|
```php
|
||||||
|
use PreDB\Search\TVShow as TVShowHelper;
|
||||||
|
|
||||||
|
$result = $db->search(new TVShowHelper(
|
||||||
|
"true blood", // the tv show name
|
||||||
|
4, // the season
|
||||||
|
1 // the episode
|
||||||
|
));
|
||||||
|
```
|
||||||
|
|
||||||
|
Since a single episode can have several releases, an array is returned.
|
||||||
62
autoload.php
Normal file
62
autoload.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
spl_autoload_register(
|
||||||
|
function ($class) {
|
||||||
|
// the package namespace
|
||||||
|
$ns = 'PreDB';
|
||||||
|
|
||||||
|
// what prefixes should be recognized?
|
||||||
|
$prefixes = array(
|
||||||
|
"{$ns}\\" => array(
|
||||||
|
__DIR__ . '/src'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// go through the prefixes
|
||||||
|
foreach ($prefixes as $prefix => $dirs) {
|
||||||
|
// does the requested class match the namespace prefix?
|
||||||
|
$prefix_len = strlen($prefix);
|
||||||
|
if (substr($class, 0, $prefix_len) !== $prefix) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip the prefix off the class
|
||||||
|
$class = substr($class, $prefix_len);
|
||||||
|
|
||||||
|
// a partial filename
|
||||||
|
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
|
||||||
|
|
||||||
|
// go through the directories to find classes
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
||||||
|
$file = $dir . DIRECTORY_SEPARATOR . $part;
|
||||||
|
if (is_readable($file)) {
|
||||||
|
require $file;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
65
examples/AlternativeAdapter.php
Normal file
65
examples/AlternativeAdapter.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Example;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../autoload.php';
|
||||||
|
|
||||||
|
use PreDB\PreDB;
|
||||||
|
use PreDB\Release;
|
||||||
|
|
||||||
|
// This example does a simple search for an pre release
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements a custom adpater
|
||||||
|
*/
|
||||||
|
class MyCustomAdapter implements \PreDB\Adapter\Adapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the underlying search method
|
||||||
|
*
|
||||||
|
* @param string $release
|
||||||
|
*/
|
||||||
|
function search($release) {
|
||||||
|
return NULL; // no search allowed
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the underlying latest method
|
||||||
|
*/
|
||||||
|
function latest() {
|
||||||
|
return [
|
||||||
|
new Release([
|
||||||
|
'release' => 'My.Awesome.Release-AWESOME',
|
||||||
|
'size' => 1 * 1024
|
||||||
|
])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = new PreDB(new MyCustomAdapter());
|
||||||
|
print_r($db->latest());
|
||||||
|
?>
|
||||||
39
examples/SimpleSearch.php
Normal file
39
examples/SimpleSearch.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Example;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../autoload.php';
|
||||||
|
|
||||||
|
use PreDB\PreDB;
|
||||||
|
|
||||||
|
// This example does a simple search for an pre release
|
||||||
|
$db = new PreDB();
|
||||||
|
|
||||||
|
$result = $db->search("Microsoft Windows");
|
||||||
|
var_dump($result);
|
||||||
|
|
||||||
|
?>
|
||||||
47
examples/TVShowSearchHelper.php
Normal file
47
examples/TVShowSearchHelper.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This example used the PreDB\Search\TVShow to search an given
|
||||||
|
// episode of an TVShow. It can be used to filter data returned.
|
||||||
|
|
||||||
|
namespace PreDB\Example;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../autoload.php';
|
||||||
|
use PreDB\PreDB;
|
||||||
|
use PreDB\Search\TVShow as TVShowHelper;
|
||||||
|
|
||||||
|
$db = new PreDB();
|
||||||
|
|
||||||
|
// Show: True Blood
|
||||||
|
// Season: 4
|
||||||
|
// Episode 1
|
||||||
|
print_r($db->search(new TVShowHelper(
|
||||||
|
"true blood", // the tv show name
|
||||||
|
4, // the season
|
||||||
|
1 // the episode
|
||||||
|
)));
|
||||||
|
|
||||||
|
?>
|
||||||
52
src/Adapter/Adapter.php
Normal file
52
src/Adapter/Adapter.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Adapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pre adapter interface
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
interface Adapter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the underlying search method
|
||||||
|
*
|
||||||
|
* @param string $release
|
||||||
|
* @param int $page
|
||||||
|
* the page to return
|
||||||
|
*/
|
||||||
|
function search($release, $page = 1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the underlying latest method
|
||||||
|
*
|
||||||
|
* @param int $page
|
||||||
|
* the page to load
|
||||||
|
*/
|
||||||
|
function latest($page = 1);
|
||||||
|
}
|
||||||
93
src/Adapter/OrlyDB.php
Normal file
93
src/Adapter/OrlyDB.php
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Adapter;
|
||||||
|
|
||||||
|
use PreDB\Release;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
use DateTime;
|
||||||
|
use DateTimeZone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapter implementation for http://orlydb.com/
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
||||||
|
* @since 1.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class OrlyDB implements Adapter {
|
||||||
|
|
||||||
|
public function latest($page = 1) {
|
||||||
|
$html = file_get_contents("http://orlydb.com/" . $page);
|
||||||
|
return $this->parseList($html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search($release, $page = 1) {
|
||||||
|
$html = file_get_contents("http://orlydb.com/{$page}?q=" . urlencode($release));
|
||||||
|
return $this->parseList($html);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseList($html) {
|
||||||
|
$dom = new DOMDocument();
|
||||||
|
@$dom->loadHTML($html); // ignore parse errors
|
||||||
|
$xpath = new DOMXPath($dom);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
$pres = array();
|
||||||
|
while (true) {
|
||||||
|
$i ++;
|
||||||
|
$node = $xpath->query("/html/body/div/div[2]/div[" . $i . "]/span");
|
||||||
|
if ($node->length == 0)
|
||||||
|
break;
|
||||||
|
$pres[] = $this->parseRelease($node);
|
||||||
|
}
|
||||||
|
return $pres;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param DOMNodeList $node
|
||||||
|
*/
|
||||||
|
private function parseRelease($node) {
|
||||||
|
$extra = $node->item(3)->nodeValue;
|
||||||
|
if (strlen($extra)) {
|
||||||
|
list ($size, $files) = explode("|", $extra);
|
||||||
|
$size = trim($size);
|
||||||
|
$files = trim($files);
|
||||||
|
}
|
||||||
|
$entry = new Release();
|
||||||
|
$entry->release = $node->item(2)->nodeValue;
|
||||||
|
$entry->type = $node->item(1)->nodeValue;
|
||||||
|
$entry->date = new DateTime($node->item(0)->nodeValue, new DateTimeZone('UTC'));
|
||||||
|
$entry->size = (intval($size)) * 1024 * 1024; // as bytes
|
||||||
|
$entry->files = intval($files);
|
||||||
|
$entry->nuke = $node->item(4)->nodeValue;
|
||||||
|
|
||||||
|
return $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
88
src/PreDB.php
Normal file
88
src/PreDB.php
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB;
|
||||||
|
|
||||||
|
use PreDB\Adapter\Adapter;
|
||||||
|
use PreDB\Search\Helper as SearchHelper;
|
||||||
|
|
||||||
|
class PreDB {
|
||||||
|
/**
|
||||||
|
* The Pre_Adapter implementation
|
||||||
|
*
|
||||||
|
* @var Adapter
|
||||||
|
*/
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param Adapter $adapter
|
||||||
|
* the adapter to use. If none is provided an default is used.
|
||||||
|
*/
|
||||||
|
public function __construct(Adapter $adapter = null) {
|
||||||
|
if ($adapter == null) {
|
||||||
|
$adapter = new \PreDB\Adapter\OrlyDB();
|
||||||
|
}
|
||||||
|
$this->adapter = $adapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the pre database for certain releases
|
||||||
|
*
|
||||||
|
* @param string|SearchHelper $query
|
||||||
|
* the query
|
||||||
|
* @param int $page
|
||||||
|
* the page to return
|
||||||
|
*/
|
||||||
|
public function search($query, $page = 1) {
|
||||||
|
if ($query instanceof SearchHelper) {
|
||||||
|
$query = $query->getSearchQuery();
|
||||||
|
}
|
||||||
|
return $this->adapter->search($query, $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches the pre database for an certain release
|
||||||
|
*
|
||||||
|
* @param string $release
|
||||||
|
* the release name
|
||||||
|
* @return Pre_Release
|
||||||
|
*/
|
||||||
|
public function get($release) {
|
||||||
|
$releases = $this->adapter->search($release);
|
||||||
|
return predb_find_suitable_release($release, $releases);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the latest pre entries from the database
|
||||||
|
*
|
||||||
|
* @param int $page
|
||||||
|
* the page to load
|
||||||
|
*/
|
||||||
|
public function latest($page = 1) {
|
||||||
|
return $this->adapter->latest($page);
|
||||||
|
}
|
||||||
|
}
|
||||||
198
src/Release.php
Normal file
198
src/Release.php
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre entry
|
||||||
|
*
|
||||||
|
* @author @author <a href="http://www.rogiel.com/">Rogiel</a>
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
class Release {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $release;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
var $date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
var $size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
var $files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $nuke;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new release instance.
|
||||||
|
*
|
||||||
|
* If $release is a string, it is set as the release name
|
||||||
|
* If $release is an arraym the following keys are set to the release object model: release, type, date, size, files and nuke.
|
||||||
|
*
|
||||||
|
* @param string $release
|
||||||
|
* the release argument
|
||||||
|
*/
|
||||||
|
public function __construct($release = NULL) {
|
||||||
|
if (is_string($release)) {
|
||||||
|
$this->release = $release;
|
||||||
|
} else if (is_array($release)) {
|
||||||
|
$this->release = (isset($release['release']) ? $release['release'] : NULL);
|
||||||
|
$this->type = (isset($release['type']) ? $release['type'] : NULL);
|
||||||
|
$this->date = (isset($release['date']) ? $release['date'] : NULL);
|
||||||
|
$this->size = (isset($release['size']) ? $release['size'] : NULL);
|
||||||
|
$this->files = (isset($release['files']) ? $release['files'] : NULL);
|
||||||
|
$this->nuke = (isset($release['nuke']) ? $release['nuke'] : NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public function getRelease() {
|
||||||
|
return $this->release;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $release
|
||||||
|
*/
|
||||||
|
public function setRelease($release) {
|
||||||
|
$this->release = $release;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public function getType() {
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
*/
|
||||||
|
public function setType($type) {
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the DateTime
|
||||||
|
*/
|
||||||
|
public function getDate() {
|
||||||
|
return $this->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param DateTime $date
|
||||||
|
*/
|
||||||
|
public function setDate(DateTime $date) {
|
||||||
|
$this->date = $date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the int
|
||||||
|
*/
|
||||||
|
public function getSize() {
|
||||||
|
return $this->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $size
|
||||||
|
*/
|
||||||
|
public function setSize($size) {
|
||||||
|
$this->size = $size;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the int
|
||||||
|
*/
|
||||||
|
public function getFiles() {
|
||||||
|
return $this->files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $files
|
||||||
|
*/
|
||||||
|
public function setFiles($files) {
|
||||||
|
$this->files = $files;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the string
|
||||||
|
*/
|
||||||
|
public function getNuke() {
|
||||||
|
return $this->nuke;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return bool true if the released is nuked
|
||||||
|
*/
|
||||||
|
public function isNuked() {
|
||||||
|
return $this->nuke != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $nuke
|
||||||
|
*/
|
||||||
|
public function setNuke($nuke) {
|
||||||
|
$this->nuke = $nuke;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/Search/Helper.php
Normal file
43
src/Search/Helper.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Search;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an search helper.
|
||||||
|
* It assists the creation of queries that will be used to find an given release.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
interface Helper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a search query that will filter and or specialize the results
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function getSearchQuery();
|
||||||
|
}
|
||||||
119
src/Search/TVShow.php
Normal file
119
src/Search/TVShow.php
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014, Rogiel Sulzbach
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
namespace PreDB\Search;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Helper asists searching for TVShow releases
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
class TVShow implements Helper {
|
||||||
|
private $name;
|
||||||
|
private $season = null;
|
||||||
|
private $episode = null;
|
||||||
|
|
||||||
|
public function __construct($name, $season = null, $episode = null) {
|
||||||
|
$this->name = $name;
|
||||||
|
$this->season = $season;
|
||||||
|
$this->episode = $episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSearchQuery() {
|
||||||
|
$query = $this->name;
|
||||||
|
if ($this->season != null) {
|
||||||
|
$query .= " S" . self::padZero($this->season);
|
||||||
|
if ($this->episode != null)
|
||||||
|
$query .= "E" . self::padZero($this->episode);
|
||||||
|
}
|
||||||
|
return str_replace(" ", ".", $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the $name
|
||||||
|
*/
|
||||||
|
public function getName() {
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return TVShow this instance
|
||||||
|
*/
|
||||||
|
public function setName($name) {
|
||||||
|
$this->name = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the $season
|
||||||
|
*/
|
||||||
|
public function getSeason() {
|
||||||
|
return $this->season;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $season
|
||||||
|
* @return TVShow this instance
|
||||||
|
*/
|
||||||
|
public function setSeason($season) {
|
||||||
|
$this->season = $season;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return the $episode
|
||||||
|
*/
|
||||||
|
public function getEpisode() {
|
||||||
|
return $this->episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $episode
|
||||||
|
* @return TVShow this instance
|
||||||
|
*/
|
||||||
|
public function setEpisode($episode) {
|
||||||
|
$this->episode = $episode;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $number
|
||||||
|
* @return the number with padded zeros
|
||||||
|
*/
|
||||||
|
private static function padZero($number) {
|
||||||
|
if ($number < 10)
|
||||||
|
return "0" . $number;
|
||||||
|
return $number;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user