logo

youtube-dl

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

medialaan.py (4184B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. extract_attributes,
  6. int_or_none,
  7. mimetype2ext,
  8. parse_iso8601,
  9. )
  10. class MedialaanIE(InfoExtractor):
  11. _VALID_URL = r'''(?x)
  12. https?://
  13. (?:
  14. (?:embed\.)?mychannels.video/embed/|
  15. embed\.mychannels\.video/(?:s(?:dk|cript)/)?production/|
  16. (?:www\.)?(?:
  17. (?:
  18. 7sur7|
  19. demorgen|
  20. hln|
  21. joe|
  22. qmusic
  23. )\.be|
  24. (?:
  25. [abe]d|
  26. bndestem|
  27. destentor|
  28. gelderlander|
  29. pzc|
  30. tubantia|
  31. volkskrant
  32. )\.nl
  33. )/video/(?:[^/]+/)*[^/?&#]+~p
  34. )
  35. (?P<id>\d+)
  36. '''
  37. _TESTS = [{
  38. 'url': 'https://www.bndestem.nl/video/de-terugkeer-van-ally-de-aap-en-wie-vertrekt-er-nog-bij-nac~p193993',
  39. 'info_dict': {
  40. 'id': '193993',
  41. 'ext': 'mp4',
  42. 'title': 'De terugkeer van Ally de Aap en wie vertrekt er nog bij NAC?',
  43. 'timestamp': 1611663540,
  44. 'upload_date': '20210126',
  45. 'duration': 238,
  46. },
  47. 'params': {
  48. 'skip_download': True,
  49. },
  50. }, {
  51. 'url': 'https://www.gelderlander.nl/video/kanalen/degelderlander~c320/series/snel-nieuws~s984/noodbevel-in-doetinchem-politie-stuurt-mensen-centrum-uit~p194093',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'https://embed.mychannels.video/sdk/production/193993?options=TFTFF_default',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'https://embed.mychannels.video/script/production/193993',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'https://embed.mychannels.video/production/193993',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://mychannels.video/embed/193993',
  64. 'only_matching': True,
  65. }, {
  66. 'url': 'https://embed.mychannels.video/embed/193993',
  67. 'only_matching': True,
  68. }]
  69. @staticmethod
  70. def _extract_urls(webpage):
  71. entries = []
  72. for element in re.findall(r'(<div[^>]+data-mychannels-type="video"[^>]*>)', webpage):
  73. mychannels_id = extract_attributes(element).get('data-mychannels-id')
  74. if mychannels_id:
  75. entries.append('https://mychannels.video/embed/' + mychannels_id)
  76. return entries
  77. def _real_extract(self, url):
  78. production_id = self._match_id(url)
  79. production = self._download_json(
  80. 'https://embed.mychannels.video/sdk/production/' + production_id,
  81. production_id, query={'options': 'UUUU_default'})['productions'][0]
  82. title = production['title']
  83. formats = []
  84. for source in (production.get('sources') or []):
  85. src = source.get('src')
  86. if not src:
  87. continue
  88. ext = mimetype2ext(source.get('type'))
  89. if ext == 'm3u8':
  90. formats.extend(self._extract_m3u8_formats(
  91. src, production_id, 'mp4', 'm3u8_native',
  92. m3u8_id='hls', fatal=False))
  93. else:
  94. formats.append({
  95. 'ext': ext,
  96. 'url': src,
  97. })
  98. self._sort_formats(formats)
  99. return {
  100. 'id': production_id,
  101. 'title': title,
  102. 'formats': formats,
  103. 'thumbnail': production.get('posterUrl'),
  104. 'timestamp': parse_iso8601(production.get('publicationDate'), ' '),
  105. 'duration': int_or_none(production.get('duration')) or None,
  106. }