logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

franceculture.py (2866B)


  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. )
  9. class FranceCultureIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emissions/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.franceculture.fr/emissions/carnet-nomade/rendez-vous-au-pays-des-geeks',
  13. 'info_dict': {
  14. 'id': 'rendez-vous-au-pays-des-geeks',
  15. 'display_id': 'rendez-vous-au-pays-des-geeks',
  16. 'ext': 'mp3',
  17. 'title': 'Rendez-vous au pays des geeks',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'upload_date': '20140301',
  20. 'timestamp': 1393700400,
  21. 'vcodec': 'none',
  22. }
  23. }, {
  24. # no thumbnail
  25. 'url': 'https://www.franceculture.fr/emissions/la-recherche-montre-en-main/la-recherche-montre-en-main-du-mercredi-10-octobre-2018',
  26. 'only_matching': True,
  27. }]
  28. def _real_extract(self, url):
  29. display_id = self._match_id(url)
  30. webpage = self._download_webpage(url, display_id)
  31. video_data = extract_attributes(self._search_regex(
  32. r'''(?sx)
  33. (?:
  34. </h1>|
  35. <div[^>]+class="[^"]*?(?:title-zone-diffusion|heading-zone-(?:wrapper|player-button))[^"]*?"[^>]*>
  36. ).*?
  37. (<button[^>]+data-(?:url|asset-source)="[^"]+"[^>]+>)
  38. ''',
  39. webpage, 'video data'))
  40. video_url = video_data.get('data-url') or video_data['data-asset-source']
  41. title = video_data.get('data-asset-title') or video_data.get('data-diffusion-title') or self._og_search_title(webpage)
  42. description = self._html_search_regex(
  43. r'(?s)<div[^>]+class="intro"[^>]*>.*?<h2>(.+?)</h2>',
  44. webpage, 'description', default=None)
  45. thumbnail = self._search_regex(
  46. r'(?s)<figure[^>]+itemtype="https://schema.org/ImageObject"[^>]*>.*?<img[^>]+(?:data-dejavu-)?src="([^"]+)"',
  47. webpage, 'thumbnail', default=None)
  48. uploader = self._html_search_regex(
  49. r'(?s)<span class="author">(.*?)</span>',
  50. webpage, 'uploader', default=None)
  51. ext = determine_ext(video_url.lower())
  52. return {
  53. 'id': display_id,
  54. 'display_id': display_id,
  55. 'url': video_url,
  56. 'title': title,
  57. 'description': description,
  58. 'thumbnail': thumbnail,
  59. 'ext': ext,
  60. 'vcodec': 'none' if ext == 'mp3' else None,
  61. 'uploader': uploader,
  62. 'timestamp': int_or_none(video_data.get('data-start-time')) or int_or_none(video_data.get('data-asset-created-date')),
  63. 'duration': int_or_none(video_data.get('data-duration')),
  64. }