CollegeDeFranceBridge.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class CollegeDeFranceBridge extends BridgeAbstract{
  3. const MAINTAINER = "pit-fgfjiudghdf";
  4. const NAME = "CollegeDeFrance";
  5. const URI = "http://www.college-de-france.fr/";
  6. const DESCRIPTION = "Returns the latest audio and video from CollegeDeFrance";
  7. public function collectData(){
  8. $months = array(
  9. '01' => 'janv.',
  10. '02' => 'févr.',
  11. '03' => 'mars',
  12. '04' => 'avr.',
  13. '05' => 'mai',
  14. '06' => 'juin',
  15. '07' => 'juil.',
  16. '08' => 'août',
  17. '09' => 'sept.',
  18. '10' => 'oct.',
  19. '11' => 'nov.',
  20. '12' => 'déc.'
  21. );
  22. // The "API" used by the site returns a list of partial HTML in this form
  23. /* <li>
  24. * <a href="/site/thomas-romer/guestlecturer-2016-04-15-14h30.htm" data-target="after">
  25. * <span class="date"><span class="list-icon list-icon-video"></span><span class="list-icon list-icon-audio"></span>15 avr. 2016</span>
  26. * <span class="lecturer">Christopher Hays</span>
  27. * <span class='title'>Imagery of Divine Suckling in the Hebrew Bible and the Ancient Near East</span>
  28. * </a>
  29. * </li>
  30. */
  31. $html = $this->getSimpleHTMLDOM(self::URI.'components/search-audiovideo.jsp?fulltext=&siteid=1156951719600&lang=FR&type=all')
  32. or $this->returnServerError('Could not request CollegeDeFrance.');
  33. foreach($html->find('a[data-target]') as $element) {
  34. $item = array();
  35. $item['title'] = $element->find('.title', 0)->plaintext;
  36. // Most relative URLs contains an hour in addition to the date, so let's use it
  37. // <a href="/site/yann-lecun/course-2016-04-08-11h00.htm" data-target="after">
  38. //
  39. // Sometimes there's an __1, perhaps it signifies an update "/site/patrick-boucheron/seminar-2016-05-03-18h00__1.htm"
  40. //
  41. // But unfortunately some don't have any hours info
  42. // <a href="/site/institut-physique/The-Mysteries-of-Decoherence-Sebastien-Gleyzes-[Video-3-35].htm" data-target="after">
  43. $timezone = new DateTimeZone('Europe/Paris');
  44. // strpos($element->href, '201') will break in 2020 but it'll probably break prior to then due to site changes anyway
  45. $d = DateTime::createFromFormat(
  46. '!Y-m-d-H\hi',
  47. substr($element->href, strpos($element->href, '201'), 16),
  48. $timezone
  49. );
  50. if(!$d){
  51. $d=DateTime::createFromFormat(
  52. '!d m Y',
  53. trim(str_replace(
  54. array_values($months),
  55. array_keys($months),
  56. $element->find('.date', 0)->plaintext
  57. )),
  58. $timezone
  59. );
  60. }
  61. $item['timestamp'] = $d->format('U');
  62. $item['content'] = $element->find('.lecturer', 0)->innertext . ' - ' . $element->find('.title', 0)->innertext;
  63. $item['uri'] = self::URI . $element->href;
  64. $this->items[] = $item;
  65. }
  66. }
  67. public function getCacheDuration(){
  68. return 3600*3; // 3 hours
  69. }
  70. }