EZTVBridge.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. class EZTVBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "alexAubin";
  5. $this->name = "EZTV";
  6. $this->uri = "https://eztv.ch/";
  7. $this->description = "Returns list of *recent* torrents for a specific show on EZTV. Get showID from URLs in https://eztv.ch/shows/showID/show-full-name.";
  8. $this->update = "2014-01-20";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "Show ids",
  13. "identifier" : "i",
  14. "exampleValue" : "showID1,showID2,..."
  15. }
  16. ]';
  17. }
  18. public function collectData(array $param){
  19. // Make timestamp from relative released time in table
  20. function makeTimestamp($relativeReleaseTime){
  21. $relativeDays = 0;
  22. $relativeHours = 0;
  23. foreach (explode(" ",$relativeReleaseTime) as $relativeTimeElement) {
  24. if (substr($relativeTimeElement,-1) == "d") $relativeDays = substr($relativeTimeElement,0,-1);
  25. if (substr($relativeTimeElement,-1) == "h") $relativeHours = substr($relativeTimeElement,0,-1);
  26. }
  27. return mktime(date('h')-$relativeHours,0,0,date('m'),date('d')-$relativeDays,date('Y'));
  28. }
  29. // Check for ID provided
  30. if (!isset($param['i']))
  31. $this->returnError('You must provide a list of ID (?i=showID1,showID2,...)', 400);
  32. // Loop on show ids
  33. $showList = explode(",",$param['i']);
  34. foreach($showList as $showID){
  35. // Get show page
  36. $html = $this->file_get_html('https://eztv.ch/shows/'.rawurlencode($showID).'/') or $this->returnError('Could not request EZTV for id "'.$showID.'"', 404);
  37. // Loop on each element that look like an episode entry...
  38. foreach($html->find('.forum_header_border') as $element) {
  39. // Filter entries that are not episode entries
  40. $ep = $element->find('td',1);
  41. if (empty($ep)) continue;
  42. $epinfo = $ep->find('.epinfo',0);
  43. $released = $element->find('td',3);
  44. if (empty($epinfo)) continue;
  45. if (empty($released->plaintext)) continue;
  46. // Filter entries that are older than 1 week
  47. if ($released->plaintext == '&gt;1 week') continue;
  48. // Fill item
  49. $item = new \Item();
  50. $item->uri = 'https://eztv.ch/'.$epinfo->href;
  51. $item->id = $item->uri;
  52. $item->timestamp = makeTimestamp($released->plaintext);
  53. $item->title = $epinfo->plaintext;
  54. $item->content = $epinfo->alt;
  55. if(!empty($item->title))
  56. $this->items[] = $item;
  57. }
  58. }
  59. }
  60. public function getName(){
  61. return 'EZTV';
  62. }
  63. public function getURI(){
  64. return 'https://eztv.ch/';
  65. }
  66. public function getCacheDuration(){
  67. return 3600; // 1 hour
  68. }
  69. }