YandereBridge.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class YandereBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "mitsukarenai";
  5. $this->name = "Yande.re";
  6. $this->uri = "https://yande.re/";
  7. $this->description = "Returns images from given page and tags";
  8. $this->update = "2014-05-25";
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "page",
  13. "identifier" : "p",
  14. "type" : "number"
  15. },
  16. {
  17. "name" : "tags",
  18. "identifier" : "t"
  19. }
  20. ]';
  21. }
  22. public function collectData(array $param){
  23. $page = 1; $tags = '';
  24. if (isset($param['p'])) {
  25. $page = (int)preg_replace("/[^0-9]/",'', $param['p']);
  26. }
  27. if (isset($param['t'])) {
  28. $tags = urlencode($param['t']);
  29. }
  30. $html = $this->file_get_html("https://yande.re/post?page=$page&tags=$tags") or $this->returnError('Could not request Yandere.', 404);
  31. $input_json = explode('Post.register(', $html);
  32. foreach($input_json as $element)
  33. $data[] = preg_replace('/}\)(.*)/', '}', $element);
  34. unset($data[0]);
  35. foreach($data as $datai) {
  36. $json = json_decode($datai, TRUE);
  37. $item = new \Item();
  38. $item->uri = 'http://yande.re/post/show/'.$json['id'];
  39. $item->postid = $json['id'];
  40. $item->timestamp = $json['created_at'];
  41. $item->imageUri = $json['file_url'];
  42. $item->thumbnailUri = $json['preview_url'];
  43. $item->title = 'Yandere | '.$json['id'];
  44. $item->content = '<a href="' . $item->imageUri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: '.$json['tags'];
  45. $this->items[] = $item;
  46. }
  47. }
  48. public function getName(){
  49. return 'Yande.re';
  50. }
  51. public function getURI(){
  52. return 'http://yande.re/post';
  53. }
  54. public function getCacheDuration(){
  55. return 1800; // 30 minutes
  56. }
  57. }