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.

106 lines
3.9 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. 'url': 'http://www.dw.com/en/documentaries-welcome-to-the-90s-2016-05-21/e-19220158-9798',
  36. 'md5': '56b6214ef463bfb9a3b71aeb886f3cf1',
  37. 'info_dict': {
  38. 'id': '19274438',
  39. 'ext': 'mp4',
  40. 'title': 'Welcome to the 90s – Hip Hop',
  41. 'description': 'Welcome to the 90s - The Golden Decade of Hip Hop',
  42. 'upload_date': '20160521',
  43. },
  44. }]
  45. def _real_extract(self, url):
  46. media_id = self._match_id(url)
  47. webpage = self._download_webpage(url, media_id)
  48. hidden_inputs = self._hidden_inputs(webpage)
  49. title = hidden_inputs['media_title']
  50. media_id = hidden_inputs.get('media_id') or media_id
  51. if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
  52. formats = self._extract_smil_formats(
  53. 'http://www.dw.com/smil/v-%s' % media_id, media_id,
  54. transform_source=lambda s: s.replace(
  55. 'rtmp://tv-od.dw.de/flash/',
  56. 'http://tv-download.dw.de/dwtv_video/flv/'))
  57. self._sort_formats(formats)
  58. else:
  59. formats = [{'url': hidden_inputs['file_name']}]
  60. upload_date = hidden_inputs.get('display_date')
  61. if not upload_date:
  62. upload_date = self._html_search_regex(
  63. r'<span[^>]+class="date">([0-9.]+)\s*\|', webpage,
  64. 'upload date', default=None)
  65. upload_date = unified_strdate(upload_date)
  66. return {
  67. 'id': media_id,
  68. 'title': title,
  69. 'description': self._og_search_description(webpage),
  70. 'thumbnail': hidden_inputs.get('preview_image'),
  71. 'duration': int_or_none(hidden_inputs.get('file_duration')),
  72. 'upload_date': upload_date,
  73. 'formats': formats,
  74. }
  75. class DWArticleIE(InfoExtractor):
  76. IE_NAME = 'dw:article'
  77. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
  78. _TEST = {
  79. 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
  80. 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
  81. 'info_dict': {
  82. 'id': '19105868',
  83. 'ext': 'mp4',
  84. 'title': 'The harsh life of refugees in Idomeni',
  85. 'description': 'md5:196015cc7e48ebf474db9399420043c7',
  86. 'upload_date': '20160310',
  87. }
  88. }
  89. def _real_extract(self, url):
  90. article_id = self._match_id(url)
  91. webpage = self._download_webpage(url, article_id)
  92. hidden_inputs = self._hidden_inputs(webpage)
  93. media_id = hidden_inputs['media_id']
  94. media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
  95. media_url = compat_urlparse.urljoin(url, media_path)
  96. return self.url_result(media_url, 'DW', media_id)