franceculture.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. extract_attributes,
  7. int_or_none,
  8. unified_strdate,
  9. )
  10. class FranceCultureIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emissions/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  12. _TEST = {
  13. 'url': 'http://www.franceculture.fr/emissions/carnet-nomade/rendez-vous-au-pays-des-geeks',
  14. 'info_dict': {
  15. 'id': 'rendez-vous-au-pays-des-geeks',
  16. 'display_id': 'rendez-vous-au-pays-des-geeks',
  17. 'ext': 'mp3',
  18. 'title': 'Rendez-vous au pays des geeks',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. 'upload_date': '20140301',
  21. 'timestamp': 1393642916,
  22. 'vcodec': 'none',
  23. }
  24. }
  25. def _real_extract(self, url):
  26. display_id = self._match_id(url)
  27. webpage = self._download_webpage(url, display_id)
  28. video_data = extract_attributes(self._search_regex(
  29. r'(?s)<div[^>]+class="[^"]*?(?:title-zone-diffusion|heading-zone-(?:wrapper|player-button))[^"]*?"[^>]*>.*?(<button[^>]+data-asset-source="[^"]+"[^>]+>)',
  30. webpage, 'video data'))
  31. video_url = video_data['data-asset-source']
  32. title = video_data.get('data-asset-title') or self._og_search_title(webpage)
  33. description = self._html_search_regex(
  34. r'(?s)<div[^>]+class="intro"[^>]*>.*?<h2>(.+?)</h2>',
  35. webpage, 'description', default=None)
  36. thumbnail = self._search_regex(
  37. r'(?s)<figure[^>]+itemtype="https://schema.org/ImageObject"[^>]*>.*?<img[^>]+(?:data-dejavu-)?src="([^"]+)"',
  38. webpage, 'thumbnail', fatal=False)
  39. uploader = self._html_search_regex(
  40. r'(?s)<span class="author">(.*?)</span>',
  41. webpage, 'uploader', default=None)
  42. ext = determine_ext(video_url.lower())
  43. return {
  44. 'id': display_id,
  45. 'display_id': display_id,
  46. 'url': video_url,
  47. 'title': title,
  48. 'description': description,
  49. 'thumbnail': thumbnail,
  50. 'ext': ext,
  51. 'vcodec': 'none' if ext == 'mp3' else None,
  52. 'uploader': uploader,
  53. 'timestamp': int_or_none(video_data.get('data-asset-created-date')),
  54. 'duration': int_or_none(video_data.get('data-duration')),
  55. }