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.

108 lines
4.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. unified_strdate,
  7. )
  8. from ..compat import compat_urlparse
  9. class DWIE(InfoExtractor):
  10. IE_NAME = 'dw'
  11. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+(?:av|e)-(?P<id>\d+)'
  12. _TESTS = [{
  13. # video
  14. 'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
  15. 'md5': '7372046e1815c5a534b43f3c3c36e6e9',
  16. 'info_dict': {
  17. 'id': '19112290',
  18. 'ext': 'mp4',
  19. 'title': 'Intelligent light',
  20. 'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
  21. 'upload_date': '20160311',
  22. }
  23. }, {
  24. # audio
  25. 'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
  26. 'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
  27. 'info_dict': {
  28. 'id': '19111941',
  29. 'ext': 'mp3',
  30. 'title': 'WorldLink: My business',
  31. 'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
  32. 'upload_date': '20160311',
  33. }
  34. }, {
  35. # DW documentaries, only last for one or two weeks
  36. 'url': 'http://www.dw.com/en/documentaries-welcome-to-the-90s-2016-05-21/e-19220158-9798',
  37. 'md5': '56b6214ef463bfb9a3b71aeb886f3cf1',
  38. 'info_dict': {
  39. 'id': '19274438',
  40. 'ext': 'mp4',
  41. 'title': 'Welcome to the 90s – Hip Hop',
  42. 'description': 'Welcome to the 90s - The Golden Decade of Hip Hop',
  43. 'upload_date': '20160521',
  44. },
  45. 'skip': 'Video removed',
  46. }]
  47. def _real_extract(self, url):
  48. media_id = self._match_id(url)
  49. webpage = self._download_webpage(url, media_id)
  50. hidden_inputs = self._hidden_inputs(webpage)
  51. title = hidden_inputs['media_title']
  52. media_id = hidden_inputs.get('media_id') or media_id
  53. if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
  54. formats = self._extract_smil_formats(
  55. 'http://www.dw.com/smil/v-%s' % media_id, media_id,
  56. transform_source=lambda s: s.replace(
  57. 'rtmp://tv-od.dw.de/flash/',
  58. 'http://tv-download.dw.de/dwtv_video/flv/'))
  59. self._sort_formats(formats)
  60. else:
  61. formats = [{'url': hidden_inputs['file_name']}]
  62. upload_date = hidden_inputs.get('display_date')
  63. if not upload_date:
  64. upload_date = self._html_search_regex(
  65. r'<span[^>]+class="date">([0-9.]+)\s*\|', webpage,
  66. 'upload date', default=None)
  67. upload_date = unified_strdate(upload_date)
  68. return {
  69. 'id': media_id,
  70. 'title': title,
  71. 'description': self._og_search_description(webpage),
  72. 'thumbnail': hidden_inputs.get('preview_image'),
  73. 'duration': int_or_none(hidden_inputs.get('file_duration')),
  74. 'upload_date': upload_date,
  75. 'formats': formats,
  76. }
  77. class DWArticleIE(InfoExtractor):
  78. IE_NAME = 'dw:article'
  79. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
  80. _TEST = {
  81. 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
  82. 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
  83. 'info_dict': {
  84. 'id': '19105868',
  85. 'ext': 'mp4',
  86. 'title': 'The harsh life of refugees in Idomeni',
  87. 'description': 'md5:196015cc7e48ebf474db9399420043c7',
  88. 'upload_date': '20160310',
  89. }
  90. }
  91. def _real_extract(self, url):
  92. article_id = self._match_id(url)
  93. webpage = self._download_webpage(url, article_id)
  94. hidden_inputs = self._hidden_inputs(webpage)
  95. media_id = hidden_inputs['media_id']
  96. media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
  97. media_url = compat_urlparse.urljoin(url, media_path)
  98. return self.url_result(media_url, 'DW', media_id)