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.

103 lines
4.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. strip_jsonp,
  7. )
  8. class WashingtonPostIE(InfoExtractor):
  9. _VALID_URL = r'^https?://(?:www\.)?washingtonpost\.com/.*?/(?P<id>[^/]+)/(?:$|[?#])'
  10. _TEST = {
  11. 'url': 'http://www.washingtonpost.com/sf/national/2014/03/22/sinkhole-of-bureaucracy/',
  12. 'playlist': [{
  13. 'md5': 'c3f4b4922ffa259243f68e928db2db8c',
  14. 'info_dict': {
  15. 'id': 'fc433c38-b146-11e3-b8b3-44b1d1cd4c1f',
  16. 'ext': 'mp4',
  17. 'title': 'Breaking Points: The Paper Mine',
  18. 'duration': 1287,
  19. 'description': 'Overly complicated paper pushing is nothing new to government bureaucracy. But the way federal retirement applications are filed may be the most outdated. David Fahrenthold explains.',
  20. 'uploader': 'The Washington Post',
  21. 'timestamp': 1395527908,
  22. 'upload_date': '20140322',
  23. },
  24. }, {
  25. 'md5': 'f645a07652c2950cd9134bb852c5f5eb',
  26. 'info_dict': {
  27. 'id': '41255e28-b14a-11e3-b8b3-44b1d1cd4c1f',
  28. 'ext': 'mp4',
  29. 'title': 'The town bureaucracy sustains',
  30. 'description': 'Underneath the friendly town of Boyers is a sea of government paperwork. In a disused limestone mine, hundreds of locals now track, file and process retirement applications for the federal government. We set out to find out what it\'s like to do paperwork 230 feet underground.',
  31. 'duration': 2217,
  32. 'timestamp': 1395528005,
  33. 'upload_date': '20140322',
  34. 'uploader': 'The Washington Post',
  35. },
  36. }]
  37. }
  38. def _real_extract(self, url):
  39. mobj = re.match(self._VALID_URL, url)
  40. page_id = mobj.group('id')
  41. webpage = self._download_webpage(url, page_id)
  42. title = self._og_search_title(webpage)
  43. uuids = re.findall(r'data-video-uuid="([^"]+)"', webpage)
  44. entries = []
  45. for i, uuid in enumerate(uuids, start=1):
  46. vinfo_all = self._download_json(
  47. 'http://www.washingtonpost.com/posttv/c/videojson/%s?resType=jsonp' % uuid,
  48. page_id,
  49. transform_source=strip_jsonp,
  50. note='Downloading information of video %d/%d' % (i, len(uuids))
  51. )
  52. vinfo = vinfo_all[0]['contentConfig']
  53. uploader = vinfo.get('credits', {}).get('source')
  54. timestamp = int_or_none(
  55. vinfo.get('dateConfig', {}).get('dateFirstPublished'), 1000)
  56. formats = [{
  57. 'format_id': (
  58. '%s-%s-%s' % (s.get('type'), s.get('width'), s.get('bitrate'))
  59. if s.get('width')
  60. else s.get('type')),
  61. 'vbr': s.get('bitrate') if s.get('width') != 0 else None,
  62. 'width': s.get('width'),
  63. 'height': s.get('height'),
  64. 'acodec': s.get('audioCodec'),
  65. 'vcodec': s.get('videoCodec') if s.get('width') != 0 else 'none',
  66. 'filesize': s.get('fileSize'),
  67. 'url': s.get('url'),
  68. 'ext': 'mp4',
  69. 'protocol': {
  70. 'MP4': 'http',
  71. 'F4F': 'f4m',
  72. }.get(s.get('type'))
  73. } for s in vinfo.get('streams', [])]
  74. source_media_url = vinfo.get('sourceMediaURL')
  75. if source_media_url:
  76. formats.append({
  77. 'format_id': 'source_media',
  78. 'url': source_media_url,
  79. })
  80. self._sort_formats(formats)
  81. entries.append({
  82. 'id': uuid,
  83. 'title': vinfo['title'],
  84. 'description': vinfo.get('blurb'),
  85. 'uploader': uploader,
  86. 'formats': formats,
  87. 'duration': int_or_none(vinfo.get('videoDuration'), 100),
  88. 'timestamp': timestamp,
  89. })
  90. return {
  91. '_type': 'playlist',
  92. 'entries': entries,
  93. 'id': page_id,
  94. 'title': title,
  95. }