alsace20tv.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. dict_get,
  5. get_element_by_class,
  6. int_or_none,
  7. unified_strdate,
  8. url_or_none,
  9. )
  10. class Alsace20TVBaseIE(InfoExtractor):
  11. def _extract_video(self, video_id, url=None):
  12. info = self._download_json(
  13. f'https://www.alsace20.tv/visionneuse/visio_v9_js.php?key={video_id}&habillage=0&mode=html',
  14. video_id) or {}
  15. title = info.get('titre')
  16. formats = []
  17. for res, fmt_url in (info.get('files') or {}).items():
  18. formats.extend(
  19. self._extract_smil_formats(fmt_url, video_id, fatal=False)
  20. if '/smil:_' in fmt_url
  21. else self._extract_mpd_formats(fmt_url, video_id, mpd_id=res, fatal=False))
  22. webpage = (url and self._download_webpage(url, video_id, fatal=False)) or ''
  23. thumbnail = url_or_none(dict_get(info, ('image', 'preview')) or self._og_search_thumbnail(webpage))
  24. upload_date = self._search_regex(r'/(\d{6})_', thumbnail, 'upload_date', default=None)
  25. upload_date = unified_strdate(f'20{upload_date[:2]}-{upload_date[2:4]}-{upload_date[4:]}') if upload_date else None
  26. return {
  27. 'id': video_id,
  28. 'title': title,
  29. 'formats': formats,
  30. 'description': clean_html(get_element_by_class('wysiwyg', webpage)),
  31. 'upload_date': upload_date,
  32. 'thumbnail': thumbnail,
  33. 'duration': int_or_none(self._og_search_property('video:duration', webpage) if webpage else None),
  34. 'view_count': int_or_none(info.get('nb_vues')),
  35. }
  36. class Alsace20TVIE(Alsace20TVBaseIE):
  37. _VALID_URL = r'https?://(?:www\.)?alsace20\.tv/(?:[\w-]+/)+[\w-]+-(?P<id>[\w]+)'
  38. _TESTS = [{
  39. 'url': 'https://www.alsace20.tv/VOD/Actu/JT/Votre-JT-jeudi-3-fevrier-lyNHCXpYJh.html',
  40. 'info_dict': {
  41. 'id': 'lyNHCXpYJh',
  42. 'ext': 'mp4',
  43. 'description': 'md5:fc0bc4a0692d3d2dba4524053de4c7b7',
  44. 'title': 'Votre JT du jeudi 3 février',
  45. 'upload_date': '20220203',
  46. 'thumbnail': r're:https?://.+\.jpg',
  47. 'duration': 1073,
  48. 'view_count': int,
  49. },
  50. }]
  51. def _real_extract(self, url):
  52. video_id = self._match_id(url)
  53. return self._extract_video(video_id, url)
  54. class Alsace20TVEmbedIE(Alsace20TVBaseIE):
  55. _VALID_URL = r'https?://(?:www\.)?alsace20\.tv/emb/(?P<id>[\w]+)'
  56. _TESTS = [{
  57. 'url': 'https://www.alsace20.tv/emb/lyNHCXpYJh',
  58. # 'md5': 'd91851bf9af73c0ad9b2cdf76c127fbb',
  59. 'info_dict': {
  60. 'id': 'lyNHCXpYJh',
  61. 'ext': 'mp4',
  62. 'title': 'Votre JT du jeudi 3 février',
  63. 'upload_date': '20220203',
  64. 'thumbnail': r're:https?://.+\.jpg',
  65. 'view_count': int,
  66. },
  67. 'params': {
  68. 'format': 'bestvideo',
  69. },
  70. }]
  71. def _real_extract(self, url):
  72. video_id = self._match_id(url)
  73. return self._extract_video(video_id)