NovelUpdatesBridge.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class NovelUpdatesBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "albirew";
  5. $this->name = "Novel Updates";
  6. $this->uri = "http://www.novelupdates.com/";
  7. $this->description = "Returns releases from Novel Updates";
  8. $this->update = "2016-05-21";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "Novel URL",
  13. "identifier" : "n"
  14. }
  15. ]';
  16. }
  17. public function collectData(array $param){
  18. if (!isset($param['n']))
  19. $this->returnError('You must specify the novel URL (/series/...)', 400);
  20. $thread = parse_url($param['n']) or $this->returnError('This URL seems malformed, please check it.', 400);
  21. if($thread['host'] !== 'www.novelupdates.com')
  22. $this->returnError('NovelUpdates URL only.', 400);
  23. if(strpos($thread['path'], 'series/') === FALSE)
  24. $this->returnError('You must specify the novel URL.', 400);
  25. $url = 'http://www.novelupdates.com'.$thread['path'].'';
  26. $fullhtml = $this->file_get_html($url) or $this->returnError("Could not request NovelUpdates, novel not found", 404);
  27. $this->request = $fullhtml->find('h4.seriestitle', 0)->plaintext;
  28. // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259
  29. // forcefully removes tbody
  30. $html = $fullhtml->find('table#myTable', 0)->innertext;
  31. $html = stristr($html, '<tbody>'); //strip thead
  32. $html = stristr($html, '<tr>'); //remove tbody
  33. $html = str_get_html(stristr($html, '</tbody>', true)); //remove last tbody and get back as an array
  34. foreach($html->find('tr') as $element){
  35. $item = new \Item();
  36. $item->uri = $element->find('td', 2)->find('a', 0)->href;
  37. $item->title = $element->find('td', 2)->find('a', 0)->plaintext;
  38. $item->team = $element->find('td', 1)->innertext;
  39. $item->timestamp = strtotime($element->find('td', 0)->plaintext);
  40. $item->content = '<a href="'.$item->uri.'">'.$this->request.' - '.$item->title.'</a> by '.$item->team.'<br><a href="'.$item->uri.'">'.$fullhtml->find('div.seriesimg', 0)->innertext.'</a>';
  41. $this->items[] = $item;
  42. }
  43. }
  44. public function getName(){
  45. return (!empty($this->request) ? $this->request.' - ' : '') .'Novel Updates';
  46. }
  47. public function getURI(){
  48. return 'http://www.novelupdates.com/';
  49. }
  50. public function getDescription(){
  51. return "Novel Updates - Directory of Translated Novels";
  52. }
  53. public function getCacheDuration(){
  54. return 21600; // 6 hours
  55. }
  56. }