CollegeDeFranceBridge.php 2.7 KB

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