CollegeDeFranceBridge.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 CACHE_TIMEOUT = 10800; // 3h
  7. const DESCRIPTION = "Returns the latest audio and video from CollegeDeFrance";
  8. public function collectData(){
  9. $months = array(
  10. '01' => 'janv.',
  11. '02' => 'févr.',
  12. '03' => 'mars',
  13. '04' => 'avr.',
  14. '05' => 'mai',
  15. '06' => 'juin',
  16. '07' => 'juil.',
  17. '08' => 'août',
  18. '09' => 'sept.',
  19. '10' => 'oct.',
  20. '11' => 'nov.',
  21. '12' => 'déc.'
  22. );
  23. // The "API" used by the site returns a list of partial HTML in this form
  24. /* <li>
  25. * <a href="/site/thomas-romer/guestlecturer-2016-04-15-14h30.htm" data-target="after">
  26. * <span class="date"><span class="list-icon list-icon-video"></span><span class="list-icon list-icon-audio"></span>15 avr. 2016</span>
  27. * <span class="lecturer">Christopher Hays</span>
  28. * <span class='title'>Imagery of Divine Suckling in the Hebrew Bible and the Ancient Near East</span>
  29. * </a>
  30. * </li>
  31. */
  32. $html = getSimpleHTMLDOM(self::URI.'components/search-audiovideo.jsp?fulltext=&siteid=1156951719600&lang=FR&type=all')
  33. or 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(
  47. '!Y-m-d-H\hi',
  48. substr($element->href, strpos($element->href, '201'), 16),
  49. $timezone
  50. );
  51. if(!$d){
  52. $d=DateTime::createFromFormat(
  53. '!d m Y',
  54. trim(str_replace(
  55. array_values($months),
  56. array_keys($months),
  57. $element->find('.date', 0)->plaintext
  58. )),
  59. $timezone
  60. );
  61. }
  62. $item['timestamp'] = $d->format('U');
  63. $item['content'] = $element->find('.lecturer', 0)->innertext . ' - ' . $element->find('.title', 0)->innertext;
  64. $item['uri'] = self::URI . $element->href;
  65. $this->items[] = $item;
  66. }
  67. }
  68. }