vrt.py 3.4 KB

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