logo

youtube-dl

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

vrt.py (3523B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. extract_attributes,
  7. float_or_none,
  8. get_element_by_class,
  9. strip_or_none,
  10. unified_timestamp,
  11. )
  12. class VRTIE(InfoExtractor):
  13. IE_DESC = 'VRT NWS, Flanders News, Flandern Info and Sporza'
  14. _VALID_URL = r'https?://(?:www\.)?(?P<site>vrt\.be/vrtnws|sporza\.be)/[a-z]{2}/\d{4}/\d{2}/\d{2}/(?P<id>[^/?&#]+)'
  15. _TESTS = [{
  16. 'url': 'https://www.vrt.be/vrtnws/nl/2019/05/15/beelden-van-binnenkant-notre-dame-een-maand-na-de-brand/',
  17. 'md5': 'e1663accf5cf13f375f3cd0d10476669',
  18. 'info_dict': {
  19. 'id': 'pbs-pub-7855fc7b-1448-49bc-b073-316cb60caa71$vid-2ca50305-c38a-4762-9890-65cbd098b7bd',
  20. 'ext': 'mp4',
  21. 'title': 'Beelden van binnenkant Notre-Dame, één maand na de brand',
  22. 'description': 'Op maandagavond 15 april ging een deel van het dakgebinte van de Parijse kathedraal in vlammen op.',
  23. 'timestamp': 1557924660,
  24. 'upload_date': '20190515',
  25. 'duration': 31.2,
  26. },
  27. }, {
  28. 'url': 'https://sporza.be/nl/2019/05/15/de-belgian-cats-zijn-klaar-voor-het-ek/',
  29. 'md5': '910bba927566e9ab992278f647eb4b75',
  30. 'info_dict': {
  31. 'id': 'pbs-pub-f2c86a46-8138-413a-a4b9-a0015a16ce2c$vid-1f112b31-e58e-4379-908d-aca6d80f8818',
  32. 'ext': 'mp4',
  33. 'title': 'De Belgian Cats zijn klaar voor het EK mét Ann Wauters',
  34. 'timestamp': 1557923760,
  35. 'upload_date': '20190515',
  36. 'duration': 115.17,
  37. },
  38. }, {
  39. 'url': 'https://www.vrt.be/vrtnws/en/2019/05/15/belgium_s-eurovision-entry-falls-at-the-first-hurdle/',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'https://www.vrt.be/vrtnws/de/2019/05/15/aus-fuer-eliott-im-halbfinale-des-eurosongfestivals/',
  43. 'only_matching': True,
  44. }]
  45. _CLIENT_MAP = {
  46. 'vrt.be/vrtnws': 'vrtnieuws',
  47. 'sporza.be': 'sporza',
  48. }
  49. def _real_extract(self, url):
  50. site, display_id = re.match(self._VALID_URL, url).groups()
  51. webpage = self._download_webpage(url, display_id)
  52. attrs = extract_attributes(self._search_regex(
  53. r'(<[^>]+class="vrtvideo"[^>]*>)', webpage, 'vrt video'))
  54. asset_id = attrs['data-videoid']
  55. publication_id = attrs.get('data-publicationid')
  56. if publication_id:
  57. asset_id = publication_id + '$' + asset_id
  58. client = attrs.get('data-client') or self._CLIENT_MAP[site]
  59. title = strip_or_none(get_element_by_class(
  60. 'vrt-title', webpage) or self._html_search_meta(
  61. ['og:title', 'twitter:title', 'name'], webpage))
  62. description = self._html_search_meta(
  63. ['og:description', 'twitter:description', 'description'], webpage)
  64. if description == '…':
  65. description = None
  66. timestamp = unified_timestamp(self._html_search_meta(
  67. 'article:published_time', webpage))
  68. return {
  69. '_type': 'url_transparent',
  70. 'id': asset_id,
  71. 'display_id': display_id,
  72. 'title': title,
  73. 'description': description,
  74. 'thumbnail': attrs.get('data-posterimage'),
  75. 'timestamp': timestamp,
  76. 'duration': float_or_none(attrs.get('data-duration'), 1000),
  77. 'url': 'https://mediazone.vrt.be/api/v1/%s/assets/%s' % (client, asset_id),
  78. 'ie_key': 'Canvas',
  79. }