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.

85 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import int_or_none
  5. from ..compat import compat_urlparse
  6. class DWIE(InfoExtractor):
  7. IE_NAME = 'dw'
  8. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+av-(?P<id>\d+)'
  9. _TESTS = [{
  10. # video
  11. 'url': 'http://www.dw.com/en/intelligent-light/av-19112290',
  12. 'md5': '7372046e1815c5a534b43f3c3c36e6e9',
  13. 'info_dict': {
  14. 'id': '19112290',
  15. 'ext': 'mp4',
  16. 'title': 'Intelligent light',
  17. 'description': 'md5:90e00d5881719f2a6a5827cb74985af1',
  18. 'upload_date': '20160311',
  19. }
  20. }, {
  21. # audio
  22. 'url': 'http://www.dw.com/en/worldlink-my-business/av-19111941',
  23. 'md5': '2814c9a1321c3a51f8a7aeb067a360dd',
  24. 'info_dict': {
  25. 'id': '19111941',
  26. 'ext': 'mp3',
  27. 'title': 'WorldLink: My business',
  28. 'description': 'md5:bc9ca6e4e063361e21c920c53af12405',
  29. 'upload_date': '20160311',
  30. }
  31. }]
  32. def _real_extract(self, url):
  33. media_id = self._match_id(url)
  34. webpage = self._download_webpage(url, media_id)
  35. hidden_inputs = self._hidden_inputs(webpage)
  36. title = hidden_inputs['media_title']
  37. if hidden_inputs.get('player_type') == 'video' and hidden_inputs.get('stream_file') == '1':
  38. formats = self._extract_smil_formats(
  39. 'http://www.dw.com/smil/v-%s' % media_id, media_id,
  40. transform_source=lambda s: s.replace(
  41. 'rtmp://tv-od.dw.de/flash/',
  42. 'http://tv-download.dw.de/dwtv_video/flv/'))
  43. self._sort_formats(formats)
  44. else:
  45. formats = [{'url': hidden_inputs['file_name']}]
  46. return {
  47. 'id': media_id,
  48. 'title': title,
  49. 'description': self._og_search_description(webpage),
  50. 'thumbnail': hidden_inputs.get('preview_image'),
  51. 'duration': int_or_none(hidden_inputs.get('file_duration')),
  52. 'upload_date': hidden_inputs.get('display_date'),
  53. 'formats': formats,
  54. }
  55. class DWArticleIE(InfoExtractor):
  56. IE_NAME = 'dw:article'
  57. _VALID_URL = r'https?://(?:www\.)?dw\.com/(?:[^/]+/)+a-(?P<id>\d+)'
  58. _TEST = {
  59. 'url': 'http://www.dw.com/en/no-hope-limited-options-for-refugees-in-idomeni/a-19111009',
  60. 'md5': '8ca657f9d068bbef74d6fc38b97fc869',
  61. 'info_dict': {
  62. 'id': '19105868',
  63. 'ext': 'mp4',
  64. 'title': 'The harsh life of refugees in Idomeni',
  65. 'description': 'md5:196015cc7e48ebf474db9399420043c7',
  66. 'upload_date': '20160310',
  67. }
  68. }
  69. def _real_extract(self, url):
  70. article_id = self._match_id(url)
  71. webpage = self._download_webpage(url, article_id)
  72. hidden_inputs = self._hidden_inputs(webpage)
  73. media_id = hidden_inputs['media_id']
  74. media_path = self._search_regex(r'href="([^"]+av-%s)"\s+class="overlayLink"' % media_id, webpage, 'media url')
  75. media_url = compat_urlparse.urljoin(url, media_path)
  76. return self.url_result(media_url, 'DW', media_id)