logo

youtube-dl

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

alsace20tv.py (3241B)


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