ina.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from .common import InfoExtractor
  2. from ..utils import unified_strdate
  3. class InaIE(InfoExtractor):
  4. _VALID_URL = r'https?://(?:(?:www|m)\.)?ina\.fr/(?:[^?#]+/)(?P<id>[\w-]+)'
  5. _TESTS = [{
  6. 'url': 'https://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html',
  7. 'md5': 'c5a09e5cb5604ed10709f06e7a377dda',
  8. 'info_dict': {
  9. 'id': 'I12055569',
  10. 'ext': 'mp4',
  11. 'title': 'François Hollande "Je crois que c\'est clair"',
  12. 'description': 'md5:19f61e2b4844ed4bb2e3df9ab9f527ff',
  13. 'upload_date': '20070712',
  14. 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/3c4/I12055569.jpeg',
  15. },
  16. }, {
  17. 'url': 'https://www.ina.fr/video/S806544_001/don-d-organes-des-avancees-mais-d-importants-besoins-video.html',
  18. 'only_matching': True,
  19. }, {
  20. 'url': 'https://www.ina.fr/audio/P16173408',
  21. 'only_matching': True,
  22. }, {
  23. 'url': 'https://www.ina.fr/video/P16173408-video.html',
  24. 'only_matching': True,
  25. }, {
  26. 'url': 'http://m.ina.fr/video/I12055569',
  27. 'only_matching': True,
  28. }, {
  29. 'url': 'https://www.ina.fr/ina-eclaire-actu/video/cpb8205116303/les-jeux-electroniques',
  30. 'md5': '4b8284a9a3a184fdc7e744225b8251e7',
  31. 'info_dict': {
  32. 'id': 'CPB8205116303',
  33. 'ext': 'mp4',
  34. 'title': 'Les jeux électroniques',
  35. 'description': 'md5:e09f7683dad1cc60b74950490127d233',
  36. 'upload_date': '19821204',
  37. 'duration': 657,
  38. 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/203/CPB8205116303.jpeg',
  39. },
  40. }, {
  41. 'url': 'https://www.ina.fr/ina-eclaire-actu/arletty-carriere-conseils-actrice-marcel-carne',
  42. 'md5': '743d6f069a00e19dda0da166a54eeccb',
  43. 'info_dict': {
  44. 'id': 'I22203233',
  45. 'ext': 'mp4',
  46. 'title': 'Arletty sur le métier d\'actrice',
  47. 'description': 'md5:3d89b5e419d8514c934f146045ccdbad',
  48. 'upload_date': '19581128',
  49. 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/082/I22203233.jpeg',
  50. },
  51. }, {
  52. 'url': 'https://www.ina.fr/ina-eclaire-actu/chasse-croise-sncf-gare-d-austerlitz-vacances-d-ete',
  53. 'md5': 'a96fb85e9ba3b5c5b2eeb0c5daa55f2f',
  54. 'info_dict': {
  55. 'id': 'CAF91038285',
  56. 'ext': 'mp4',
  57. 'title': 'Les grands départs : les trains',
  58. 'description': 'md5:1630ee819d8d4da97df53459e99f72bb',
  59. 'upload_date': '19740801',
  60. 'thumbnail': 'https://cdn-hub.ina.fr/notice/690x517/2cf/CAF91038285.jpeg',
  61. },
  62. }]
  63. def _real_extract(self, url):
  64. display_id = self._match_id(url)
  65. webpage = self._download_webpage(url, display_id)
  66. api_url = self._html_search_regex(r'asset-details-url\s*=\s*["\'](?P<api_url>[^"\']+)', webpage, 'api_url')
  67. asset_id = self._search_regex(r'assets/([^?/]+)', api_url, 'asset_id')
  68. api_response = self._download_json(api_url.replace(asset_id, f'{asset_id}.json'), asset_id)
  69. return {
  70. 'id': asset_id,
  71. 'url': api_response['resourceUrl'],
  72. 'ext': {'video': 'mp4', 'audio': 'mp3'}.get(api_response.get('type')),
  73. 'title': api_response.get('title'),
  74. 'description': api_response.get('description'),
  75. 'upload_date': unified_strdate(api_response.get('dateOfBroadcast')),
  76. 'duration': api_response.get('duration'),
  77. 'thumbnail': api_response.get('resourceThumbnail'),
  78. }