You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. unescapeHTML,
  9. unified_timestamp,
  10. )
  11. class ExpressenIE(InfoExtractor):
  12. _VALID_URL = r'''(?x)
  13. https?://
  14. (?:www\.)?expressen\.se/
  15. (?:(?:tvspelare/video|videoplayer/embed)/)?
  16. tv/(?:[^/]+/)*
  17. (?P<id>[^/?#&]+)
  18. '''
  19. _TESTS = [{
  20. 'url': 'https://www.expressen.se/tv/ledare/ledarsnack/ledarsnack-om-arbetslosheten-bland-kvinnor-i-speciellt-utsatta-omraden/',
  21. 'md5': '2fbbe3ca14392a6b1b36941858d33a45',
  22. 'info_dict': {
  23. 'id': '8690962',
  24. 'ext': 'mp4',
  25. 'title': 'Ledarsnack: Om arbetslösheten bland kvinnor i speciellt utsatta områden',
  26. 'description': 'md5:f38c81ff69f3de4d269bbda012fcbbba',
  27. 'thumbnail': r're:^https?://.*\.jpg$',
  28. 'duration': 788,
  29. 'timestamp': 1526639109,
  30. 'upload_date': '20180518',
  31. },
  32. }, {
  33. 'url': 'https://www.expressen.se/tv/kultur/kulturdebatt-med-expressens-karin-olsson/',
  34. 'only_matching': True,
  35. }, {
  36. 'url': 'https://www.expressen.se/tvspelare/video/tv/ditv/ekonomistudion/experterna-har-ar-fragorna-som-avgor-valet/?embed=true&external=true&autoplay=true&startVolume=0&partnerId=di',
  37. 'only_matching': True,
  38. }, {
  39. 'url': 'https://www.expressen.se/videoplayer/embed/tv/ditv/ekonomistudion/experterna-har-ar-fragorna-som-avgor-valet/?embed=true&external=true&autoplay=true&startVolume=0&partnerId=di',
  40. 'only_matching': True,
  41. }]
  42. @staticmethod
  43. def _extract_urls(webpage):
  44. return [
  45. mobj.group('url') for mobj in re.finditer(
  46. r'<iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//(?:www\.)?expressen\.se/(?:tvspelare/video|videoplayer/embed)/tv/.+?)\1',
  47. webpage)]
  48. def _real_extract(self, url):
  49. display_id = self._match_id(url)
  50. webpage = self._download_webpage(url, display_id)
  51. def extract_data(name):
  52. return self._parse_json(
  53. self._search_regex(
  54. r'data-%s=(["\'])(?P<value>(?:(?!\1).)+)\1' % name,
  55. webpage, 'info', group='value'),
  56. display_id, transform_source=unescapeHTML)
  57. info = extract_data('video-tracking-info')
  58. video_id = info['videoId']
  59. data = extract_data('article-data')
  60. stream = data['stream']
  61. if determine_ext(stream) == 'm3u8':
  62. formats = self._extract_m3u8_formats(
  63. stream, display_id, 'mp4', entry_protocol='m3u8_native',
  64. m3u8_id='hls')
  65. else:
  66. formats = [{
  67. 'url': stream,
  68. }]
  69. self._sort_formats(formats)
  70. title = info.get('titleRaw') or data['title']
  71. description = info.get('descriptionRaw')
  72. thumbnail = info.get('socialMediaImage') or data.get('image')
  73. duration = int_or_none(info.get('videoTotalSecondsDuration')
  74. or data.get('totalSecondsDuration'))
  75. timestamp = unified_timestamp(info.get('publishDate'))
  76. return {
  77. 'id': video_id,
  78. 'display_id': display_id,
  79. 'title': title,
  80. 'description': description,
  81. 'thumbnail': thumbnail,
  82. 'duration': duration,
  83. 'timestamp': timestamp,
  84. 'formats': formats,
  85. }